Learn R Programming

jfa (version 0.4.0)

planning: Frequentist and Bayesian Planning for Audit Sampling

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(confidence = 0.95, expectedError = 0, likelihood = "poisson", N = NULL, 
          materiality = NULL, minPrecision = NULL, 
          prior = FALSE, kPrior = 0, nPrior = 0,
          increase = 1, maxSize = 5000)

Arguments

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).

materiality

a value between 0 and 1 representing the materiality of the audit as a fraction of the total size or value. Can be NULL, but minPrecision should be specified in that case.

minPrecision

The minimum precision to be obtained. Can be NULL, but materiality should be specified in that case.

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).

increase

the desired increase step for the sample size calculation.

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).

Value

An object of class jfaPlanning containing:

confidence

the confidence level for the desired population statement.

expectedError

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

likelihood

the specified likelihood.

N

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

materiality

the value of the specified materiality. Can be NULL.

minPrecision

The minimum precision to be obtained. Can be NULL.

sampleSize

the resulting sample size.

errorType

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

expectedSampleError

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

expectedBound

a value specifying the expected upper bound if the sample goes according to plan.

expectedPrecision

a value specifying the expected precision if the sample goes according to plan.

populationK

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

prior

an object of class jfaPrior that represents the prior distribution.

expectedPosterior

an object of class jfaPosterior that represents the expected posterior distribution.

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 selection 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(confidence = 0.95, expectedError = 0.025, likelihood = "binomial",
               materiality = 0.05)
print(p1)

# ------------------------------------------------------------
#              jfa Planning Summary (Frequentist)
# ------------------------------------------------------------     
# Input:
# 
# Confidence:              95% 
# Materiality:             5% 
# Minimum precision:       Not specified 
# Likelihood:              binomial 
# Expected sample errors:  6 
# ------------------------------------------------------------
# Output:
#
# Sample size:             234 
# ------------------------------------------------------------
# Statistics:
#
# Expected upper bound:    5% 
# Expected precision:      2.43% 
# ------------------------------------------------------------ 

# Bayesian planning with prior:

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

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

# ------------------------------------------------------------
#              jfa Planning Summary (Bayesian)
# ------------------------------------------------------------
# Input:
# 
# Confidence:              95%      
# Materiality:             5% 
# Minimum precision:       Not specified 
# Likelihood:              binomial 
# Prior distribution:      beta(2.275, 50.725) 
# Expected sample errors:  4.23 
# ------------------------------------------------------------
# Output:
#
# Sample size:             169 
# Posterior distribution:  beta(6.5, 215.5) 
# ------------------------------------------------------------
# Statistics:
#
# Expected upper bound:    4.99% 
# Expected precision:      2.49% 
# Expected Bayes factor-+: 9.32 
# ------------------------------------------------------------ 

# }

Run the code above in your browser using DataLab