Skip to content

Commit

Permalink
Add more returns and examples for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ohjakobsen committed Oct 14, 2024
1 parent cf2ed03 commit 6f544e1
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 36 deletions.
20 changes: 11 additions & 9 deletions R/bootstrap-dea.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions R/compute_dea.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
26 changes: 22 additions & 4 deletions R/dea-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 3 additions & 7 deletions R/shiny-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
20 changes: 11 additions & 9 deletions man/bootstrap_dea.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions man/compute_dea.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions man/compute_scale_efficiency.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions man/create_matrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions man/run_pioneer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/unset_env_vars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f544e1

Please sign in to comment.