4.13 Convert models to equations

The equatiomatic package (https://github.com/datalorax/equatiomatic) developed by Daniel Anderson et al. provides a convenient and automatic way to show the equations corresponding to models fitted in R. We show a few brief examples below:

fit <- lm(mpg ~ cyl + disp, mtcars)
# show the theoretical model
equatiomatic::extract_eq(fit)

\[ \operatorname{mpg} = \alpha + \beta_{1}(\operatorname{cyl}) + \beta_{2}(\operatorname{disp}) + \epsilon \]

# display the actual coefficients
equatiomatic::extract_eq(fit, use_coefs = TRUE)

\[ \operatorname{mpg} = 34.66 - 1.59(\operatorname{cyl}) - 0.02(\operatorname{disp}) + \epsilon \]

To display the actual math equations, you need the chunk option results = "asis" (see Section 11.11 for the meaning of this option), otherwise the equations will be displayed as normal text output.

Please read the documentation and follow the development of this package on GitHub if you are interested in knowing more about it.