norm1UV.2sided: Normal Suite: One Sample, Two Sided, Unknown Variance

Description Usage Arguments Details Value See Also Examples

View source: R/norm1UV.2sided.R

Description

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

Usage

1
  norm1UV.2sided(theta0, prob, mu, scale, shape, rate)

Arguments

theta0

Scalar. The critical value of the mean under the null hypothesis: theta==theta0.

prob

Scalar. The prior probability of the null hypothesis. Must be a value between 0 and 1.

mu

Scalar. The mean of the normal prior density on theta under the alternative hypothesis. See documentation for dnorm.

scale

Scalar. Used to determine the standard deviation for the normal prior density on theta under the alternative hypothesis. The standard deviation is equal to scale*sigma. See documentation for dnorm.

shape

Scalar. The shape parameter for the gamma prior on the inverse of the unknown standard deviation sigma2. See documenation for dgamma.

rate

Scalar. The rate parameter for the gamma prior on the inverse of the unknown standard deviation sigma2. See documentation for dgamma.

Details

norm1UV.2sided is used to generate a suite of functions for a one-sample normal experiment with a two-sided alternative hypothesis when the variance is unknown. That is, when

X ~ Normal(theta,sigma2)

H0: theta == theta0 vs. H1: theta != theta0

using the following prior on theta and sigma2

pi(theta|sigma2) = u*I(theta==theta0) + (1-u)*I(theta!=theta0)Normal(mu,(scale*sigma)^2),

pi(sigma2) = InverseGamma(shape,rate),

where Normal(mu,tau2) is Normal density with mean mu and variance tau2 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 parameters theta and sigma2, as well as constructing the Bayes Factor and determining the sample size via an average error based approach.

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

Value

norm1UV.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, s2, n, theta0, prob, mu, scale, shape, rate)
  • xbar: Vector. Observed sample mean from the experiment.

  • s2: Vector. Observed sample standard deviation from the experiment.

  • n: Scalar. Sample size.

  • Remaining parameters described above for norm1UV.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, s2, n, theta0, prob, mu, scale, shape, rate)

For details on the arguments, see logm above.

prior

Returns a vector. The value of the prior density. The function has the following usage:

prior(theta, sigma2, theta0, prob, mu, scale, shape, rate)
  • theta: Vector. The quantiles of the mean at which to evaluate the prior.

  • sigma2: Vector. The quantiles of the standard deviation at which to evaluate the prior.

  • Remaining parameters described above for norm1UV.2sided

post

Returns a vector. The value of the posterior density. The function has the following usage:

post(theta, sigma2, xbar, s2, n, theta0, prob, mu, scale, 
    shape, rate)
  • theta: Vector. The quantiles of the mean at which to evaluate the posterior.

  • sigma2: Vector. The quantiles of the standard deviation at which to evaluate the psterior.

  • xbar: Vector. Observed sample mean from the experiment.

  • s2: Vector. Observed sample standard deviation from the experiment.

  • n: Scalar. Sample size.

  • Remaining parameters described above for norm1UV.2sided

ssd.norm1UV.2sided

Sample size calculations for this particular set-up. The function has the following usage:

ssd.norm1UV.2sided(alpha, w, theta0, prob, mu, scale, shape, 
    rate, m = 2500, minn = 3, maxn = 1000, all = FALSE)

See ssd for more details. The suite-specific parameters are described above for norm1UV.2sided. Note that this example will not work with ssd.norm1KV.

See Also

binom1.1sided,binom1.2sided, binom2.1sided,binom2.2sided, norm1KV.1sided,norm1KV.2sided, norm2KV.2sided,ssd,BAEssd

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
############################################################
# Generate the suite of functions for a one-sample normal
# with a two-sided test. Consider the hypothesis
#      H0: theta==0  vs.  H1: theta!=0
#
# with a normal prior for theta with prior mean 2 and 
# scale of 1/3 for the standard deviation. The prior proability
# of the null hypothesis is set to 0.5. The prior density
# on sigma2 is taken to be InverseGamma with parameters
# 11 and 30 for the shape and rate.

# generate suite
f8 <- norm1UV.2sided(theta0=0,prob=0.5,mu=2,scale=(1/3),shape=11,rate=30)

# attach suite
attach(f8)

# calculate the Bayes Factor for the following observed data
#   n = 30, xbar = 1, s2 = 2
logbf(xbar=1,s2=2,n=30)

# perform sample size calculation with TE bound of 0.25 and weight 0.5
ssd.norm1UV.2sided(alpha=0.25,w=0.5)

# detain suite
detach(f8)

BAEssd documentation built on May 2, 2019, 3 a.m.