diff --git a/R/bootstrap-dea.R b/R/bootstrap-dea.R index 0d85b46..31610ba 100644 --- a/R/bootstrap-dea.R +++ b/R/bootstrap-dea.R @@ -6,11 +6,11 @@ NULL #' Run bootstrap on a DEA model to estimate bias corrected efficiency scores and confidence #' intervals #' -#' @param dea An object of type pioneer_dea from `compute_dea()` -#' @param alpha One minus the confidence level required (defaults to 0.05) +#' @param dea An object of class 'pioneer_dea' from `compute_dea()` +#' @param alpha One minus the confidence level required. Default is 0.05. #' @param bw_rule A string with the type of bandwidth rule to be used, or a number with the #' bandwidth parameter. See details. -#' @param iterations The number of bootstrap iterations to be performed +#' @param iterations Integer. The number of bootstrap iterations to perform. Default is 2000. #' #' @details #' In order to bootstrap a DEA model, you must first create a DEA model object using the @@ -25,16 +25,18 @@ NULL #' applications of the bootstrap, the default of unbias cross validation is sensible. #' #' @examples -#' \dontrun{ #' # Get data #' fare89 <- deaR::Electric_plants #' # Estimate efficiency -#' mod <- compute_dea(fare89, 'Plant', c('Labor', 'Fuel', 'Capital'), 'Output', 'vrs', 'in') -#' # Run bootstrap -#' boot <- bootstrap_dea(mod, iterations = 2000) -#' } +#' mod <- compute_dea(fare89, +#' input = c("Labor", "Fuel", "Capital"), +#' output = "Output", +#' id = "Plant", +#' ) +#' # Run bootstrap. Reducing the number of iterations to save processing time +#' boot <- bootstrap_dea(mod, iterations = 100) #' -#' @return A list object of class `pioneer_bootstrap` +#' @return An object of class 'pioneer_bootstrap' containing bootstrap results. #' @seealso [compute_dea()] #' #' @export diff --git a/R/compute_dea.R b/R/compute_dea.R index 8754615..10072f8 100644 --- a/R/compute_dea.R +++ b/R/compute_dea.R @@ -19,6 +19,20 @@ #' @param slack If `TRUE` slack values are calculated. #' @param peers If `TRUE` peers are added to the response. #' +#' @examples +#' # Get data +#' fare89 <- deaR::Electric_plants +#' # Estimate efficiency +#' mod <- compute_dea(fare89, +#' input = c("Labor", "Fuel", "Capital"), +#' output = "Output", +#' id = "Plant", +#' rts = "vrs", +#' orientation = "in" +#' ) +#' # Print the results +#' print(mod) +#' #' @return A list of class `pioneer_dea` #' @export compute_dea <- function( diff --git a/R/dea-utils.R b/R/dea-utils.R index 3c57381..deb590d 100644 --- a/R/dea-utils.R +++ b/R/dea-utils.R @@ -3,10 +3,17 @@ #' Create a matrix for input or output variables that can be used in DEA models #' from a supplied data.frame #' -#' @param df A data.frame -#' @param columns A vector of column names that should be included in the matrix -#' @param id The name of the column with the DMU IDs -#' @param normalize If `TRUE`, all columns will be normalized with a mean of 1 +#' @param df A data.frame containing the data. +#' @param columns A character vector of column names to include in the matrix. +#' @param id A character string specifying the column with DMU IDs. +#' @param normalize A logical indicating whether to normalize the columns by their +#' mean. Defaults to `FALSE`. +#' +#' @examples +#' df <- data.frame(id = 1:3, a = c(10, 20, 30), b = c(5, 15, 25)) +#' create_matrix(df, columns = c("a", "b"), id = "id", normalize = TRUE) +#' +#' @return A matrix of inputs or outputs #' #' @export create_matrix <- function(df, columns, id, normalize = FALSE) { @@ -37,6 +44,17 @@ create_matrix <- function(df, columns, id, normalize = FALSE) { #' @param digits An integer with the number of digits to round to. If `NULL` the #' values are kept unrounded. #' +#' @examples +#' # Create matrices with random values +#' inputs <- matrix(runif(10, 1, 10), ncol = 2) +#' outputs <- matrix(runif(10, 1, 10), ncol = 2) +#' # Compute scale efficiency +#' compute_scale_efficiency(inputs, outputs, orientation = 'out', digits = 2) +#' +#' @return A data frame containing the efficiency scores for CRS, VRS, the +#' Scale Efficiency, the VRS to NIRS ratio, and a recommendation on whether to +#' increase or decrease the size of the DMU. +#' #' @export compute_scale_efficiency <- function( x, diff --git a/R/shiny-functions.R b/R/shiny-functions.R index 532d9ea..8366535 100644 --- a/R/shiny-functions.R +++ b/R/shiny-functions.R @@ -58,17 +58,13 @@ run_pioneer <- function(x = NULL, port = NULL, ...) { } -#' @rdname run_pioneer -#' @export -runPioneeR <- function(x = NULL, port = NULL, ...) { - deprecation_warning(alternative = "run_pioneeR", next_release = TRUE) - run_pioneer(x = x, port = port, ...) -} - #' Unset environment variables #' #' Unsets the environment variables set by pioneeR #' +#' @examples +#' unset_env_vars() +#' #' @export unset_env_vars <- \() Sys.unsetenv('PIONEER_DATA') diff --git a/man/bootstrap_dea.Rd b/man/bootstrap_dea.Rd index ecbeb14..92b2314 100644 --- a/man/bootstrap_dea.Rd +++ b/man/bootstrap_dea.Rd @@ -7,17 +7,17 @@ bootstrap_dea(dea, alpha = 0.05, bw_rule = "ucv", iterations = 2000) } \arguments{ -\item{dea}{An object of type pioneer_dea from \code{compute_dea()}} +\item{dea}{An object of class 'pioneer_dea' from \code{compute_dea()}} -\item{alpha}{One minus the confidence level required (defaults to 0.05)} +\item{alpha}{One minus the confidence level required. Default is 0.05.} \item{bw_rule}{A string with the type of bandwidth rule to be used, or a number with the bandwidth parameter. See details.} -\item{iterations}{The number of bootstrap iterations to be performed} +\item{iterations}{Integer. The number of bootstrap iterations to perform. Default is 2000.} } \value{ -A list object of class \code{pioneer_bootstrap} +An object of class 'pioneer_bootstrap' containing bootstrap results. } \description{ Run bootstrap on a DEA model to estimate bias corrected efficiency scores and confidence @@ -36,14 +36,16 @@ to replicate results where \code{h} is given, such as Simar & Wilson (1998). For applications of the bootstrap, the default of unbias cross validation is sensible. } \examples{ -\dontrun{ # Get data fare89 <- deaR::Electric_plants # Estimate efficiency -mod <- compute_dea(fare89, 'Plant', c('Labor', 'Fuel', 'Capital'), 'Output', 'vrs', 'in') -# Run bootstrap -boot <- bootstrap_dea(mod, iterations = 2000) -} +mod <- compute_dea(fare89, + input = c("Labor", "Fuel", "Capital"), + output = "Output", + id = "Plant", +) +# Run bootstrap. Reducing the number of iterations to save processing time +boot <- bootstrap_dea(mod, iterations = 100) } \seealso{ diff --git a/man/compute_dea.Rd b/man/compute_dea.Rd index f5bd7b7..55808bb 100644 --- a/man/compute_dea.Rd +++ b/man/compute_dea.Rd @@ -48,3 +48,18 @@ A list of class \code{pioneer_dea} Solve an input or output oriented DEA model under constant (\code{crs}), variable (\code{vrs}), non-increasing (\code{drs}), or non-decreasing (\code{irs}) returns to scale. } +\examples{ +# Get data +fare89 <- deaR::Electric_plants +# Estimate efficiency +mod <- compute_dea(fare89, + input = c("Labor", "Fuel", "Capital"), + output = "Output", + id = "Plant", + rts = "vrs", + orientation = "in" +) +# Print the results +print(mod) + +} diff --git a/man/compute_scale_efficiency.Rd b/man/compute_scale_efficiency.Rd index 70d1cfc..ccd55de 100644 --- a/man/compute_scale_efficiency.Rd +++ b/man/compute_scale_efficiency.Rd @@ -16,7 +16,20 @@ compute_scale_efficiency(x, y, orientation = c("in", "out"), digits = NULL) \item{digits}{An integer with the number of digits to round to. If \code{NULL} the values are kept unrounded.} } +\value{ +A data frame containing the efficiency scores for CRS, VRS, the +Scale Efficiency, the VRS to NIRS ratio, and a recommendation on whether to +increase or decrease the size of the DMU. +} \description{ Calculate scale efficiency from a set of inputs and outputs and return a data.frame } +\examples{ +# Create matrices with random values +inputs <- matrix(runif(10, 1, 10), ncol = 2) +outputs <- matrix(runif(10, 1, 10), ncol = 2) +# Compute scale efficiency +compute_scale_efficiency(inputs, outputs, orientation = 'out', digits = 2) + +} diff --git a/man/create_matrix.Rd b/man/create_matrix.Rd index 3564696..3c8e23f 100644 --- a/man/create_matrix.Rd +++ b/man/create_matrix.Rd @@ -7,15 +7,24 @@ create_matrix(df, columns, id, normalize = FALSE) } \arguments{ -\item{df}{A data.frame} +\item{df}{A data.frame containing the data.} -\item{columns}{A vector of column names that should be included in the matrix} +\item{columns}{A character vector of column names to include in the matrix.} -\item{id}{The name of the column with the DMU IDs} +\item{id}{A character string specifying the column with DMU IDs.} -\item{normalize}{If \code{TRUE}, all columns will be normalized with a mean of 1} +\item{normalize}{A logical indicating whether to normalize the columns by their +mean. Defaults to \code{FALSE}.} +} +\value{ +A matrix of inputs or outputs } \description{ Create a matrix for input or output variables that can be used in DEA models from a supplied data.frame } +\examples{ +df <- data.frame(id = 1:3, a = c(10, 20, 30), b = c(5, 15, 25)) +create_matrix(df, columns = c("a", "b"), id = "id", normalize = TRUE) + +} diff --git a/man/run_pioneer.Rd b/man/run_pioneer.Rd index 6e56a9f..8684a1c 100644 --- a/man/run_pioneer.Rd +++ b/man/run_pioneer.Rd @@ -2,12 +2,9 @@ % Please edit documentation in R/shiny-functions.R \name{run_pioneer} \alias{run_pioneer} -\alias{runPioneeR} \title{Run pioneeR} \usage{ run_pioneer(x = NULL, port = NULL, ...) - -runPioneeR(x = NULL, port = NULL, ...) } \arguments{ \item{x}{A data frame that should be loaded with the app. See details.} diff --git a/man/unset_env_vars.Rd b/man/unset_env_vars.Rd index dda6162..045f853 100644 --- a/man/unset_env_vars.Rd +++ b/man/unset_env_vars.Rd @@ -9,3 +9,7 @@ unset_env_vars() \description{ Unsets the environment variables set by pioneeR } +\examples{ +unset_env_vars() + +}