library(swdpwr)
#a cross-sectional design with 12 clusters, 3 periods and binary outcomes applying conditional model
#alpha2 should not be specified, as the current version does not support power calculation using
#conditional models with binary outcomes in a cohort design
#create a 12*3 matrix which describes the study design,
#0 means control status, 1 means intervention status
dataset = matrix(c(rep(c(0,1,1),6),rep(c(0,0,1),6)),12,3,byrow=TRUE)
#specify meanresponse_start, meanresponse_end0 and meanresponse_end1
swdpower(K = 30, design = dataset, family = "binomial", model = "conditional", link = "logit",
type = "cross-sectional", meanresponse_start = 0.2, meanresponse_end0 = 0.3,
meanresponse_end1 = 0.4, typeIerror = 0.05, alpha0 = 0.01, alpha1 = 0.01)
#specify meanresponse_start, meanresponse_end0 and effectsize_beta
swdpower(K = 30, design = dataset, family = "binomial", model = "conditional", link = "logit",
type = "cross-sectional", meanresponse_start = 0.2, meanresponse_end0 = 0.3, effectsize_beta = 0.6,
typeIerror = 0.05, alpha0 = 0.01, alpha1 = 0.01)
#a cohort design with 8 clusters, 3 periods and continuous outcomes applying marginal model
#sigma2 should be specified, as continuous outcomes require marginal variance in calculation
#create a 8*3 matrix which describes the study design,
#0 means control status, 1 means intervention status
dataset = matrix(c(rep(c(0,1,1),4),rep(c(0,0,1),4)),8,3, byrow=TRUE)
#specify meanresponse_start, meanresponse_end0 and meanresponse_end1
swdpower(K = 24, design = dataset, family = "gaussian", model = "marginal", link = "identity",
type = "cohort", meanresponse_start = 0.1, meanresponse_end0 = 0.2, meanresponse_end1 = 0.4,
sigma2 = 0.095, typeIerror = 0.05, alpha0 = 0.03, alpha1 = 0.015, alpha2 = 0.2)
#specify effectsize_beta only, then the program runs assuming no time effects
swdpower(K = 24, design = dataset, family = "gaussian", model = "marginal", link = "identity",
type = "cohort",effectsize_beta=0.3, sigma2 = 0.095, typeIerror = 0.05, alpha0 = 0.03,
alpha1 = 0.015, alpha2 = 0.2)
Run the code above in your browser using DataLab