4.13 Convert models to equations
The equatiomatic package (Anderson, Heiss, and Sumners 2024) (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:
<- lm(mpg ~ cyl + disp, mtcars)
fit # show the theoretical model
::extract_eq(fit) equatiomatic
\[ \operatorname{mpg} = \alpha + \beta_{1}(\operatorname{cyl}) + \beta_{2}(\operatorname{disp}) + \epsilon \]
# display the actual coefficients
::extract_eq(fit, use_coefs = TRUE) equatiomatic
\[ \operatorname{\widehat{mpg}} = 34.66 - 1.59(\operatorname{cyl}) - 0.02(\operatorname{disp}) \]
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.