-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
4,253 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ | |
#' \item{populationK}{the assumed total errors in the population. Used in inferences with \code{hypergeometric} method.} | ||
#' \item{prior}{an object of class 'jfaPrior' to represents the prior distribution.} | ||
#' \item{posterior}{an object of class 'jfaPosterior' to represents the posterior distribution.} | ||
#' \item{data}{a data frame containing the relevant columns from the \code{sample} input.} | ||
#' | ||
#' @author Koen Derks, \email{[email protected]} | ||
#' | ||
|
@@ -357,10 +358,10 @@ evaluation <- function(confidence = 0.95, method = "binomial", N = NULL, | |
result[["mle"]] <- as.numeric(mle) | ||
if(!is.null(precision)) | ||
result[["precision"]] <- as.numeric(precision) | ||
if(!is.null(populationBookValue)) | ||
result[["popBookvalue"]] <- as.numeric(populationBookValue) | ||
if(method %in% c("direct", "difference", "quotient", "regression")){ | ||
# These methods yield an interval instead of a bound | ||
result[["popBookvalue"]] <- as.numeric(populationBookValue) | ||
result[["pointEstimate"]] <- as.numeric(out[["pointEstimate"]]) | ||
result[["lowerBound"]] <- as.numeric(out[["lowerBound"]]) | ||
result[["upperBound"]] <- as.numeric(out[["upperBound"]]) | ||
} else { | ||
|
@@ -377,12 +378,17 @@ evaluation <- function(confidence = 0.95, method = "binomial", N = NULL, | |
result[["populationK"]] <- as.numeric(populationK) | ||
# Produce relevant conclusions conditional on the analysis result | ||
approvePrecision <- TRUE | ||
if(minPrecision != 1) | ||
approvePrecision <- result[["precision"]] <= minPrecision | ||
if(minPrecision != 1){ | ||
if(method %in% c("direct", "difference", "quotient", "regression")){ | ||
approvePrecision <- (result[["precision"]] / populationBookValue) < minPrecision | ||
} else { | ||
approvePrecision <- result[["precision"]] < minPrecision | ||
} | ||
} | ||
approveMateriality <- TRUE | ||
if(materiality != 1){ | ||
if(method %in% c("direct", "difference", "quotient", "regression")){ | ||
approveMateriality <- populationBookValue <= result[["upperBound"]] && populationBookValue >= result[["lowerBound"]] | ||
approveMateriality <- (result[["upperBound"]] / populationBookValue) < materiality | ||
} else { | ||
approveMateriality <- result[["confBound"]] < materiality | ||
} | ||
|
@@ -466,6 +472,16 @@ evaluation <- function(confidence = 0.95, method = "binomial", N = NULL, | |
# Add class 'jfaPosterior' to the posterior distribution object. | ||
class(result[["posterior"]]) <- "jfaPosterior" | ||
} | ||
if(!is.null(sample)){ | ||
indexa <- which(colnames(sample) == auditValues) | ||
indexb <- which(colnames(sample) == bookValues) | ||
frame <- as.data.frame(sample[, c(indexb, indexa)]) | ||
frame <- cbind(as.numeric(rownames(frame)), frame) | ||
frame[["difference"]] <- frame[, 2] - frame[, 3] | ||
frame[["taint"]] <- frame[, 4] / frame[, 2] | ||
colnames(frame) <- c("Row", bookValues, auditValues, "Difference", "Taint") | ||
result[["data"]] <- frame | ||
} | ||
# Add class 'jfaEvaluation' to the result. | ||
class(result) <- "jfaEvaluation" | ||
return(result) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#' Generate an Audit Report | ||
#' | ||
#' @description This function takes an object of class \code{jfaEvaluation}, creates a report containing the results, and saves the report to a file in your working directory. | ||
#' | ||
#' For more details on how to use this function see the package vignette: | ||
#' \code{vignette("jfa", package = "jfa")} | ||
#' | ||
#' @usage report(object = NULL, file = NULL, format = "html_document") | ||
#' | ||
#' @param object an object of class 'jfaEvaluation' as returned by the \code{evaluation()} function. | ||
#' @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. | ||
#' @param format can be either one of \code{"html_document"} or \code{"pdf_document"} (required MikTex). | ||
#' | ||
#' @return A html or pdf report containing the results of the evaluation. | ||
#' | ||
#' @author Koen Derks, \email{[email protected]} | ||
#' | ||
#' @seealso \code{\link{evaluation}} | ||
#' | ||
#' @examples | ||
#' library(jfa) | ||
#' 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 monetary unit sampling, draw a random sample from the population. | ||
#' s1 <- selection(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 | ||
#' | ||
#' e2 <- evaluation(sample = s1_sample, bookValues = "bookValue", auditValues = "trueValue", | ||
#' method = "stringer", materiality = 0.05, counts = s1_sample$counts) | ||
#' | ||
#' # Generate report | ||
#' # report(e2, file = "myFile.html") | ||
#' | ||
#' @keywords evaluation report audit | ||
#' | ||
#' @export | ||
|
||
report <- function(object = NULL, file = NULL, format = "html_document"){ | ||
|
||
if(!class(object) == "jfaEvaluation") | ||
stop("Object must be of class 'jfaEvaluation'.") | ||
|
||
#Determine the template | ||
theFile <- system.file("rmd/report.Rmd", package = "jfa") | ||
|
||
#Process the Arguments | ||
args <- list() | ||
args$input <- theFile | ||
args$output_dir <- getwd() | ||
args$output_format <- format | ||
args$output_file <- file | ||
|
||
#Run the render | ||
outputFileName <- do.call(.getfun('rmarkdown::render'), args = args) | ||
invisible(outputFileName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.