#Milton's example in Colada 78a, code written quickly in response to a comment by a reader
#Last updated:2019 09 06
#Please email Uri directly if you have any comments or see any errors (urisohn@gmail.com)
#####################################################################
#Function that computes the bayes factor for a null of 0% effect vs uniform between min and max
bf=function(ef,se,min,max)
#Syntax
#ef: the effect that is observed, ef=1.5 in the original example, ef=1 in the modified one
#se: the standard error of the effect, for example, se=.75 would lead to a Z=2
#min: smallest effect predicted by Milton
#max: biggest effect predicted by Milton
{
#Likelihood under the null
l0=dnorm(ef,mean=0,sd=se)
#Likelihood under the alternative
a=seq(min,max,.001) #consider values between min and max, in small increments
la=sum(dnorm(ef,mean=a,sd=se)*1/length(a)) #Likelihood of alterantive: poor-man's integral, sum in increement of .001
la/l0 #The bayes factor is the ratio o the likelihood for alterantive/null
}
#A reader suggested computing the Bayes factor for the original point estimate of 1.5%, with a SE=0.7%. With these numbers, you get BF=2.66, inconclusive but directionally sopporting alternative
bf(ef=1.5,se=.7,min=1,max=6) #the reader pointed out that if the SE=.7, BF=2.66
#here is the modified example
ef=1 #we observe 1%
min=1 #predict between 1% and 10%
max=10
bf(ef=ef,se=ef/1.649,min=1,max=10) #se=significant for a one sided test, since BF is one-sided too
#Modified example 2, context free and ultimately not used in the post
bf(ef=150,se=150/1.649,min=100,max=5000)