Skip to content

Commit f6f4b87

Browse files
committed
Ready for 0.5.0
1 parent a242c96 commit f6f4b87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4360
-188
lines changed

.Rbuildignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
^\.travis\.yml$
1+
^.yml$
22
^cran-comments.md$
33
^codecov.yml$
44
^.github$

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
doc
2-
Meta
31
docs
2+
Meta

.travis.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: jfa
22
Title: Bayesian and Classical Audit Sampling
33
Version: 0.5.0
4-
Date: 2020-11-07
4+
Date: 2021-01-04
55
Authors@R:
66
person(given = "Koen",
77
family = "Derks",

Meta/vignette.rds

407 Bytes
Binary file not shown.

R/auditPrior.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ auditPrior <- function(confidence = 0.95, likelihood = "binomial", method = "non
129129
if(likelihood == "hypergeometric" && (is.null(N) || N <= 0))
130130
stop("The hypergeometric likelihood requires that you specify a positive value for the populatin size N.")
131131

132-
if(expectedError >= 1 || expectedError < 0)
133-
stop("The expected errors must be entered as a proportion.")
132+
if(expectedError < 0)
133+
stop("The expected errors must be zero or larger than zero.")
134+
135+
if(expectedError >= 1 && method != "none")
136+
stop("The expected errors must be entered as a proportion to use this prior construction method.")
134137

135138
# Create the prior distribution depending on the specified method
136139
if(method == "none"){

R/evaluation.R

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Evaluation of Audit Samples using Confidence / Credible Bounds
22
#'
3-
#' @description This function takes a data frame (using \code{sample}, \code{bookValue}, and \code{auditValues}) or summary statistics (using \code{nSumstats} and \code{kSumstats}) and evaluates the audit sample according to the specified method. The returned object is of class \code{jfaEvaluation} and can be used with associated \code{print()} and \code{plot()} methods.
3+
#' @description This function takes a data frame (using \code{sample}, \code{bookValues}, and \code{auditValues}) or summary statistics (using \code{nSumstats} and \code{kSumstats}) and evaluates the audit sample according to the specified method. The returned object is of class \code{jfaEvaluation} and can be used with associated \code{print()} and \code{plot()} methods.
44
#'
55
#' For more details on how to use this function see the package vignette:
66
#' \code{vignette("jfa", package = "jfa")}
@@ -14,7 +14,7 @@
1414
#' csA = 1, csB = 3, csMu = 0.5)
1515
#'
1616
#' @param confidence the required confidence level for the bound. Default is 0.95 for 95\% confidence.
17-
#' @param method the method that is used to evaluate the sample. This can be either one of \code{poisson}, \code{binomial}, \code{hypergeometric}, \code{stringer}, \code{stringer-meikle}, \code{stringer-lta}, \code{stringer-pvz}, \code{rohrbach}, \code{moment}, \code{direct}, \code{difference}, \code{quotient}, or \code{regression}.
17+
#' @param method the method that is used to evaluate the sample. This can be either one of \code{poisson}, \code{binomial}, \code{hypergeometric}, \code{mpus}, \code{stringer}, \code{stringer-meikle}, \code{stringer-lta}, \code{stringer-pvz}, \code{rohrbach}, \code{moment}, \code{direct}, \code{difference}, \code{quotient}, or \code{regression}.
1818
#' @param N an integer specifying the total number of units (transactions or monetary units) in the population.
1919
#' @param sample a data frame containing at least a column of Ist values and a column of Soll (true) values.
2020
#' @param bookValues a character specifying the column name for the Ist values in the sample.
@@ -40,6 +40,7 @@
4040
#' \item{\code{poisson}: The confidence bound taken from the Poisson distribution. If combined with \code{prior = TRUE}, performs Bayesian evaluation using a \emph{gamma} prior and posterior.}
4141
#' \item{\code{binomial}: The confidence bound taken from the binomial distribution. If combined with \code{prior = TRUE}, performs Bayesian evaluation using a \emph{beta} prior and posterior.}
4242
#' \item{\code{hypergeometric}: The confidence bound taken from the hypergeometric distribution. If combined with \code{prior = TRUE}, performs Bayesian evaluation using a \emph{beta-binomial} prior and posterior.}
43+
#' \item{\code{mpu}}: Mean per unit estimator using the observed sample taints.
4344
#' \item{\code{stringer}: The Stringer bound (Stringer, 1963).}
4445
#' \item{\code{stringer-meikle}: Stringer bound with Meikle's correction for understatements (Meikle, 1972).}
4546
#' \item{\code{stringer-lta}: Stringer bound with LTA correction for understatements (Leslie, Teitlebaum, and Anderson, 1979).}
@@ -187,13 +188,13 @@ evaluation <- function(confidence = 0.95, method = "binomial", N = NULL,
187188
if(!is.null(minPrecision) && minPrecision == 0)
188189
stop("The minimum required precision cannot be zero.")
189190

190-
if(!(method %in% c("poisson", "binomial", "hypergeometric", "stringer", "stringer-meikle", "stringer-lta", "stringer-pvz", "rohrbach", "moment", "coxsnell", "direct", "difference", "quotient", "regression")) || length(method) != 1)
191+
if(!(method %in% c("poisson", "binomial", "hypergeometric", "stringer", "stringer-meikle", "stringer-lta", "stringer-pvz", "rohrbach", "moment", "coxsnell", "direct", "difference", "quotient", "regression", "mpu")) || length(method) != 1)
191192
stop("Specify a valid method for the evaluation.")
192193

193194
if(!is.null(counts) && any(counts < 1))
194195
stop("When specified, your 'counts' must all be equal to, or larger than, 1.")
195196

196-
if(((class(prior) == "logical" && prior == TRUE) || class(prior) == "jfaPrior") && method %in% c("stringer", "stringer-meikle", "stringer-lta", "stringer-pvz", "rohrbach", "moment", "direct", "difference", "quotient", "regression"))
197+
if(((class(prior) == "logical" && prior == TRUE) || class(prior) == "jfaPrior") && method %in% c("stringer", "stringer-meikle", "stringer-lta", "stringer-pvz", "rohrbach", "moment", "direct", "difference", "quotient", "regression", "mpu"))
197198
stop("To use a prior distribution, you must use either the poisson, the binomial, or the hypergeometric method.")
198199

199200
if((class(prior) == "logical" && prior == TRUE) && kPrior < 0 || nPrior < 0)
@@ -208,7 +209,7 @@ evaluation <- function(confidence = 0.95, method = "binomial", N = NULL,
208209
stop("Specify one value for nSumstat and kSumstat")
209210
if(kSumstats > nSumstats)
210211
stop("The sum of the errors is higher than the sample size")
211-
if(method %in% c("stringer", "stringer-meikle", "stringer-lta", "stringer-pvz", "coxsnell", "rohrbach", "moment", "direct", "difference", "quotient", "regression"))
212+
if(method %in% c("stringer", "stringer-meikle", "stringer-lta", "stringer-pvz", "coxsnell", "rohrbach", "moment", "direct", "difference", "quotient", "regression", "mpu"))
212213
stop("The selected method requires raw observations, and does not accomodate summary statistics")
213214

214215
n <- nSumstats
@@ -220,10 +221,11 @@ evaluation <- function(confidence = 0.95, method = "binomial", N = NULL,
220221
if(is.null(bookValues) || is.null(auditValues) || length(bookValues) != 1 || length(auditValues) != 1)
221222
stop("Specify a valid book value column name and a valid audit value column name when using a sample")
222223

223-
sample <- stats::na.omit(sample)
224-
n <- nrow(sample)
225-
if(n == 0)
224+
missingValues <- unique(c(which(is.na(sample[, bookValues])), which(is.na(sample[, auditValues]))))
225+
if(length(missingValues) == nrow(sample))
226226
stop("Your sample has 0 rows after removing missing values.")
227+
sample <- stats::na.omit(sample)
228+
n <- nrow(sample)
227229
if(!is.null(counts))
228230
n <- sum(counts)
229231
bv <- sample[, bookValues]
@@ -319,6 +321,11 @@ evaluation <- function(confidence = 0.95, method = "binomial", N = NULL,
319321
bound <- out[["confBound"]]
320322
mle <- out[["mle"]]
321323
precision <- out[["precision"]]
324+
} else if(method == "mpu"){
325+
out <- .mpuMethod(taints, confidence, n)
326+
bound <- out[["confBound"]]
327+
mle <- out[["mle"]]
328+
precision <- out[["precision"]]
322329
} else if(method == "direct"){
323330
out <- .directMethod(bv, av, confidence, N, n, populationBookValue)
324331
mle <- out[["pointEstimate"]]

R/methods.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@
116116
return(result)
117117
}
118118

119+
.mpuMethod <- function(taints, confidence, n){
120+
result <- list()
121+
result[["confBound"]] <- mean(taints) + stats::qnorm(p = confidence) * (stats::sd(taints) / sqrt(n))
122+
result[["mle"]] <- sum(taints) / n
123+
result[["precision"]] <- result[["confBound"]] - result[["mle"]]
124+
return(result)
125+
}
126+
119127
.directMethod <- function(bookValues, auditValues, confidence, N = NULL, n, populationBookValue = NULL, correction = FALSE){
120128
if(is.null(N))
121129
stop("The direct method requires that you specify the population size N")

R/planning.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Frequentist and Bayesian Planning for Audit Sampling
22
#'
3-
#' @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 \code{jfaPlanning} and can be used with associated \code{print()} and \code{plot()} methods.
3+
#' @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 \code{jfaPlanning} and can be used with associated \code{print()} and \code{plot()} methods.
44
#'
55
#' For more details on how to use this function see the package vignette:
66
#' \code{vignette("jfa", package = "jfa")}

R/report.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#'
1010
#' @param object an object of class 'jfaEvaluation' as returned by the \code{evaluation()} function.
1111
#' @param file a string that gives the desired name of the file (e.g. \code{"report.html"}). The report is created in your current working directory.
12-
#' @param format can be either one of \code{"html_document"} or \code{"pdf_document"} (required MikTex).
12+
#' @param format can be either one of \code{"html_document"} or \code{"pdf_document"} (compiling to pdf requires MikTex).
1313
#'
1414
#' @return A html or pdf report containing the results of the evaluation.
1515
#'

0 commit comments

Comments
 (0)