1pbetat=function(p0,prob,ab,data) 2{ 3# 4# PBETAT Performs a test that a proportion is equal to a specific value. 5# PBETAT(P0,PROB,AB,DATA) gives a vector of the Bayes factor and 6# the probability of the hypothesis P=P0, where P0 is the proportion 7# value to be tested, PROB is the prior probability of the hypothesis, 8# AB is the vector of parameters of the beta density under the 9# alternative hypothesis, and DATA is the vector of numbers of 10# successes and failures. 11#------------------------ 12# Written by Jim Albert 13# albert@bgnet.bgsu.edu 14# November 2004 15#------------------------ 16 17a=ab[1]; b=ab[2] 18s=data[1]; f=data[2] 19 20lbf=s*log(p0)+f*log(1-p0)+lbeta(a,b)-lbeta(a+s,b+f) 21 22bf=exp(lbf) 23post=prob*bf/(prob*bf+1-prob) 24 25return(list(bf=bf,post=post)) 26 27} 28