R: Normal Suite: Two Sample, Two Sided, Known Variance
norm2KV.2sided
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.
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]
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:
############################################################
# 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)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(BAEssd)
Loading required package: mvtnorm
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/BAEssd/norm2KV.2sided.Rd_%03d_medium.png", width=480, height=480)
> ### Name: norm2KV.2sided
> ### Title: Normal Suite: Two Sample, Two Sided, Known Variance
> ### Aliases: norm2KV.2sided
>
> ### ** 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)
Loading the 'norm2KV.2sided' suite...
This suite contains functions pertaining to an experiment with two
independent samples, each with a response that is normally
distributed with a common known variance. The hypothesis of
of interest has a two-sided alternative.
>
> # 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)
[1] -0.9607166
>
> # 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)
Bayesian Average Error Sample Size Determination
Call: ssd.norm2KV.2sided(alpha = 0.5, w = 0.9)
Sample Size: 3
Total Average Error: 0.4872
Acceptable sample size determined!
>
> # detain suite
> detach(f7)
>
>
>
>
>
> dev.off()
null device
1
>