binom1.2sided {BAEssd}  R Documentation 
Generates the suite of functions related to the one sample binomial experiment with a twosided alternative hypothesis of interest.
binom1.2sided(p0, prob, a, b)
p0 
Scalar. The value of p under null hypothesis Ho: p==p0. Must be a value between 0 and 1. 
prob 
Scalar. The prior probability that the null hypothesis is true. Must be a value between 0 and 1. 
a 
Scalar. Shape1 parameter for prior Beta distribution. See documentation for

b 
Scalar. Shape2 parameter for prior Beta distribution. See documentation for

binom1.2sided
is used to generate a suite of functions for a onesample
binomial experiment with a twosided alternative hypothesis. That is, when
X ~ Binomial(n,p)
H0: p == p0 vs. H1: p != p0
using the following prior on p
pi(p) = u*(p==p0) + (1u)*(p!=p0)Beta(a,b),
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 binom1.2sided
are passed to each of the additional
functions upon their creation as default values. That is, if p0
is
set to 0.5 in the call to binom1.2sided
, each of the functions returned
will have the defaualt value of 0.5 for p0
. If an argument is not
specified in the call to binom1.2sided
, then it remains a required
parameter in all functions created.
binom1.2sided
returns a list of 4 functions:
logm 
Returns a list of three vectors: the log marginal density under
the null hypothesis ( logm(x, n, p0, prob, a, b)

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, p0, prob, a, b) For details on the parameters, see above function 
prior 
Returns a vector: the value of the prior density. The function has the following usage: prior(p, p0, prob, a, b)

post 
Returns a vector: the value of the posterior density. The function has the following usage: post(p, x, n, p0, prob, a, b)

binom1.1sided
,binom2.1sided
,
binom2.2sided
,norm1KV.1sided
,
norm1KV.2sided
,norm2KV.2sided
norm1UV.2sided
,ssd
,BAEssd
############################################################ # Generate the suite of functions for a onesample binomial # with a twosided test. Consider the hypothesis # H0: p==0.5 vs. H1: p!=0.5 # # with a uniform prior on p under the alternative and a # prior probability of the null hypothesis equal to 0.5. # generate suite f2 < binom1.2sided(p0=0.5,prob=0.5,a=1,b=1) # attach suite attach(f2) # plot prior and posterior given x = 25, n = 30 #  don't forget that point mass is not shown on plot ps < seq(0.01,0.99,0.01) p1 < prior(ps) p2 < post(ps,x=25,n=30) plot(c(p1,p2)~rep(ps,2),type="n",ylab="Density",xlab="p",main="") lines(p1~ps,lty=1,lwd=2) lines(p2~ps,lty=2,lwd=2) # perform sample size calculation with TE bound of 0.25 and weight 0.5 ssd.binom(alpha=0.25,w=0.5,logm=logm) # detain suite detach(f2)