#Chapter 12 #simulation to calculate power at a certain sample size with all continuous variables bx= #1 bm= #2 sx= #3 sm= #4 sy= #5 c= #8 nsim=100 #number of simulations for the power analysis alpha=0.05 # result1=NULL set.seed(1) for (i in 1:nSims){ pred=rnorm(n,0,sx) e1=rnorm(n,0,sm) e2=rnorm(n,0,sy) #continuous m=a*pred+e1 y=c*x+b*m+e2 temp2<-mma(data.frame(m=m),y,pred=pred,mediator=1, jointm=list(n=1,j1=1),n2=100) #m is forced in as a third-variable D=summary(temp2,plot=F,alpha=alpha) result1=rbind(result1,c(D$results$indirect.effect[[1]][,2]))}