betaci {CPTtools} | R Documentation |
This generates upper and lower bounds for a highest posterior density credibility interval for a beta distribution by looking at appropriate quantiles of the beta distribution. This is designed to work with sums of classification probabilities.
betaci(sumData, totals = NULL, limits = c(lower = 0.025, upper = 0.975), a = 0.5, b = 0.5)
sumData |
Counts or averages of proportions. Note these do not need to be integers, sums of classification probabilities work here. |
totals |
Total number of individuals as reference for
|
limits |
The upper and lower credibility limits. |
a |
Value for the |
b |
Value for the |
This function computes the upper and lower bounds of a credibility
interval for a beta distribution based on sumData
successes out
of totals
trials. Note that as a beta distribution is used for
the basic calculations, neither sumData
nor totals
need
be integers.
To avoid problems with zero cells (or cells with values equal to
totals
), a small prior is added to the beta calculations. By
default a Jeffrey's prior (.5,.5) is added to the data. Thus the
final returned value is:
\code{qbeta}(prob,sumData+a,totals-sumData+b)
where prob
varies over the values in limits
. Note that
a
and b
can be scalars or an array conformable with
totals
.
A list of the same length as limits
with the same names. Each
component is a quantile of the posterior distribution which has the
same shape as sumData
.
Note that limits
is not limited to length 2, although this is
the most obvious application.
Russell Almond
See OCP
for an application.
x <- matrix(c(7,4,2,31),2,2) ## Use column sums as totals betaci(x) ## fixed totals nn <- matrix(c(30,15,20,35),2,2) betaci(x,nn) ## Prior varies according to cell. pi0 <- c(.2,.2,.2,.8) betaci(x,nn,a=pi0,b=1-pi0)