## ----setup, include = FALSE---------------------------------------------------


has_bench   <- requireNamespace("Benchmarking",  quietly = TRUE)
has_smacof  <- requireNamespace("smacof",        quietly = TRUE)
has_igraph  <- requireNamespace("igraph",        quietly = TRUE) &&
               requireNamespace("graphlayouts",  quietly = TRUE)
has_kohonen <- requireNamespace("kohonen",       quietly = TRUE)

knitr::opts_chunk$set(
  collapse   = TRUE,
  comment    = "#>",
  fig.width  = 7,
  fig.height = 4.8,
  fig.align  = "center",
  dpi        = 96,
  out.width  = "85%"
)

## ----load---------------------------------------------------------------------
library(deaviz)

## ----dea-data-----------------------------------------------------------------
d <- dea_data(
  chinese_cities,
  inputs  = c("industrial_labour_force", "working_funds", "investments"),
  outputs = c("gross_industrial_output", "profit_and_tax", "retail_sales"),
  id      = "DMU"
)
d

## ----dea-data-by-position, eval = FALSE---------------------------------------
# d <- dea_data(
#   chinese_cities,
#   inputs  = 2:4,
#   outputs = 5:7,
#   id      = "DMU"
# )
# 

## ----efficiency, eval = has_bench---------------------------------------------
eff <- compute_efficiency(x = d, rts = "vrs", orientation = "in")
head(round(eff$eff, 3))

## ----dist, eval = has_bench---------------------------------------------------
plot_efficiency_distributions(d, rts = "vrs", title = "Chinese Cities Efficiency Scores", subtitle = "Variable Return To Scale")

## ----io-dist, eval = has_bench, fig.height = 5.2------------------------------
plot_io_distributions(d, type = "box", x_angle = 30)

## ----efficients, eval = has_bench, fig.height = 3.6---------------------------
plot_io_efficients(d, rts = "vrs", transparency = 1)

## ----scatter, eval = has_bench, fig.height = 6--------------------------------

plot_io_scatter(d, vars = c("industrial_labour_force", "gross_industrial_output", "retail_sales") , color = "vrs")

## ----scatter-efficiency, eval = has_bench, fig.height = 6---------------------

plot_io_scatter(d, vars = c("industrial_labour_force", "gross_industrial_output", "retail_sales"), efficiency = "vrs" , color = "vrs")

## ----costa, eval = has_bench--------------------------------------------------
plot_io_costa_frontier(d)

## ----pca, eval = has_bench----------------------------------------------------
plot_io_pca_biplot(d, rts = "vrs")

## ----mds, eval = has_bench && has_smacof--------------------------------------
plot_io_mds(d)

## ----mds-interactive, eval = FALSE--------------------------------------------
# plot_io_mds(d, interactive = TRUE)

## ----lambda, eval = has_bench-------------------------------------------------
plot_io_lambda_network(d, rts = "vrs")

## ----peer, eval = has_bench && has_igraph-------------------------------------
plot_io_peer_network(d, rts = "vrs")

## ----peer-label, eval = has_bench && has_igraph-------------------------------
plot_io_peer_network(d,layout = "fr",labels = "Xian", rts = "vrs")

## ----cem, eval = has_bench, fig.height = 6------------------------------------
cem <- compute_cross_efficiency(d)

plot_cem_heatmap(cem, x_angle = 90)

## ----cem-unfold, eval = has_bench && has_smacof-------------------------------
plot_cem_unfolding(cem)

## ----cem-weights, eval = has_bench, fig.height = 6----------------------------
plot_cem_weights_heatmap(d, x_angle = 30)

## ----cem-weights-focus, eval = has_bench, fig.height = 6----------------------
plot_cem_weights_heatmap(d, x_angle = 30, labels = "Xian")

## ----radar, eval = has_bench, fig.width = 6.5, fig.height = 5.5---------------
plot_io_radar(d, efficiency = "vrs")

## ----parcoo, eval = has_bench, fig.height = 4.2-------------------------------
plot_io_parcoo(d, efficiency = "vrs", x_angle = 30)

## ----focus, eval = has_bench--------------------------------------------------
plot_io_pca_biplot(d, rts = "vrs", labels = "Beijing")

## ----focus-level, eval = has_bench--------------------------------------------
plot_io_parcoo(d, efficiency = "vrs", labels = "Beijing", fade = 0.4)

## ----cem-unfold-id, eval = has_bench && has_smacof----------------------------
plot_cem_unfolding(cem, labels = "id")

## ----som, eval = has_bench && has_kohonen, fig.height = 5---------------------
som <- compute_som(d)
plot_io_som(som)

## ----panel-id, eval = has_bench, fig.width = 7.5, fig.height = 5.5------------
plot_panel_io_biplot(
  taiwanese_banks, id = "DMU", period = "Year",
  inputs = 3:5, outputs = 6:8, labels = "id"
)

## ----panel-Cathay, eval = has_bench, fig.width = 7.5, fig.height = 5.5--------
plot_panel_io_biplot(
  taiwanese_banks, id = "DMU", period = "Year",
  inputs = 3:5, outputs = 6:8, labels = "Cathay", fade = 0.25
)

## ----interactive, eval = FALSE------------------------------------------------
# plot_io_pca_biplot(d, rts = "vrs", labels = "Beijing", interactive = TRUE)

