3.10 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. At the time of writing, this package is still very new on GitHub and its API may change significantly before its possible future CRAN release, so we only show a few brief examples below:

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

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

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

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

To display the actual math equations, you need the chunk option results = "asis", 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.