Provides an equatiomatic::extract_eq() method for "nestedLogit" objects
to render the models as LaTeX equations in documents.
It extracts the LaTeX equation for each of the binary logit sub-models
comprising a nested logit model, substituting the dichotomy name for the
internal ..y placeholder used by nestedLogit().
Arguments
- model
a
"nestedLogit"object.- submodel
character; name of a single dichotomy (e.g.
"work"). When supplied, a single"equation"object is returned and renders directly in a knitr chunk. When omitted, equations for all dichotomies are returned as a named list of class"nestedLogit_equations".- ...
additional arguments passed to
equatiomatic::extract_eq(). For example, useuse_coefs = TRUEto display fitted coefficients rather than symbols;wrap = TRUEto split the RHS across multiple lines;greek_colors,var_colors, etc. to color the symbols.
Value
When submodel is NULL, an object of class
c("nestedLogit_equations", "list") containing one "equation" per
dichotomy, named by the dichotomy. Individual equations can be extracted
with $name or by passing submodel. When submodel is a dichotomy
name, the single corresponding "equation" object is returned and renders
directly in a knitr chunk.
Details
Internally, nestedLogit() fits each sub-model on a temporary response
column named ..y, so equatiomatic::extract_eq() would render the
response as ..y rather than the dichotomy name. This method replaces
..y with the name of each dichotomy.
Because _ is the subscript operator in LaTeX, any underscores in
dichotomy names are replaced by . in the displayed equation
(e.g., a dichotomy named fish_inv appears as fish.inv).
This does not affect the names of the returned list, which retain the
original R names.
Examples
data("Womenlf", package = "carData")
wlf.nested <- nestedLogit(partic ~ hincome + children,
dichotomies = logits(work = dichotomy("not.work",
working = c("parttime", "fulltime")),
full = dichotomy("parttime", "fulltime")),
data = Womenlf)
if (requireNamespace("equatiomatic", quietly = TRUE)) {
equatiomatic::extract_eq(wlf.nested)
}
#>
#> Dichotomy: work
#> $$
#> \log\left[ \frac { P( \operatorname{work} ) }{ 1 - P( \operatorname{work} ) } \right] = \alpha + \beta_{1}(\operatorname{hincome}) + \beta_{2}(\operatorname{children}_{\operatorname{present}})
#> $$
#>
#> Dichotomy: full
#> $$
#> \log\left[ \frac { P( \operatorname{full} ) }{ 1 - P( \operatorname{full} ) } \right] = \alpha + \beta_{1}(\operatorname{hincome}) + \beta_{2}(\operatorname{children}_{\operatorname{present}})
#> $$
