https://www.lexjansen.com/phuse/2011/sp/SP08.pdf
In the above (short) paper, the authors present an approach for a one-sample Bayesian proportion test with uninformed and informed priors. Below I have presented code for the informed setting, which consists of just a few lines of code. However, something about the approach isn't clicking in my head. I think first issue is that in the past I have done most of my Bayesian analyses via MCMC and not much experience with beta distribution.
What is tripping me up in particular is:
where: x = # events
n = # trials
alpha = alpha for prior
beta = beta for prior
Ho = is the value for hypothesis
So to test this, you just need to add #events to alpha for a and number of trials for non-events plus disperse for b? This part just isn't clicking. Any insight would be appreciated. Here is the full code:
In the above (short) paper, the authors present an approach for a one-sample Bayesian proportion test with uninformed and informed priors. Below I have presented code for the informed setting, which consists of just a few lines of code. However, something about the approach isn't clicking in my head. I think first issue is that in the past I have done most of my Bayesian analyses via MCMC and not much experience with beta distribution.
What is tripping me up in particular is:
Code:
a=&x+α
b=&n-&x+β
x1=probbeta(&H0,a,b);
n = # trials
alpha = alpha for prior
beta = beta for prior
Ho = is the value for hypothesis
So to test this, you just need to add #events to alpha for a and number of trials for non-events plus disperse for b? This part just isn't clicking. Any insight would be appreciated. Here is the full code:
Code:
/******************************NOTES**********************************************/
/*Bayesian macro to test two hypotheses with a Beta prior distribution
(Beta (alpha,beta));
Variables and parameters needed
x: number of successes in the sample
n: sample size
Alpha: alpha parameter of the prior beta distribution
Beta: beta parameter of the prior beta distribution
H0: Null hypothesis
H1: Alternative hypothesis
The conjugate distribution is a Beta(x+alpha,n-x+beta)
****************************************************************************/
%MACRO Bayes_test (x=,n=,H0=,H1=,alpha=,beta=);
DATA bayes1;
length test $255.;
a=&x+α
b=&n-&x+β
h0="p<="||left(trim(&H0));
h1="p>"||left(trim(&H1));
x=&x;
n=&n;
x1=probbeta(&H0,a,b);
x2=1-probbeta(&H1,a,b);
If x1>x2 then test='H0 is more probable than H1';
else if x1<x2 then test='H1 is more probable than H0';
else if x1=x2 then test='Equally probable hypotheses';
run;
Proc print data=bayes1 noobs l;
var h0 h1 x n test x1 x2;
label h0='H0' h1='H1' x='X' n='N' test='Test' x1='Prob. under H0' x2='Prob. under H1';
title "Bayes test of &x successes in &n samples";
footnote "Prior distribution Beta (&alpha,&beta)";
run;
title;
footnote;
%MEND Bayes_test;
%Bayes_test (x=24,n=40,H0=0.40,H1=0.60,alpha=12,beta=12);