Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

find_formula

Find model formula


Description

Returns the formula(s) for the different parts of a model (like fixed or random effects, zero-inflated component, ...). formula_ok() checks if a model formula has valid syntax regarding writing TRUE instead of T inside poly() and that no data names are used (i.e. no data$variable, but rather variable).

Usage

find_formula(x, verbose = TRUE, ...)

formula_ok(x, verbose = TRUE, ...)

Arguments

x

A fitted model.

verbose

Toggle warnings.

...

Currently not used.

Value

A list of formulas that describe the model. For simple models, only one list-element, conditional, is returned. For more complex models, the returned list may have following elements:

  • conditional, the "fixed effects" part from the model. One exception are DirichletRegModel models from DirichletReg, which has two or three components, depending on model.

  • random, the "random effects" part from the model (or the id for gee-models and similar)

  • zero_inflated, the "fixed effects" part from the zero-inflation component of the model

  • zero_inflated_random, the "random effects" part from the zero-inflation component of the model

  • dispersion, the dispersion formula

  • instruments, for fixed-effects regressions like ivreg::ivreg(), lfe::felm() or plm::plm(), the instrumental variables

  • cluster, for fixed-effects regressions like lfe::felm(), the cluster specification

  • correlation, for models with correlation-component like nlme::gls(), the formula that describes the correlation structure

  • slopes, for fixed-effects individual-slope models like feisr::feis(), the formula for the slope parameters

  • precision, for DirichletRegModel models from DirichletReg, when parametrization (i.e. model) is "alternative".

Note

For models of class lme or gls the correlation-component is only returned, when it is explicitly defined as named argument (form), e.g. corAR1(form = ~1 | Mare)

Examples

data(mtcars)
m <- lm(mpg ~ wt + cyl + vs, data = mtcars)
find_formula(m)

if (require("lme4")) {
  m <- lmer(Sepal.Length ~ Sepal.Width + (1 | Species), data = iris)
  f <- find_formula(m)
  f
  format(f)
}

insight

Easy Access to Model Information for Various Model Objects

v0.14.0
GPL-3
Authors
Daniel Lüdecke [aut, cre] (<https://orcid.org/0000-0002-8895-3206>, @strengejacke), Dominique Makowski [aut, ctb] (<https://orcid.org/0000-0001-5375-9967>, @Dom_Makowski), Indrajeet Patil [aut, ctb] (<https://orcid.org/0000-0003-1995-6531>, @patilindrajeets), Philip Waggoner [aut, ctb] (<https://orcid.org/0000-0002-7825-7573>), Mattan S. Ben-Shachar [aut, ctb] (<https://orcid.org/0000-0002-4287-4801>), Brenton M. Wiernik [aut] (<https://orcid.org/0000-0001-9560-6336>, @bmwiernik)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.