Skip to content

Commit

Permalink
jfa version 0.1.0 (#9)
Browse files Browse the repository at this point in the history
* jfa version 0.1.0

* Update auditWorkflow.Rmd
  • Loading branch information
koenderks committed Dec 14, 2019
1 parent cf4477b commit 467306d
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 670 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
@@ -1,2 +1,4 @@
^\.travis\.yml$
cran-comments.md
^doc$
^Meta$
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
doc
Meta
6 changes: 3 additions & 3 deletions DESCRIPTION
@@ -1,17 +1,17 @@
Package: jfa
Title: A multi-functional R package for auditing
Version: 1.0.0
Version: 0.1.0
Authors@R:
person(given = "Koen",
family = "Derks",
role = c("aut", "cre"),
email = "k.derks@nyenrode.nl")
Description: The jfa package provides functions for daily use in auditing, such as calculating sample sizes, sampling, and calculating confidence bounds.
Description: Functions for daily use in auditing, such as calculating sample sizes, sampling, and evaluating samples by calculating confidence bounds.
Language: en-US
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.0.1
RoxygenNote: 7.0.2
VignetteBuilder: knitr
Suggests:
testthat, knitr, rmarkdown
4 changes: 2 additions & 2 deletions NEWS.md
@@ -1,3 +1,3 @@
# jfa 1.0.0
# jfa 0.1.0

First version of the `jfa` package.
First version of the `jfa` package. The package provides four functions: `auditPrior()`, `planning()`, `sampling()`, and `evaluation()`.
61 changes: 3 additions & 58 deletions R/auditPrior.R
Expand Up @@ -36,23 +36,18 @@
#'
#' @examples
#' library(jfa)
#' set.seed(1)
#'
#' # Generate some audit data (N = 1000).
#' population <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE),
#' bookValue = runif(n = 1000, min = 700, max = 1000))
#'
#' # Specify the materiality, confidence, and expected errors.
#' # Specify the materiality, confidence, and expected errors:
#' materiality <- 0.05 # 5%
#' confidence <- 0.95 # 95%
#' expectedError <- 0.025 # 2.5%
#'
#' # Specify the inherent risk (ir) and control risk (cr).
#' # Specify the inherent risk (ir) and control risk (cr):
#' ir <- 1 # 100%
#' cr <- 0.6 # 60%
#'
#' # Create a beta prior distribution according to the Audit Risk Model (arm)
#' # and a binomial likelihood.
#' # and a binomial likelihood:
#' prior <- auditPrior(materiality = materiality, confidence = confidence,
#' method = "arm", ir = ir, cr = cr,
#' expectedError = expectedError, likelihood = "binomial")
Expand All @@ -63,56 +58,6 @@
#' # Prior sample size: 51
#' # Prior errors: 1.27
#' # Prior: beta(2.275, 50.725)
#'
#' # Calculate the sample size according to the binomial distribution with the specified prior.
#' sampleSize <- planning(materiality = materiality, confidence = confidence,
#' expectedError = expectedError, prior = prior, likelihood = "binomial")
#' print(sampleSize)
#'
#' # 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
#'
#' # Draw sample using random monetary unit sampling.
#' sampleResult <- sampling(population = population, sampleSize = sampleSize,
#' algorithm = "random", units = "mus", seed = 1, bookValues = "bookValue")
#' print(sampleResult)
#'
#' # jfa sampling results for random monetary unit sampling:
#' #
#' # Population size: 1000
#' # Sample size: 169
#' # Proportion n/N: 0.169
#' # Precentage of value: 16.84%
#'
#' # Isolate the sample.
#' sample <- sampleResult$sample
#'
#' # For this example, we use the book values as audit values. Implies zero errors at this point.
#' sample$trueValue <- sample$bookValue
#'
#' # One overstatement is found.
#' sample$trueValue[2] <- sample$trueValue[2] - 500
#'
#' # Evaluate the sample with one partial error using the posterior distribution.
#' conclusion <- evaluation(sample = sample, bookValues = "bookValue", auditValues = "trueValue",
#' prior = prior, materiality = 0.05)
#' print(conclusion)
#'
#' # jfa evaluation results for binomial likelihood with prior:
#' #
#' # Materiality: 5%
#' # Confidence: 95%
#' # Upper bound: 2.729%
#' # Sample size: 169
#' # Sample errors: 1
#' # Conclusion: Approve population
#'
#' @export

auditPrior <- function(materiality, confidence = 0.95, method = "arm", ir = 1, cr = 1,
Expand Down
60 changes: 30 additions & 30 deletions R/evaluation.R
Expand Up @@ -86,50 +86,50 @@
#'
#' @examples
#' library(jfa)
#'
#' # Generate some audit data (N = 1000)
#' set.seed(1)
#'
#' # Generate some audit data (N = 1000):
#' data <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE),
#' bookValue = runif(n = 1000, min = 700, max = 1000))
#'
#' # Using the binomial likelihood, calculates the upper 95% confidence bound for a
#' # materiality of 5% when 1% full errors are found in a sample (n = 93).
#' jfaRes <- planning(materiality = 0.05, confidence = 0.95, expectedError = 0.01,
#' likelihood = "binomial")
#'
#' bookValue = runif(n = 1000, min = 700, max = 1000))
#'
#' # Using monetary unit sampling, draw a random sample from the population.
#' samp <- sampling(population = data, sampleSize = jfaRes, units = "mus",
#' bookValues = "bookValue", algorithm = "random")
#'
#' samp$sample$trueValue <- samp$sample$bookValue
#' samp$sample$trueValue[2] <- samp$sample$trueValue[2] - 500 # One overstatement is found
#'
#' # Evaluate the sample using the stringer bound.
#' conclusion <- evaluation(sample = samp$sample, bookValues = "bookValue",
#' auditValues = "trueValue", method = "stringer", materiality = 0.05)
#' print(conclusion)
#' s1 <- sampling(population = data, sampleSize = 100, units = "mus",
#' bookValues = "bookValue", algorithm = "random")
#' s1_sample <- s1$sample
#' s1_sample$trueValue <- s1_sample$bookValue
#' s1_sample$trueValue[2] <- s1_sample$trueValue[2] - 500 # One overstatement is found
#'
#' # jfa evaluation results for stringer method:
#' # Using summary statistics, calculate the upper confidence bound according
#' # to the binomial distribution:
#'
#' e1 <- evaluation(nSumstats = 100, kSumstats = 1, method = "binomial",
#' materiality = 0.05)
#' print(e1)
#'
#' # jfa evaluation results for binomial method:
#' #
#' # Materiality: 5%
#' # Confidence: 95%
#' # Upper bound: 4.244%
#' # Sample size: 93
#' # Upper bound: 4.656%
#' # Sample size: 100
#' # Sample errors: 1
#' # Sum of taints: 1
#' # Conclusion: Approve population
#'
#' # Evaluate the sample using summary statistics (n = 93, k = 1).
#' conclusion <- evaluation(nSumstats = 93, kSumstats = 1, method = "binomial",
#' materiality = 0.05)
#' print(conclusion)
#'
#' # jfa evaluation results for binomial method:
#' # Evaluate the raw sample using the stringer bound:
#'
#' e2 <- evaluation(sample = s1_sample, bookValues = "bookValue", auditValues = "trueValue",
#' method = "stringer", materiality = 0.05)
#' print(e2)
#'
#' # jfa evaluation results for stringer method:
#' #
#' # Materiality: 5%
#' # Confidence: 95%
#' # Upper bound: 4.999%
#' # Sample size: 93
#' # Upper bound: 3.952%
#' # Sample size: 100
#' # Sample errors: 1
#' # Sum of taints: 0.587
#' # Conclusion: Approve population
#'
#' @keywords evaluation confidence bound audit
Expand Down
2 changes: 1 addition & 1 deletion R/hidden.R
Expand Up @@ -36,7 +36,7 @@ print.jfaSampling <- function(x, ...){
#
# Population size: ", nrow(x$population),"
# Sample size: ", nrow(x$sample),"
# Proportion n/N: ", round(nrow(x$sample)/nrow(x$population)), 3)
# Proportion n/N: ", round(nrow(x$sample)/nrow(x$population), 3))
}
}

Expand Down
55 changes: 45 additions & 10 deletions R/planning.R
Expand Up @@ -48,17 +48,51 @@
#' # 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.
#' planning(materiality = 0.05, confidence = 0.95, expectedError = 0.025,
#' likelihood = "binomial")
#' # Frequentist planning with binomial likelihood:
#'
#' # Bayesian planning with uninformed prior.
#' planning(materiality = 0.05, confidence = 0.95, expectedError = 0.025,
#' likelihood = "binomial", prior = TRUE)
#' p1 <- planning(materiality = 0.05, confidence = 0.95, expectedError = 0.025,
#' likelihood = "binomial")
#' print(p1)
#'
#' # Bayesian planning with informed prior (based on 10 correct observations).
#' planning(materiality = 0.05, confidence = 0.95, expectedError = 0.025,
#' likelihood = "binomial", prior = TRUE, kPrior = 0, nPrior = 10)
#' # 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
#'
#' @keywords planning sample size audit
#'
Expand Down Expand Up @@ -129,7 +163,8 @@ planning <- function(materiality, confidence = 0.95, expectedError = 0, likeliho
break
}
} else {
prob <- stats::dbinom(0:ceiling(implicitK), size = i, prob = materiality)
implicitK <- ceiling(implicitK)
prob <- stats::dbinom(0:implicitK, size = i, prob = materiality)
if(sum(prob) < (1 - confidence)){
ss <- i
break
Expand Down
38 changes: 28 additions & 10 deletions R/sampling.R
Expand Up @@ -48,22 +48,40 @@
#'
#' @examples
#' library(jfa)
#' set.seed(1)
#'
#' # Generate some audit data (N = 1000).
#' population <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE),
#' bookValue = runif(n = 1000, min = 700, max = 1000))
#'
#' # Calculate the sample size according to the binomial distribution with zero errors
#' jfaRes <- planning(materiality = 0.05, confidence = 0.95, expectedError = 0,
#' likelihood = "binomial")
#'
#' # Draw sample using random record sampling
#' sampling(population = population, sampleSize = jfaRes, algorithm = "random",
#' units = "records", seed = 1)
#' # Draw a custom sample of 100 from the population (via random record sampling):
#'
#' s1 <- sampling(population = population, sampleSize = 100, algorithm = "random",
#' units = "records", seed = 1)
#' print(s1)
#'
#' # jfa sampling results for random random record sampling:
#' #
#' # Population size: 1000
#' # Sample size: 100
#' # Proportion n/N: 0.1
#'
#' # Use the result from the planning stage in the sampling stage:
#'
#' p1 <- planning(materiality = 0.05, confidence = 0.95, expectedError = 0.025,
#' likelihood = "binomial")
#'
#' # Draw a sample via random monetary unit sampling:
#' s2 <- sampling(population = population, sampleSize = p1, algorithm = "random",
#' units = "mus", seed = 1, bookValues = "bookValue")
#' print(s2)
#'
#' # Draw sample using random monetary unit sampling
#' sampling(population = population, sampleSize = jfaRes, algorithm = "random",
#' units = "mus", bookValues = "bookValue", seed = 1)
#' # jfa sampling results for random monetary unit sampling:
#' #
#' # Population size: 1000
#' # Sample size: 234
#' # Proportion n/N: 0.234
#' # Percentage of value: 23.3%
#'
#' @keywords sampling sample audit
#'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -19,7 +19,7 @@
* [Functions](##Functions)
* [Poster](##Poster)

For complete documentation, see the package [manual](./man/manual/jfa_1.0.0.pdf). For a complete example, see the package [vignette](./vignettes/jfaVignette.html).
For complete documentation, see the package [manual](./man/manual/jfa_0.1.0.pdf). For a complete example, see the package [vignette](./vignettes/jfaVignette.html).

### Authors

Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Expand Up @@ -6,4 +6,4 @@
There were no ERRORs or WARNINGs or NOTEs.

## Downstream dependencies
There are currently no downstream dependencies for this package
There are currently no downstream dependencies for this package.

0 comments on commit 467306d

Please sign in to comment.