Skip to contents

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).


find_formula(x, ...)

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

# Default S3 method
find_formula(x, verbose = TRUE, ...)

# S3 method for class 'nestedLogit'
find_formula(x, dichotomies = FALSE, verbose = TRUE, ...)



A fitted model.


Currently not used.


Toggle warnings.


Logical, if model is a nestedLogit objects, returns the formulas for the dichotomies.


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 (in the context of fixed-effects or instrumental variable regression, also called regressors) . 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 or instrumental variable 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

  • scale, for distributional models such as mgcv::gaulss() family fitted with mgcv::gam(), the formula that describes the scale parameter

  • 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".


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)


m <- lm(mpg ~ wt + cyl + vs, data = mtcars)
#> $conditional
#> mpg ~ wt + cyl + vs
#> <environment: 0x56536d83a548>
#> attr(,"class")
#> [1] "insight_formula" "list"           

m <- lme4::lmer(Sepal.Length ~ Sepal.Width + (1 | Species), data = iris)
f <- find_formula(m)
#> $conditional
#> Sepal.Length ~ Sepal.Width
#> <environment: 0x56536d83a548>
#> $random
#> ~1 | Species
#> <environment: 0x56536e0088c8>
#> attr(,"class")
#> [1] "insight_formula" "list"           
#> [1] "Sepal.Length ~ Sepal.Width + (~1 | Species)"