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

## ----install, eval = FALSE----------------------------------------------------
# # Install smfa from CRAN
# install.packages("smfa")
# 
# # Or install the development version from GitHub
# # if (!require("devtools")) install.packages("devtools")
# # devtools::install_github("SulmanOlieko/smfa")

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

# Create technology groups based on farm area terciles
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)

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

## ----quickstart-summary-------------------------------------------------------
summary(meta_lp)

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

