betaci: Credibility intervals for a proportion based on beta...

betaciR Documentation

Credibility intervals for a proportion based on beta distribution

Description

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.

Usage

betaci(sumData, totals = NULL, limits = c(lower = 0.025, upper = 0.975),
       a = 0.5, b = 0.5)

Arguments

sumData

A vector or matrix of counts or sums proportions. Note these do not need to be integers, sums of classification probabilities work here.

totals

Total number of individuals as reference for sumData. If missing or NULL then the value use is rowSums(data).

limits

The upper and lower credibility limits.

a

Value for the shape1 parameter of the beta prior.

b

Value for the shape2 parameter of the beta prior.

Details

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.

If totals is not supplied, and sumData is a vector, then the sum is used as the total. If the totals is not supplied and sumData is a matrix, then the row sums are used. For higher dimensional arrays, it is necessary to explicitly specify a total.

Value

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.

Note

A previous verison used colSums(data) rather than rowSums(). Using the row sums makes more sense as this corresponds to the CPF format.

Author(s)

Russell Almond

See Also

See OCP for an application.

Examples


x <- matrix(c(7,4,2,31),2,2)
## Use row sums as totals
betaci(x)

## fixed totals
x <- c(7,2,31)
nn <- c(30,15,35)
betaci(x,nn,c(Q1=.25,Q2=.5,Q3=.75))

## Prior varies according to cell.
pi0 <- c(.2,.2,.8)
betaci(x,nn,a=pi0,b=1-pi0)


ralmond/CPTtools documentation built on Dec. 27, 2024, 7:15 a.m.