= function(
probrep # sample size of both the initial and replication experiment
nn, # prior probability of the hypothesis
gamma, # success probability under the null hypothesis
theta0, # success probability under the null hypothesis
theta1, # significance cutoff
alpha
){= seq(0,nn) # possible values of original experiment
x1range = pH0 = rep(NA,nn+1) # initialization
pvalue1 # type two error estimation via quick simulation
= 10000
MM = rbinom(MM,nn,theta1)
xx.under.alt = NA
pvalue.alt for (mm in 1:MM){
= binom.test(xx.under.alt[mm],nn,theta0,alternative="two.sided")$p.value
pvalue.alt[mm]
}= mean( pvalue.alt > .05) # type one error in both studies
beta #
for (xx in x1range){
# mapping between number of successes and pvalue in original ezxperiment
=
pvalue1[xx] binom.test(xx,nn,theta0,alternative="two.sided")$p.value
# probability of null hypothesis given first experiment
= gamma * dbinom(xx,nn,theta0) /
pH0[xx] * dbinom(xx,nn,theta0) + (1-gamma) * dbinom(xx,nn,theta1))
( gamma
}# set tiny p-values to e-20 for visualization purposes
is.na(pvalue1)] = 0
pvalue1[is.na(pH0)] = 0
pH0[# separate rejections
= x1range[ pvalue1 < .05 ] + 1
xx.reject = x1range[ pvalue1>=.05 ] + 1
xx.retain = pvalue1[xx.reject]
pvalue.reject = pvalue1[xx.retain]
pvalue.retain = pH0[xx.reject]
pH0.reject = pH0[xx.retain]
pH0.retain
# browser()
# compute replication probabilitie
= (alpha/2) * pH0[xx.reject] + (1-beta) * (1-pH0[xx.reject])
prep.reject = (1-alpha) * pH0[xx.retain] + beta * (1-pH0[xx.retain])
prep.retain
return(list(
reject = na.omit(data.frame(prep.reject,pvalue.reject,pH0.reject)),
retain = na.omit(data.frame(prep.retain,pvalue.retain,pH0.retain))))
}
Probability of Replication
Probability of replication of a Binomial test for simple versus simple hypothesis. Inspired by Miller’s paper.
Model: \(x\) is Binomial \(\theta\). There are two possible values of \(\theta\) the null value \(\theta_0\) and the alternative \(\theta_1\). Both the original and replicated experiment have size \(n\). We know \(\gamma\).
The logic is this:
-- compute the power \((1-\beta\)) of the studies (it is the same for both) by simulation
-- for ever possible \(x\) in \(0, \ldots, n\) compute the p-value and the posterior probability of the null \(\theta=\theta_0\)
-- if the \(x\) leads to a rejection compute the probability of replication as \(\alpha/2 * p(\theta_0|x) + (1-\beta) (1-p(\theta_0|x))\)
-- if the \(x\) does not lead to a rejection compute the probability of replication as \((1-\alpha) * p(\theta_0|x) + \beta (1-p(\theta_0|x))\)
Function to compute the probability of replication.
= probrep(nn=20,gamma=.5,theta0=.1,theta1=.2,alpha=0.05)
probrep.out plot(probrep.out$reject$pvalue.reject,
$reject$prep.reject,
probrep.outylab="probability of replication",
xlab="p-value of original study")
plot(probrep.out$reject$pvalue.reject,
$reject$pH0.reject,
probrep.outylab="probability of null hypothesis",
xlab="p-value of original study")
plot(probrep.out$retain$pvalue.retain,
$retain$prep.retain,
probrep.outylab="probability of replication",
xlab="p-value of original study")
plot(probrep.out$retain$pvalue.retain,
$retain$pH0.retain,
probrep.outylab="probability of null hypothesis",
xlab="p-value of original study")