## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  message  = FALSE,
  warning  = FALSE,
  comment  = "#>"
)

.opts <- options(digits = 4)

# packages to be cited in packages.bib
.to.cite <- c("nestedLogit", "equatiomatic", "carData")

## ----setup--------------------------------------------------------------------
library(nestedLogit)
library(equatiomatic)

## ----model--------------------------------------------------------------------
data(Womenlf, package = "carData")

comparisons <- logits(
  work = dichotomy("not.work", working = c("parttime", "fulltime")),
  full = dichotomy("parttime", "fulltime")
)

wlf.nested <- nestedLogit(partic ~ hincome + children,
                           dichotomies = comparisons,
                           data = Womenlf)

## ----eqn-work-----------------------------------------------------------------
extract_eq(wlf.nested, submodel = "work")

## ----eqn-full-----------------------------------------------------------------
extract_eq(wlf.nested, submodel = "full")

## ----eqn-full-logit-----------------------------------------------------------
extract_eq(wlf.nested, submodel = "full", logit_notation = TRUE)

## ----eqn-coef-work------------------------------------------------------------
extract_eq(wlf.nested, use_coefs = TRUE, submodel = "work")

## ----eqn-coef-full------------------------------------------------------------
extract_eq(wlf.nested, use_coefs = TRUE, submodel = "full")

## ----eqn-colors---------------------------------------------------------------
extract_eq(wlf.nested,
           greek_colors = "blue",
           submodel = "work")

## ----eqn-colors-vec-----------------------------------------------------------
extract_eq(wlf.nested,
           greek_colors = c("black", "blue", "blue"),
           var_colors   = c(hincome = "red", children="darkgreen"),
           submodel     = "work")

## ----submodel-----------------------------------------------------------------
mod.work <- models(wlf.nested, "work")
extract_eq(mod.work)

## ----raw-latex----------------------------------------------------------------
cat(as.character(extract_eq(wlf.nested, submodel = "work")), "\n\n")

cat(as.character(extract_eq(wlf.nested, submodel = "full")), "\n")

## ----write-bib, echo=FALSE----------------------------------------------------
pkgs <- unique(c(.to.cite, .packages()))
knitr::write_bib(pkgs, file = here::here("vignettes", "packages.bib"))

## ----gators-model-------------------------------------------------------------
data(gators)
gators.dichots <- logits(
  other    = dichotomy("Other", c("Fish", "Invertebrates")),
  fish_inv = dichotomy("Fish", "Invertebrates")
)
gators.dichots

gators.nested <- nestedLogit(food ~ length,
                             dichotomies = gators.dichots,
                             data = gators)

## ----gators-eqns--------------------------------------------------------------
extract_eq(gators.nested, submodel = "other")
extract_eq(gators.nested, submodel = "fish_inv")

## ----gators-eqns-coef---------------------------------------------------------
extract_eq(gators.nested, use_coefs = TRUE, submodel = "other")
extract_eq(gators.nested, use_coefs = TRUE, submodel = "fish_inv")

## ----include=FALSE------------------------------------------------------------
options(.opts)

