EasyBetaParms()
Finds a > 1 and b > 1 parameters for unimodal distribution, X ~ beta(a,b), where (a, b) correspond to (shape1, shape2) for pbeta(shape1, shape2) in R's base stats. Comments within this Rfunc's code summarize the theory. The example uses EasyBetaParms() to specify the prior distribution for a beta-binomial Bayesian solution for the one-sample proportion problem.
EasyBetaParms() is iIncluded within these Rfuncs: DensityPlotter().
Finds a > 1 and b > 1 parameters for unimodal distribution, X ~ beta(a,b), where (a, b) correspond to (shape1, shape2) for pbeta(shape1, shape2) in R's base stats. Comments within this Rfunc's code summarize the theory. The example uses EasyBetaParms() to specify the prior distribution for a beta-binomial Bayesian solution for the one-sample proportion problem.
- Current (first) version released 29 December 2016.
- Download EasyBetaParms.Rfunc161229.R
EasyBetaParms() is iIncluded within these Rfuncs: DensityPlotter().
Arguments
Mode=NA
Mode=NA
- mode of X. If used, then Mean= is ignored.
- mean of X.
- P*100% quantile of X.
- defines RelSpread.P, or P = c(P1, P2) defines Q = c(Q.P1, Q.P2).
- standard deviation of X. Mean= must be specified.
Object Returned
- A data.frame (unnamed) with one row and two columns: a and b. See example.
Example
This example is given in the "RunExamples" block of code in EasyBetaParms().
Suppose that Streptococcus heftans (fictitious) is an uncommon oral bacteria that has recently been found to cause rare heart infections affecting chambers and valves, especially in the elderly. The prevalence for S. heftans has never been rigorously estimated, but is believed to be less than 0.005 (0.5% of the population), is very likely to be less than 0.01, and is virtually certain to be less than 0.05. Maya Cardiya, PhD, tests 500 dental patients to determine whether each carries S. heftans among their oral flora. Her protocol's formal statistical plan calls for using the standard beta-binomial Bayesian methodology based on a skeptical prior distribution that sets the median of possible prevalences to be 0.01 and the 99% quantile to be 0.05.5.
Her collaborating statistician, Anne Ova, MS, uses EasyBetaParms() to determine a and b:
This example is given in the "RunExamples" block of code in EasyBetaParms().
Suppose that Streptococcus heftans (fictitious) is an uncommon oral bacteria that has recently been found to cause rare heart infections affecting chambers and valves, especially in the elderly. The prevalence for S. heftans has never been rigorously estimated, but is believed to be less than 0.005 (0.5% of the population), is very likely to be less than 0.01, and is virtually certain to be less than 0.05. Maya Cardiya, PhD, tests 500 dental patients to determine whether each carries S. heftans among their oral flora. Her protocol's formal statistical plan calls for using the standard beta-binomial Bayesian methodology based on a skeptical prior distribution that sets the median of possible prevalences to be 0.01 and the 99% quantile to be 0.05.5.
Her collaborating statistician, Anne Ova, MS, uses EasyBetaParms() to determine a and b:
> (prior <- EasyBetaParms(Mode=0.01,Q.P=0.05,P=0.99))
a b
1 2.451013 144.6503
Dr. Cardiya's protocol calls for one interim analysis near 50% of recruitment. Using this Bayesian approach avoids fretting about "alpha spending" to control multiple frequentist testing as data accumulate (e.g. using the O'Brien-Fleming method). Of the first 241 patients tested, 7 are positive for S. heftans. This yields a first posterior of beta(prior$a + 7, prior$b + 234) = beta(2.45 + 7, 144.65 + 234), giving a posterior median of
> qbeta(0.50, prior$a + 7, prior$b + 234) # median
[1] 0.023539
and a 95% credible (probability) interval of
> qbeta(c(0.025,0.975),prior$a + 7, prior$b + 234)
[1] 0.01147814 0.04183539
These results are greater than expected, but not unreasonably so.
Testing the final 247 patients finds 5 positives. Thus, the second posterior distribution is beta(prior$a + 7 + 5, prior$b + 234 + 242). The associated median and 95% credible interval are
Testing the final 247 patients finds 5 positives. Thus, the second posterior distribution is beta(prior$a + 7 + 5, prior$b + 234 + 242). The associated median and 95% credible interval are
> qbeta(0.50, prior$a + 7 + 5, prior$b + 234 + 242)
[1] 0.02225456
> qbeta(c(0.025,0.975), prior$a + 7 + 5, prior$b + 234 + 242)
[1] 0.01265088 0.03569048
For a "teaching moment," let us compare these results to those derived from two common approaches. (I would not recommend either alternative for this study, because both assume no knowledge of the prevalence.)
<1> A frequentist analysis:
> prop.test(x=12, n=488)
<snip>
95 percent confidence interval:
0.01337393 0.04376508
sample estimates:
p
0.02459016
<2> a beta-binomial Bayesian analysis with a uniform prior, i.e., prevalence ~ uniform(0, 1) = beta(1, 1).
> qbeta(0.50, 1+12, 1+476) # median
[1] 0.02588871
> qbeta(c(0.025,0.975), 1+12, 1+476) # 95% credible interval
[1] 0.01422960 0.04247359
Because both methods assume no prior knowledge about the prevalence, they give similar results—estimates leaning a little towards 0.50 and wider statistical intervals. In a sense, the the subjective (but skeptical!) prior of beta(2.5, 144.7) likens to having previously run a no-cost, no-time, no-work study of n = 146 and observing 1.5 positives.