Description Usage Arguments Value Author(s) References See Also Examples
View source: R/sample.size.calc.R
Calculates the required sample size for a new study to conduct the prior predictive check with sufficient statistical power.
1 2 3 4 | sample.size.calc(start_n=20,itmax=10,nmax=600,powtarget=.825,powmargin=.025,
posterior,g.m,p.sd,
statistic,Amat=0L,exact=0L,difmin=0L,effectsize=FALSE,
alpha=.05,printit=TRUE)
|
start_n |
integer; the starting value for the sample size per group. Defaults to 20. |
itmax |
integer; the maximum number of iterations for the function. |
nmax |
integer; the maximum total sample size to evaluate. |
powtarget |
integer; the target power for which the sample size is to be obtained. |
powmargin |
integer; the margin around the target power for which results are to be returned. |
posterior |
a matrix (e.g., the output of Gibbs.ANOVA) with samples from the posterior based on the original data (i.e., y_o). |
g.m |
vector; the population values the alternative distribution. To calculate the power to reject replication if the means are equal specify the grand mean of the study variables in the original dataset. |
p.sd |
integer; the population value for the pooled standard deviation in the alternative distribution. We advice to specify the pooled standard deviation for the study variables in the original dataset. |
statistic |
the type of hypothesis to be calculated: "ineq" for inequality constrained means, "dif" for inequality constraints plus minimum differences between means, "exact" for specific values for the means. |
Amat |
a p by q matrix, where p is the number of means in the ANOVA model, and q is the number of constraints to be imposed on the model. Each row represents one constraint where the parameter with the lower value according to the constraint receives the value -1, and the parameter with the higher value according to the constraint receives the value 1. Other parameters within the same row obtain the value 0. |
exact |
a vector of length p, where p is the number of means in the ANOVA model, with the exact values of the constrained hypothesis. |
difmin |
a vector of length q with the minimum difference per constraint as specified in |
effectsize |
logical; If TRUE the values in |
alpha |
integer; the level of alpha that should be taken into account while calculating the required sample size. |
printit |
logical; If TRUE the current iteration is printed to provide an indication of progress. Default is TRUE. |
Prints iterations while calculating. Prints a matrix with two columns. The first column contains the sample size per group and the second column the associated power. Furthermore, sample.size.calc produces a histogram with the null (i.e., the red distribution) and alternative distribution (i.e., the blue distribution) for the last iteration afterwards. The vertical line indicates rej.value (i.e., the 1-alpha'th percentile of the null distribution). The proportion of the alternative distribution on the right side of rej.value constitutes the statistical power.
M.A.J. Zondervan-Zwijnenburg
Zondervan-Zwijnenburg, M.A.J., Van de Schoot, R., & Hoijtink, H. (2017). Testing ANOVA replication by means of the prior predictive p-value.
See also runShiny
, prior.predictive.check
, power.calc
, Fbar.ineq
, Fbar.dif
, and Fbar.exact
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #analysis original data
data_o <- data.frame(y=ChickWeight$weight,g=ChickWeight$Diet)
#compute pooled sd
sd.g <- aggregate(data_o$y,by=list(data_o$g),sd)[,2]
n.g <- table(data_o$g)
p.sd<- pooled.sd(data_o)
post <- Gibbs.ANOVA(data_o)
#create matrices HR: g4>(g1,g2,g3). g4-g1>0.8, g4-g2>0.5, g4-g3>0.2
HR <- create_matrices(varnames = c("g1","g2","g3","g4"),
hyp = "g4-g1>0.8 & g4-g2>0.5 & g4-g3>0.2")
Amat <- HR$Amat
difmin <- HR$difmin
#sample size calculator
sample.size.calc(start_n=30, powtarget=.825,powmargin=.025,posterior=post$posterior,
g.m=rep(mean(data_o$y),4),p.sd=p.sd,
statistic="dif",effectsize=TRUE,Amat=Amat,difmin=difmin)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.