norm2KV.2sided {BAEssd} R Documentation

## Normal Suite: Two Sample, Two Sided, Known Variance

### Description

Generates the suite of functions related to the two sample normal experiment with a two-sided alternative hypothesis of interest when the variance is known.

### Usage

```  norm2KV.2sided(sigma, prob, mu0, tau0, mu1, tau1, mu2, tau2)
```

### Arguments

 `sigma` Scalar. The known standard deviation of the population. `prob` Scalar. The prior probability of the null hypothesis. Must be a value between 0 and 1. `mu0` Scalar. The mean of the normal prior density on theta under the null hypothesis. See documentation for `dnorm`. `tau0` Scalar. The standard deviation of the normal prior density on theta under the null hypothesis. See documentation for `dnorm`. `mu1` Scalar. The mean of the normal prior density on mean for sample 1 under the alternative hypothesis. See documentation for `dnorm`. `tau1` Scalar. The standard deviation of the normal prior density on mean for sample 1 under the alternative hypothesis. See documentation for `dnorm`. `mu2` Scalar. The mean of the normal prior density on mean for sample 2 under the alternative hypothesis. See documentation for `dnorm`. `tau2` Scalar. The standard deviation of the normal prior density on mean for sample 2 under the alternative hypothesis. See documentation for `dnorm`.

### Details

`norm2KV.2sided` is used to generate a suite of functions for a two-sample normal experiment with a two-sided alternative hypothesis when the variance is known and the samples are independent. That is, when

X[j] ~ Normal(theta[j],sigma2)

H0: theta[1] == theta[2] vs. H1: theta[1] != theta[2]

using the following prior on theta[1] and theta[2]

pi(theta) = u*I(theta[1]==theta[2])Normal(mu0,tau0^2) + (1-u)*I(theta[1]!=theta[2])Normal(mu1,tau1^2)Normal(mu2,tau2^2),

where Normal(mu,tau^2) is Normal density with mean `mu` and variance `tau^2` and u is the prior probability of the null hypothesis (`prob`).

The functions that are generated are useful in examining the prior and posterior densities of the parameter `theta`, as well as constructing the Bayes Factor and determining the sample size via an average error based approach.

The arguments of `norm2KV.2sided` are passed to each of the additional functions upon their creation as default values. That is, if `mu0` is set to 1 in the call to `norm2KVV.2sided`, each of the functions returned will have the defaualt value of 1 for `mu0`. If an argument is not specified in the call to `norm2KV.2sided`, then it remains a required parameter in all functions created.

### Value

`norm2KV.2sided` returns a list of 5 functions:

 `logm` Returns a list of three vectors: the log marginal density under the null hypothesis (`logm0`), the log marginal density under the alternative hypothesis (`logm1`), the log marginal density (`logm`). Each are evaluated at the observed data provided. The function takes the following usage: `logm(xbar, n, sigma, prob, mu0, tau0, mu1, tau1, mu2, tau2)` `xbar`: Matrix with 2 columns. Each column represents the sample mean for each of the two samples. `n`: Scalar. The sample size. Remaining parameters are described above for `norm2KV.2sided`. `logbf` Returns a vector. The value of the log Bayes Factor given the observed data provided and the prior parameters specified. The function has the following usage: `logbf(xbar, n, sigma, prob, mu0, tau0, mu1, tau1, mu2, tau2)` For details on the arguments, see `logm` above. `prior` Returns a vector. The value of the prior density. The function takes the following usage: `prior(theta, prob, mu0, tau0, mu1, tau1, mu2, tau2)` `theta`: Vector. The quantiles at which to evaluate the prior. Remaining paramters are described above for `norm2KV.2sided`. `post` Returns a vector. The value of the posterior density. The function takes the following usage: ```post(theta, xbar, n, sigma, prob, mu0, tau0, mu1, tau1, mu2, tau2)``` `theta`: Vector. The quantiles at which to evaluate the posterior. `xbar`: Vector of length 2. Each element represents the sample mean for each of the two samples, respectively. `n`: Scalar. The sample size. Remaining paramters are described above for `norm2KV.2sided`. `ssd.norm2KV.2sided` Sample size calculations for this particular set-up. The function has the following usage: ```ssd.norm2KV.2sided(alpha, w, sigma, prob, mu0, tau0, mu1, tau1, mu2, tau2, m = 2500, minn = 2, maxn = 1000, all = FALSE)``` See `ssd` for more details. The suite-specific parameters are described above for `norm2KV.2sided`.

`binom1.1sided`,`binom1.2sided`, `binom2.1sided`,`binom2.2sided`, `norm1KV.1sided`,`norm1KV.2sided`, `norm1UV.2sided`,`ssd`,`BAEssd`

### Examples

```############################################################
# Generate the suite of functions for a two-sample normal
# with a two-sided test. Consider the hypothesis
#      H0: theta[1]==theta[2]  vs.  H1: theta[1]!=theta[2]
#
# with a known variance of 3.

# generate suite
f7 <- norm2KV.2sided(sigma=3,prob=0.5,mu0=0,tau0=1,mu1=2,tau1=1,mu2=2,tau2=1)

# attach suite
attach(f7)

# calculate the Bayes Factor for the following observed data
#   n = 30, xbar[1] = -1, xbar[2] = 1
logbf(xbar=matrix(c(-1,1),nrow=1,ncol=2),n=30)

# perform sample size calculation with TE bound of 0.5 and weight 0.9
#  - due to a need for a Monte Carlo implementation of this procedure, this
#    problem can take significantly longer to solve, compared to other examples.
#    Thus, for this example, a large error bound and weight were chosen to
#    decrease computation time while illustrating the function.
ssd.norm2KV.2sided(alpha=0.5,w=0.9)

# detain suite
detach(f7)
```

[Package BAEssd version 1.0.1 Index]