## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 6, fig.height = 4)
library(DEA)

## -----------------------------------------------------------------------------
data(charnes1981)
x <- charnes1981[, paste0("x", 1:5)]
y <- charnes1981[, paste0("y", 1:3)]

dea(x, y, rts = "crs", orientation = "in")

## -----------------------------------------------------------------------------
sim <- dea_sim(n = 150, p = 2, q = 1, returns = 0.9, seed = 1)
sim

## -----------------------------------------------------------------------------
fit <- dea(sim$x, sim$y, rts = "vrs", orientation = "in")
fit

## -----------------------------------------------------------------------------
head(peers(fit), 4)
head(slacks(fit), 4)

## -----------------------------------------------------------------------------
rho <- dea_sbm(sim$x, sim$y, rts = "vrs")
c(radial = mean(fit$eff), sbm = mean(rho$eff))
all(rho$eff <= fit$eff + 1e-8)

## -----------------------------------------------------------------------------
ddf <- dea_ddf(sim$x, sim$y, direction = "both", rts = "vrs")
summary(ddf$beta)

## -----------------------------------------------------------------------------
b_in <- dea_ddf(sim$x, sim$y, direction = "in", rts = "vrs")
max(abs(b_in$beta - (1 - fit$eff)))

## -----------------------------------------------------------------------------
dea_rts(x, y, orientation = "out")

## -----------------------------------------------------------------------------
c(mean_estimate = mean(fit$eff), mean_truth = mean(sim$theta))

## -----------------------------------------------------------------------------
set.seed(1)
b <- dea_boot(fit, B = 100, seed = 1, progress = FALSE)
b

## -----------------------------------------------------------------------------
c(`1 in, 1 out` = dea_rate(1, 1, "vrs"),
  `2 in, 2 out` = dea_rate(2, 2, "vrs"),
  `4 in, 4 out` = dea_rate(4, 4, "vrs"))

## -----------------------------------------------------------------------------
dea_rate(5, 3, "crs")

## -----------------------------------------------------------------------------
ben <- dea_cross(x, y, secondary = "benevolent")
summary(ben)

## -----------------------------------------------------------------------------
agg <- dea_cross(x, y, secondary = "aggressive")
range(ben$eff - agg$eff)

## -----------------------------------------------------------------------------
w  <- c(1.4, 0.9, 2.1, 1.2, 1.0)   # one price list, faced by every site
ce <- dea_cost(x, y, w, rts = "crs")
ce

## -----------------------------------------------------------------------------
sum(ce$technical > 1 - 1e-9)   # technically efficient
sum(ce$eff == 1)               # and allocatively efficient too

## -----------------------------------------------------------------------------
fit <- dea(x, y, rts = "crs", orientation = "in", multipliers = TRUE)
round(head(multipliers(fit), 4), 4)

