This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Script based on Carter & McCullough (2014) doi: 10.3389/fpsyg.2014.00823 | |
#Load Libraries | |
library(meta) | |
library(metafor) | |
#Insert effect sizes and sample sizes | |
es.d<-c(0.38,0.41,-0.14,0.63,0.22) | |
n1<-c(75,48,22,18,60) | |
n2<-c(75,52,21,20,55) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(MBESS) | |
Lims <- conf.limits.ncf(F.value = 7, conf.level = 0.90, df.1 <- 4, df.2 <- 50) | |
Lower.lim <- Lims$Lower.Limit/(Lims$Lower.Limit + df.1 + df.2 + 1) | |
Upper.lim <- Lims$Upper.Limit/(Lims$Upper.Limit + df.1 + df.2 + 1) | |
Lower.lim | |
Upper.lim |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### | |
p1 <-numeric(200) #set up empty container for all p-values | |
bf1 <-numeric(200) #set up empty container for all bf | |
p2 <-numeric(200) #set up empty container for all p-values | |
bf2 <-numeric(200) #set up empty container for all bf | |
p3 <-numeric(200) #set up empty container for all p-values | |
bf3 <-numeric(200) #set up empty container for all bf | |
t <- 1.96 #set start point t-value | |
for (i in 1:201) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#####SIMULATE & PLOT Z-SCORES######### | |
nSims <- 100000 #number of simulated experiments | |
p <-numeric(nSims) #set up empty container for all simulated p-values | |
z <-numeric(nSims) #set up empty container for z-scores | |
for(i in 1:nSims){ #for each simulated experiment | |
x<-rnorm(n = 23, mean = 100, sd = 20) #produce simulated participants | |
y<-rnorm(n = 23, mean = 110, sd = 20) #produce simulated participants | |
t<-t.test(x,y) #perform the t-test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############DATA############ | |
#All significant Z values: 1.9609,1.9611,1.9727,1.9859,2.0063,2.017,2.0188,2.0231,2.0316,2.0377,2.04,2.0444,2.0494,2.0579,2.062,2.0624,2.0662,2.0737,2.0802,2.0803,2.0821,2.0863,2.0895,2.095,2.0964,2.0983,2.1,2.1,2.1113,2.1219,2.124,2.1299,2.1314,2.1318,2.1444,2.1448,2.1481,2.1491,2.1551,2.1584,2.1599,2.1615,2.1622,2.163,2.1656,2.1711,2.1807,2.1836,2.1865,2.1879,2.1909,2.2068,2.2151,2.2205,2.2212,2.2237,2.2316,2.2369,2.2457,2.2572,2.2668,2.2716,2.2777,2.2892,2.2993,2.3001,2.3034,2.31,2.3171,2.3183,2.3232,2.3282,2.337,2.343,2.3455,2.3459,2.3473,2.3517,2.354,2.3543,2.36,2.3623,2.3697,2.3707,2.3767,2.3781,2.3833,2.3871,2.396,2.4221,2.43,2.4408,2.4463,2.4584,2.4714,2.4751,2.485,2.488,2.4889,2.5121,2.5141,2.5306,2.5387,2.5531,2.5698,2.5711,2.5726,2.5793,2.5803,2.5988,2.6322,2.6335,2.6396,2.6397,2.6468,2.6475,2.6664,2.6687,2.6788,2.702,2.7032,2.7212,2.7245,2.7289,2.729,2.7324,2.736,2.7371,2.7402,2.744,2.7537,2.7578,2.761,2.7775,2.7846,2.7929,2.7931,2.8054,2.8131,2.8474,2.8605,2.8657,2.87 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nSims <- 11000 #number of simulated experiments | |
psig <-numeric(nSims) #set up empty container for all simulated p-values | |
pnonsig <-numeric(nSims) #set up empty container for all simulated p-values | |
z <-numeric(nSims) #set up empty container for z-scores | |
for(i in 1:nSims){ #for each simulated experiment | |
x<-rnorm(n = 38, mean = 100, sd = 20) #produce simulated participants | |
y<-rnorm(n = 38, mean = 108, sd = 20) #produce simulated participants | |
t<-t.test(x,y) #perform the t-test | |
if(t$p.value<=0.05&t$p.value>=0.01) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# phack | |
# Requires | |
# {psych} | |
# See Also http://rynesherman.com/blog/phack-an-r-function-for-examining-the-effects-of-p-hacking/ | |
phack <- function(initialN=50, hackrate=10, grp1M=0, grp2M=0, grp1SD=1, grp2SD=1, maxN=100, alpha=.05, alternative="greater", graph=TRUE, sims=100000) { | |
require(psych) | |
outmat <- matrix(NA, nrow=sims, ncol=6) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#####EFFECT WITH PUBLICATION BIAS######### | |
nSims <- 10000 #number of simulated experiments | |
z1 <-numeric(nSims) #set up empty container for z-scores | |
for(i in 1:nSims){ #for each simulated experiment | |
x<-rnorm(n = 23, mean = 100, sd = 20) #produce simulated participants | |
y<-rnorm(n = 23, mean = 114, sd = 20) #produce simulated participants | |
t<-t.test(x,y) #perform the t-test | |
if(t$p.value<0.05) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Adapted from on EV Nordheim, MK Clayton & BS Yandell https://www.stat.wisc.edu/~yandell/st571/R/append7.pdf | |
n.draw = 20 #number of tests you draw | |
mu = 0.3 #true difference | |
SD = 1 | |
#determine sample sizes for three tests | |
library(pwr) | |
pwr.t.test(d=0.3, power=0.9, sig.level=0.05, type = "one.sample", alternative="two.sided") | |
pwr.t.test(d=0.3, power=0.9, sig.level=0.01, type = "one.sample", alternative="two.sided") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#You will need to load the R package "hypergeo" to use the vstat function | |
library(hypergeo) | |
#Below, I'm vectorizing the function so that I can plot curves. | |
#The rest is unchanged from the vstat function by Stober-Davis & Dana. | |
#If you want to use R unbiased, remove the # before the Rsq adjustment calculation below | |
vstat <- Vectorize(function(n,p,Rsq) | |
{ | |
#Rsq = Re(1-((n-2)/(n-p))*(1-Rsq)*hypergeo(1,1,(n-p+2)*.5,1-Rsq)) |
OlderNewer