## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  collapse  = TRUE,
  comment   = "#>",
  eval      = TRUE
)

## ----data---------------------------------------------------------------------
library(smfa)
data("ricephil", package = "sfaR")

ricephil$group <- cut(
  ricephil$AREA,
  breaks        = quantile(ricephil$AREA, probs = c(0, 1/3, 2/3, 1), na.rm = TRUE),
  labels        = c("small", "medium", "large"),
  include.lowest = TRUE
)

table(ricephil$group)
#>  small medium  large
#>    125    104    115

## ----lp-----------------------------------------------------------------------
meta_lp <- smfa(
  formula    = log(PROD) ~ log(AREA) + log(LABOR) + log(NPK),
  data       = ricephil,
  group      = "group",
  S          = 1,
  udist      = "hnormal",
  groupType  = "sfacross",
  metaMethod = "lp"
)
summary(meta_lp)

## ----qp-----------------------------------------------------------------------
meta_qp <- smfa(
  formula    = log(PROD) ~ log(AREA) + log(LABOR) + log(NPK),
  data       = ricephil,
  group      = "group",
  S          = 1,
  udist      = "hnormal",
  groupType  = "sfacross",
  metaMethod = "qp"
)
summary(meta_qp)

## ----huang--------------------------------------------------------------------
meta_huang <- smfa(
  formula     = log(PROD) ~ log(AREA) + log(LABOR) + log(NPK),
  data        = ricephil,
  group       = "group",
  S           = 1,
  udist       = "hnormal",
  groupType   = "sfacross",
  metaMethod  = "sfa",
  sfaApproach = "huang"
)
summary(meta_huang)

## ----odonnell-----------------------------------------------------------------
meta_ordonnell <- smfa(
  formula     = log(PROD) ~ log(AREA) + log(LABOR) + log(NPK),
  data        = ricephil,
  group       = "group",
  S           = 1,
  udist       = "hnormal",
  groupType   = "sfacross",
  metaMethod  = "sfa",
  sfaApproach = "ordonnell"
)
summary(meta_ordonnell)

## ----eff----------------------------------------------------------------------
eff <- efficiencies(meta_lp)
head(eff)

# Subset for a specific group
eff_small <- eff[eff$group == "small", ]
summary(eff_small[, c("TE_group_BC", "TE_meta_BC", "MTR_BC")])

## ----other--------------------------------------------------------------------
coef(meta_qp)          # metafrontier coefficients
vcov(meta_qp)          # variance-covariance matrix
logLik(meta_lp)        # log-likelihood
ic(meta_lp)            # AIC, BIC, HQIC
nobs(meta_lp)          # number of observations
fitted(meta_lp)        # fitted values
residuals(meta_lp)     # residuals

