binom2.2sided: Binomial Suite: Two Sample, Two Sided

Description Usage Arguments Details Value See Also Examples

View source: R/binom2.2sided.R

Description

Generates the suite of functions related to the two sample binomial experiment with a two-sided alternative hypothesis of interest.

Usage

1
  binom2.2sided(prob, a0, b0, a1, b1, a2, b2)

Arguments

prob

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

a0

Scalar. Shape1 parameter for prior Beta distribution under the null hypothesis that the two parameters are equal. See documentation for dbeta.

b0

Scalar. Shape2 parameter for prior Beta distribution under the null hypothesis that the two parameters are equal. See documentation for dbeta.

a1

Scalar. Shape1 parameter for prior Beta distribution for the parameter governing sample 1 under the alternative hypothesis. See documentation for dbeta.

b1

Scalar. Shape2 parameter for prior Beta distribution for the parameter governing sample 1 under the alternative hypothesis. See documentation for dbeta.

a2

Scalar. Shape1 parameter for prior Beta distribution for the parameter governing sample 2 under the alternative hypothesis. See documentation for dbeta.

b2

Scalar. Shape2 parameter for prior Beta distribution for the parameter governing sample 2 under the alternative hypothesis. See documentation for dbeta.

Details

binom2.2sided is used to generate a suite of functions for a two-sample binomial experiment with a two-sided alternative hypothesis. That is, when

X[j]|p[j] ~ Binomial(n,p[j]), independent

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

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

pi(p) = u*(p[1]==p[2])Beta(a0,b0) + (1-u)*(p[1]!=p[2])Beta(a1,b1)Beta(a2,b2),

where Beta(a,b) is Beta density with parameters a and b 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 p, as well as constructing the Bayes Factor and determining the sample size via an average error based approach.

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

Value

binom2.2sided returns a list of 4 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. This function is passed to ssd.binom to calculate required sample sizes. This function takes the following usage:

logm(x, n, prob, a0, b0, a1, b1, a2, b2)
  • x: Matrix with two columns. Each row represents the number of successes in sample 1 and sample 2, respectively, observed out of n independent Bernoulli trials.

  • n: Scalar. The number of independent Bernoulli trials.

  • Remaining parameters described above for bionom2.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(x, n, prob, a0, b0, a1, b1, a2, b2)

For details on the parameters, see logm above.

prior

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

prior(p, prob, a0, b0, a1, b1, a2, b2)
  • p: Matrix with 2 columns. Each row is a vector of length 2 corresponding to a 2-dimensional quantile at which to compute the density. The first column represents the parameter for sample 1, and the second column, the parameter for sample 2.

  • Remaining parameters described above for binom2.2sided.

post

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

post(p, x, n, prob, a0, b0, a1, b1, a2, b2)
  • p: Matrix with 2 columns. Each row is a vector of length 2 corresponding to a 2-dimensional quantile at which to compute the density. The first column represents the parameter for sample 1, and the second column, the parameter for sample 2.

  • x: Vector of length 2. Element 1 represents the number of successes for sample 1 and element 2 the number of successes in sample 2.

  • Remaining parameters described above for binom2.2sided.

See Also

binom1.1sided,binom1.2sided, binom2.1sided,norm1KV.1sided, norm1KV.2sided,norm2KV.2sided norm1UV.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
############################################################
# Generate the suite of functions for a one-sample binomial
# with a two-sided test. Consider the hypothesis
#      H0: p[1]==p[2]   vs.  H1: p[1]!=p[2]
#
# with a uniform prior on p under the null and a uniform
# prior on p[1] and p[2] under the alternative with a 0.5
# probability of the null hypothesis being true.

# generate suite
f4 <- binom2.2sided(prob=0.5,a0=1,b0=1,a1=1,b1=1,a2=1,b2=1)

# attach suite
attach(f4)

# calculate the Bayes factor when the observed data are
#   n = 30, x[1] = 10, x[2] = 20
logbf(x=matrix(c(10,20),ncol=2,nrow=1),n=30)

# perform sample size calculation with TE bound of 0.25 and weight 0.5
ssd.binom(alpha=0.25,w=0.5,logm=logm,two.sample=TRUE)

# detain suite
detach(f4)

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