Learn R Programming

jfa (version 0.1.0)

planning: Frequentist and Bayesian Planning for Audit Samples

Description

This function calculates the required sample size for an audit, based on the poisson, binomial, or hypergeometric likelihood. A prior can be specified to perform Bayesian planning. The returned object is of class jfaPlanning and can be used with associated print() and plot() methods.

Usage

planning(materiality, confidence = 0.95, expectedError = 0, likelihood = "poisson", 
         N = NULL, maxSize = 5000, prior = FALSE, kPrior = 0, nPrior = 0)

Arguments

materiality

a value between 0 and 1 representing the materiality of the audit as a fraction of the total size or value.

confidence

the confidence level desired from the confidence bound (on a scale from 0 to 1). Defaults to 0.95, or 95% confidence.

expectedError

a fraction representing the percentage of expected mistakes in the sample relative to the total size, or a number (>= 1) that represents the number of expected mistakes.

likelihood

can be one of binomial, poisson, or hypergeometric.

N

the population size (required for hypergeometric calculations).

maxSize

the maximum sample size that is considered for calculations. Defaults to 5000 for efficiency. Increase this value if the sample size cannot be found due to it being too large (e.g., for a low materiality).

prior

whether to use a prior distribution when planning. Defaults to FALSE for frequentist planning. If TRUE, the prior distribution is updated by the specified likelihood. Chooses a conjugate gamma distribution for the Poisson likelihood, a conjugate beta distribution for the binomial likelihood, and a conjugate beta-binomial distribution for the hypergeometric likelihood.

kPrior

the prior parameter \(\alpha\) (number of errors in the assumed prior sample).

nPrior

the prior parameter \(\beta\) (total number of observations in the assumed prior sample).

Value

An object of class jfaPlanning containing:

materiality

the value of the specified materiality.

confidence

the confidence level for the desired population statement.

sampleSize

the resulting sample size.

expectedSampleError

the number of full errors that are allowed to occur in the sample.

expectedError

the specified number of errors as a fraction or as a number.

likelihood

the specified likelihood.

errorType

whether the expected errors where specified as a percentage or as an integer.

N

the population size (only returned in case of a hypergeometric likelihood).

populationK

the assumed population errors (only returned in case of a hypergeometric likelihood).

prior

a list containing information on the prior parameters.

Details

This section elaborates on the available likelihoods and corresponding prior distributions for the likelihood argument.

  • poisson: The Poisson likelihood is used as a likelihood for monetary unit sampling (MUS). Its likelihood function is defined as: $$p(x) = \frac{\lambda^x e^{-\lambda}}{x!}$$ The conjugate gamma(\(\alpha, \beta\)) prior has probability density function: $$f(x; \alpha, \beta) = \frac{\beta^\alpha x^{\alpha - 1} e^{-\beta x}}{\Gamma(\alpha)}$$

  • binomial: The binomial likelihood is used as a likelihood for record sampling with replacement. Its likelihood function is defined as: $$p(x) = {n \choose k} p^k (1 - p)^{n - k}$$ The conjugate beta(\(\alpha, \beta\)) prior has probability density function: $$f(x; \alpha, \beta) = \frac{1}{B(\alpha, \beta)} x^{\alpha - 1} (1 - x)^{\beta - 1}$$

  • hypergeometric: The hypergeometric likelihood is used as a likelihood for record sampling without replacement. Its likelihood function is defined as: $$p(x = k) = \frac{{K \choose k} {N - K \choose n - k}}{{N \choose n}}$$ The conjugate beta-binomial(\(\alpha, \beta\)) prior (Dyer and Pierce, 1993) has probability density function: $$f(k | n, \alpha, \beta) = {n \choose k} \frac{B(k + \alpha, n - k + \beta)}{B(\alpha, \beta)}$$

References

Dyer, D. and Pierce, R.L. (1993). On the Choice of the Prior Distribution in Hypergeometric Sampling. Communications in Statistics - Theory and Methods, 22(8), 2125 - 2146.

See Also

auditPrior sampling evaluation

Examples

Run this code
# NOT RUN {
library(jfa)

# Using the binomial distribution, calculates the required sample size for a 
# materiality of 5% when 2.5% mistakes are expected to be found in the sample.

# Frequentist planning with binomial likelihood:

p1 <- planning(materiality = 0.05, confidence = 0.95, expectedError = 0.025, 
               likelihood = "binomial")
print(p1)

# jfa planning results for binomial likelihood:
#      
# Materiality:             5% 
# Confidence:              95% 
# Sample size:             234 
# Allowed sample errors:   6

# Bayesian planning with uninformed prior:

p2 <- planning(materiality = 0.05, confidence = 0.95, expectedError = 0.025, 
               likelihood = "binomial", prior = TRUE)
print(p2)

# jfa planning results for beta prior with binomial likelihood:
#      
# Materiality:             5% 
# Confidence:              95% 
# Sample size:             220 
# Allowed sample errors:   5.5 
# Prior parameter alpha:   1 
# Prior parameter beta:    1

# Bayesian planning with informed prior:

prior <- auditPrior(materiality = 0.05, confidence = 0.95, cr = 0.6, 
                    expectedError = 0.025, likelihood = "binomial")

p3 <- planning(materiality = 0.05, confidence = 0.95, expectedError = 0.025,
               prior = prior)
print(p3)

# jfa planning results for beta prior with binomial likelihood:
#      
# Materiality:             5% 
# Confidence:              95% 
# Sample size:             169 
# Allowed sample errors:   4.23 
# Prior parameter alpha:   2.275 
# Prior parameter beta:    50.725

# }

Run the code above in your browser using DataLab