#R-code for footnote in Colada[19] #This function generates high and low conditions, runs a t-test, and stores the significantly different samples #It then compares how simlar the high and low means are to each other, and contrasts that to their SE (hw similar they shoudl be ignoring selective reporting) Colada19=function(n,muH, simtot) #SYNTAX #n: number of observations per cell #muH: population mean in the high conditoin (low conditions is 0) #simtot: number of simulations { set.seed(n*1000+muH*1000+simtot) #seed so that same parameters always lead to same results #create vectors to store results mh=c() ml=c() sd=c() for (i in 1:simtot) { #draw the two samples y1=rnorm(n,mean=muH,sd=1) y2=rnorm(n) #p-value of the t-test p=t.test(y1,y2)$p.value #if significant keep summary stats if (p<.05) { #compute means and SD m1=mean(y1) m2=mean(y2) sd.k=sd(c(y1-m1,y2-m2)) #pooled SD via shortcut mh=c(mh,max(m1,m2)) #keep high mean as high ml=c(ml,min(m1,m2)) #keep low mean as low sd=c(sd,sd.k) } } cat("\n# of significant tests: ",length(mh)) cat("\nSD of high means (how similar they are) : ",sd(mh)) cat("\nSD of low means (how similar they are) : ",sd(ml)) cat("\nSE of means (how similar they should be): ",mean(sd)/sqrt(n)) } #Smeesters had 14 per cell, so I use that here Colada19(n=14,simtot=10000,muH=0) #assuming true effect is 0 Colada19(n=14,simtot=10000,muH=1) #assuming true effect is d=1, about what Smeesters reported