Last data update: 2014.03.03

R: Binomial Suite: Two Sample, One Sided
binom2.1sidedR Documentation

Binomial Suite: Two Sample, One Sided

Description

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

Usage

  binom2.1sided(a1, b1, a2, b2)

Arguments

a1

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

b1

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

a2

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

b2

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

Details

binom2.1sided is used to generate a suite of functions for a two-sample binomial experiment with a one-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) = Beta(a1,b1)Beta(a2,b2),

where Beta(a,b) is Beta density with parameters a and b.

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.1sided are passed to each of the additional functions upon their creation as default values. That is, if a1 is set to 1 in the call to binom2.1sided, each of the functions returned will have the defaualt value of 1 for a1. If an argument is not specified in the call to binom2.1sided, then it remains a required parameter in all functions created.

Value

binom2.1sided 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, 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.1sided.

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, 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, 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.1sided.

post

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

post(p, x, n, 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.1sided.

See Also

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

Examples

############################################################
# 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[1] and a uniform prior on p[2].

# generate suite
f3 <- binom2.1sided(a1=1,b1=1,a2=1,b2=1)

# attach suite
attach(f3)

# 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(f3)

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/binom2.1sided.Rd_%03d_medium.png", width=480, height=480)
> ### Name: binom2.1sided
> ### Title: Binomial Suite: Two Sample, One Sided
> ### Aliases: binom2.1sided
> 
> ### ** Examples
> 
> ############################################################
> # 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[1] and a uniform prior on p[2].
> 
> # generate suite
> f3 <- binom2.1sided(a1=1,b1=1,a2=1,b2=1)

Loading the 'binom2.1sided' suite... 
  This suite contains functions pertaining to an experiment with two 
  independent samples involving a binary outcome. The hypothesis of 
  interest has a one-sided alternative.

> 
> # attach suite
> attach(f3)
> 
> # 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)
[1] -5.244361
> 
> # 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)

Bayesian Average Error Sample Size Determination

Call: ssd.binom(alpha = 0.25, w = 0.5, logm = logm, two.sample = TRUE)

Sample Size:  12
Total Average Error:  0.2481694

Acceptable sample size determined!

> 
> # detain suite
> detach(f3)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>