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
).
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 (in the context of fixed-effects or instrumental variable regression, also called regressors) . One exception areDirichletRegModel
models from DirichletReg, which has two or three components, depending onmodel
.random
, the "random effects" part from the model (or theid
for gee-models and similar)zero_inflated
, the "fixed effects" part from the zero-inflation component of the modelzero_inflated_random
, the "random effects" part from the zero-inflation component of the modeldispersion
, the dispersion formulainstruments
, for fixed-effects or instrumental variable regressions likeivreg::ivreg()
,lfe::felm()
orplm::plm()
, the instrumental variablescluster
, for fixed-effects regressions likelfe::felm()
, the cluster specificationcorrelation
, for models with correlation-component likenlme::gls()
, the formula that describes the correlation structureslopes
, for fixed-effects individual-slope models likefeisr::feis()
, the formula for the slope parametersprecision
, forDirichletRegModel
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)
#> $conditional
#> mpg ~ wt + cyl + vs
#> <environment: 0x561cc2d1f210>
#>
#> attr(,"class")
#> [1] "insight_formula" "list"
if (require("lme4")) {
m <- lmer(Sepal.Length ~ Sepal.Width + (1 | Species), data = iris)
f <- find_formula(m)
f
format(f)
}
#> [1] "Sepal.Length ~ Sepal.Width + (~1 | Species)"