#This function computes the BF for a set of 2-sample t-tests. # Based on formulas in Rouder & Morey (2011) # BF>1 indicates evidence for alternative hypothesis # when more than one t-value is provided, it computes a meta-BF. # Calculations verified relative to earlier MatLab code by GF. # Largely follows code by Richard Morey (one correction to df) # gfrancis@purdue.edu # July 15, 2013 BF2N = function(t,N1,N2,lo=-Inf,up=Inf){ result = marglike(t,N1, N2,lo=lo,up=up)/exp(sum(dt(t,(N1+N2-2),log=TRUE))) return(result) } # Helper functions int1 = function(delta,t,N1, N2){ exp(sum(dt(t,df=(N1+N2-2),ncp=delta*sqrt(N1*N2/(N1+N2)),log=TRUE)) + dcauchy(delta,log=TRUE)) } v.int1 =Vectorize(int1,"delta") marglike = function(t,N1, N2,lo=-Inf,up=Inf){ integrate(v.int1,lo,up,N1=N1, N2=N2,t=t)[[1]] }