Last active
September 23, 2016 09:05
-
-
Save Lakens/fd8fe98fa38e7b6b7b87422cd6b2f70f to your computer and use it in GitHub Desktop.
Dance of the Bayes factors
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
if(!require(BayesFactor)){install.packages('BayesFactor')} | |
library(BayesFactor) | |
#to get emoticons for each test, set wait to 0.5 and showfaces to 1. | |
#When running large number of simulations, set wait to 0 and showfaces to 0. | |
options(scipen=20) #disable scientific notation for numbers | |
waitx<-0.5 #To see a small wait between individual trials, set a wait time to e.g., 0.5 | |
showfaces<-1 #Set to 0 if you do not want the faces, set to 1 if you want to see the faces | |
cohensd<-0.3 #set true effect size | |
n<-75 #sample size in each group | |
nSims <- 100 #number of simulated experiments (for large numbers, set wait to 0 and showfaces to 0) | |
for(i in 1:nSims){ #for each simulated experiment | |
x<-rnorm(n = n, mean = 0, sd = 1) #produce N simulated participants | |
y<-rnorm(n = n, mean = cohensd, sd = 1) #produce N simulated participants | |
z<-t.test(x,y) #perform the t-test | |
BF10<-exp(ttest.tstat(z$statistic,n,n,rscale=sqrt(2)/2)$bf) | |
if(BF10 < 0.1 & showfaces==1){cat(":D BF =",BF10,"\n\n")} | |
if(0.1 <= BF10 & BF10 < 1/3 & showfaces==1){cat(":) BF =",BF10,"\n\n")} | |
if(1/3 <= BF10 & BF10 < 3 & showfaces==1){cat("(._.) BF =",BF10,"\n\n")} | |
if(3 <= BF10 & BF10 < 10 & showfaces==1){cat(":( BF =",BF10,"\n\n")} | |
if(BF10>10 & showfaces==1){cat(":(( BF =",BF10,"\n\n")} | |
Sys.sleep(waitx) | |
} | |
#© Daniel Lakens, 2016. | |
# This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. https://creativecommons.org/licenses/by-nc-sa/4.0/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment