Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
2 of 19 committers (10.5%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (19.6%) to scientific vocabulary
Keywords from Contributors
data-wrangling
tidy-data
effect-size
phylogenetics
visualisation
shiny
ecology
Last synced: 10 months ago
·
JSON representation
Repository
Convert models to LaTeX equations
Basic Info
- Host: GitHub
- Owner: datalorax
- License: cc-by-4.0
- Language: R
- Default Branch: master
- Homepage: https://datalorax.github.io/equatiomatic/
- Size: 68 MB
Statistics
- Stars: 621
- Watchers: 11
- Forks: 44
- Open Issues: 25
- Releases: 4
Created about 7 years ago
· Last pushed 12 months ago
Metadata Files
Readme
Changelog
License
Code of conduct
README.Rmd
---
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>",
fig.path = "man/figures/README-", out.width = "100%")
```
# equatiomatic
[](https://lifecycle.r-lib.org/articles/stages.html#stable) [](https://github.com/datalorax/equatiomatic/actions) [](https://app.codecov.io/gh/datalorax/equatiomatic?branch=master) [](https://github.com/datalorax/equatiomatic/tree/master/tests) [](https://cranlogs.r-pkg.org/badges/grand-total/equatiomatic)
The goal of {equatiomatic} is to reduce the pain associated with writing LaTeX code from a fitted model. The package aims to support any model
supported by [{broom}](https://cran.r-project.org/package=broom). See the [introduction to equatiomatic](https://datalorax.github.io/equatiomatic/articles/equatiomatic.html#other-models) for currently supported models.
## Installation
Install from CRAN with:
```{r install-cran, eval=FALSE}
install.packages("equatiomatic")
```
Or get the development version from GitHub with:
```{r install-command, eval=FALSE}
remotes::install_github("datalorax/equatiomatic")
```
## Basic usage

The gif above shows the basic functionality.
To convert a model to LaTeX, feed a model object to `extract_eq()`:
```{r example-basic, warning=FALSE, message=FALSE, eval=FALSE}
library(equatiomatic)
# Fit a simple model
mod1 <- lm(mpg ~ cyl + disp, data = mtcars)
# Give the results to extract_eq
extract_eq(mod1)
```
```{r example-basic-preview, echo=FALSE}
library(equatiomatic)
mod1 <- lm(mpg ~ cyl + disp, data = mtcars)
eq1 <- extract_eq(mod1)
print(eq1)
eq1
```
The model can be built in any standard way. It can handle shortcut syntax:
```{r example-shortcut, eval=FALSE}
mod2 <- lm(mpg ~ ., data = mtcars)
extract_eq(mod2)
```
```{r example-shortcut-preview, echo=FALSE}
mod2 <- lm(mpg ~ ., data = mtcars)
eq2 <- extract_eq(mod2)
print(eq2)
eq2
```
When using categorical variables, it will include the levels of the variables as subscripts.
```{r example-categorical, eval=FALSE}
data("penguins", package = "equatiomatic")
mod3 <- lm(body_mass_g ~ bill_length_mm + species, data = penguins)
extract_eq(mod3)
```
```{r example-categorical-preview, echo=FALSE}
mod3 <- lm(body_mass_g ~ bill_length_mm + species, data = penguins)
eq3 <- extract_eq(mod3)
print(eq3)
eq3
```
It helpfully preserves the order the variables are supplied in the formula:
```{r example-preserve-order, eval=FALSE}
set.seed(8675309)
d <- data.frame(cat1 = rep(letters[1:3], 100),
cat2 = rep(LETTERS[1:3], each = 100),
cont1 = rnorm(300, 100, 1),
cont2 = rnorm(300, 50, 5),
out = rnorm(300, 10, 0.5))
mod4 <- lm(out ~ cont1 + cat2 + cont2 + cat1, data = d)
extract_eq(mod4)
```
```{r example-preserve-order-preview, echo=FALSE}
set.seed(8675309)
d <- data.frame(cat1 = rep(letters[1:3], 100),
cat2 = rep(LETTERS[1:3], each = 100),
cont1 = rnorm(300, 100, 1),
cont2 = rnorm(300, 50, 5),
out = rnorm(300, 10, 0.5))
mod4 <- lm(out ~ cont1 + cat2 + cont2 + cat1, data = d)
eq4 <- extract_eq(mod4)
print(eq4)
eq4
```
## Appearance
You can wrap the equations so that a specified number of terms appear on the right-hand side of the equation using `terms_per_line` (defaults to 4):
```{r example-wrap, eval=FALSE}
extract_eq(mod2, wrap = TRUE)
```
```{r example-wrap-preview, echo=FALSE}
eq2 <- extract_eq(mod2, wrap = TRUE)
print(eq2)
eq2
```
```{r example-wrap-longer, eval=FALSE}
extract_eq(mod2, wrap = TRUE, terms_per_line = 6)
```
```{r example-wrap-longer-preview, echo=FALSE}
eq2 <- extract_eq(mod2, wrap = TRUE, terms_per_line = 6)
print(eq2)
eq2
```
When wrapping, you can change whether the lines end with trailing math operators like `+` (the default), or if they should begin with them using `operator_location = "end"` or `operator_location = "start"`:
```{r example-wrap-longer-location, eval=FALSE}
extract_eq(mod2, wrap = TRUE, terms_per_line = 4, operator_location = "start")
```
```{r example-wrap-longer-location-preview, echo=FALSE}
eq2 <- extract_eq(mod2, wrap = TRUE, terms_per_line = 4,
operator_location = "start")
print(eq2)
eq2
```
By default, all text in the equation is wrapped in `\operatorname{}`. You can optionally have the variables themselves be italicized (i.e. not be wrapped in `\operatorname{}`) with `ital_vars = TRUE`:
```{r example-italics, eval=FALSE}
extract_eq(mod2, wrap = TRUE, ital_vars = TRUE)
```
```{r example-italics-preview, echo=FALSE}
eq2 <- extract_eq(mod2, wrap = TRUE, ital_vars = TRUE)
print(eq2)
eq2
```
## R Markdown and previewing
If you include `extract_eq()` in an R Markdown chunk, {knitr} will render the equation. If you'd like to see the LaTeX code wrap the call in `print()`.
You can also use the `preview_eq()` function to preview the equation in RStudio:
```{r example-preview, eval=FALSE}
preview_eq(mod1)
```

Both `extract_eq()` and `preview_eq()` work with base R or {magrittr} pipes, so you can do something like this:
```{r pipe-example, eval=FALSE}
#library(magrittr) # if you want to use %>% instead of |>
extract_eq(mod1) |>
preview_eq()
# Or simply: preview_eq(mod1)
```
## Extra options
There are several extra options you can enable with additional arguments to `extract_eq()`.
### Actual coefficients
You can return actual numeric coefficients instead of Greek letters with `use_coefs = TRUE`:
```{r use-coefs, eval=FALSE}
extract_eq(mod1, use_coefs = TRUE)
```
```{r use-coefs-preview, echo=FALSE}
eq1 <- extract_eq(mod1, use_coefs = TRUE)
print(eq1)
eq1
```
By default, it will remove doubled operators like "+ -", but you can keep those in (which is often useful for teaching) with `fix_signs = FALSE`:
```{r fix-signs, eval=FALSE}
extract_eq(mod1, use_coefs = TRUE, fix_signs = FALSE)
```
```{r fix-signs-preview, echo=FALSE}
eq1 <- extract_eq(mod1, use_coefs = TRUE, fix_signs = FALSE)
print(eq1)
eq1
```
This works in longer wrapped equations:
```{r fix-signs-long, eval=FALSE}
extract_eq(mod2, wrap = TRUE, terms_per_line = 3, use_coefs = TRUE,
fix_signs = FALSE)
```
```{r fix-signs-long-preview, echo=FALSE}
eq2 <- extract_eq(mod2, wrap = TRUE, terms_per_line = 3, use_coefs = TRUE,
fix_signs = FALSE)
print(eq2)
eq2
```
## Beyond `lm()`
You're not limited to just `lm` models! {equatiomatic} supports many other models, including logistic regression, probit regression, and ordered logistic regression (with `MASS::polr()`).
### Logistic regression with `glm()`
```{r example-logit, eval=FALSE}
model_logit <- glm(sex ~ bill_length_mm + species, data = penguins,
family = binomial(link = "logit"))
extract_eq(model_logit, wrap = TRUE, terms_per_line = 3)
```
```{r example-logit-preview, echo=FALSE}
model_logit <- glm(sex ~ bill_length_mm + species, data = penguins,
family = binomial(link = "logit"))
eq_logit <- extract_eq(model_logit, wrap = TRUE, terms_per_line = 3)
print(eq_logit)
eq_logit
```
### Probit regression with `glm()`
```{r example-probit, eval=FALSE}
model_probit <- glm(sex ~ bill_length_mm + species, data = penguins,
family = binomial(link = "probit"))
extract_eq(model_probit, wrap = TRUE, terms_per_line = 3)
```
```{r example-probit-preview, echo=FALSE}
model_probit <- glm(sex ~ bill_length_mm + species, data = penguins,
family = binomial(link = "probit"))
eq_probit <- extract_eq(model_probit, wrap = TRUE, terms_per_line = 3)
print(eq_probit)
eq_probit
```
### Ordered logistic regression with `MASS::polr()`
```{r example-polr, eval=FALSE}
set.seed(1234)
df <- data.frame(
outcome = ordered(rep(LETTERS[1:3], 100), levels = LETTERS[1:3]),
continuous_1 = rnorm(300, 100, 1),
continuous_2 = rnorm(300, 50, 5))
model_ologit <- MASS::polr(outcome ~ continuous_1 + continuous_2,
data = df, Hess = TRUE, method = "logistic")
model_oprobit <- MASS::polr(outcome ~ continuous_1 + continuous_2,
data = df, Hess = TRUE, method = "probit")
extract_eq(model_ologit, wrap = TRUE)
```
```{r example-ologit-preview, echo=FALSE}
set.seed(1234)
df <- data.frame(
outcome = ordered(rep(LETTERS[1:3], 100), levels = LETTERS[1:3]),
continuous_1 = rnorm(300, 100, 1),
continuous_2 = rnorm(300, 50, 5))
model_ologit <- MASS::polr(outcome ~ continuous_1 + continuous_2,
data = df, Hess = TRUE, method = "logistic")
model_oprobit <- MASS::polr(outcome ~ continuous_1 + continuous_2,
data = df, Hess = TRUE, method = "probit")
eq_ologit <- extract_eq(model_ologit, wrap = TRUE)
print(eq_ologit)
eq_ologit
```
```{r example-polr-probit, eval=FALSE}
extract_eq(model_oprobit, wrap = TRUE)
```
```{r example-polr-probit-preview, echo=FALSE}
eq_oprobit <- extract_eq(model_oprobit, wrap = TRUE)
print(eq_oprobit)
eq_oprobit
```
### Ordered regression (logit and probit) with `ordinal::clm()`
```{r example-clm, eval=FALSE}
set.seed(1234)
df <- data.frame(
outcome = ordered(rep(LETTERS[1:3], 100), levels = LETTERS[1:3]),
continuous_1 = rnorm(300, 1, 1),
continuous_2 = rnorm(300, 5, 5))
model_ologit <- ordinal::clm(outcome ~ continuous_1 + continuous_2,
data = df, link = "logit")
model_oprobit <- ordinal::clm(outcome ~ continuous_1 + continuous_2,
data = df, link = "probit")
extract_eq(model_ologit, wrap = TRUE)
```
```{r example-clm-ologit-preview, echo=FALSE}
set.seed(1234)
df <- data.frame(
outcome = ordered(rep(LETTERS[1:3], 100), levels = LETTERS[1:3]),
continuous_1 = rnorm(300, 1, 1),
continuous_2 = rnorm(300, 5, 5))
model_ologit <- ordinal::clm(outcome ~ continuous_1 + continuous_2,
data = df, link = "logit")
model_oprobit <- ordinal::clm(outcome ~ continuous_1 + continuous_2,
data = df, link = "probit")
eq_ologit <- extract_eq(model_ologit, wrap = TRUE)
print(eq_ologit)
eq_ologit
```
```{r example-clm-probit, eval=FALSE}
extract_eq(model_oprobit, wrap = TRUE)
```
```{r example-clm-oprobit-preview, echo=FALSE}
eq_oprobit <- extract_eq(model_oprobit, wrap = TRUE)
print(eq_oprobit)
eq_oprobit
```
## Extension
If you would like to contribute to this package, we'd love your help! We are particularly interested in extending to more models. We hope to support
any model supported by [{broom}](https://cran.r-project.org/package=broom) in the future.
## Code of Conduct
Please note that the 'equatiomatic' project is released with a [Contributor Code of Conduct](https://github.com/datalorax/equatiomatic/blob/master/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.
## A note of appreciation
We'd like to thank the authors of the [{palmerpenguins}](https://allisonhorst.github.io/palmerpenguins/index.html) dataset for generously allowing us to incorporate the `penguins` dataset in our package for example usage.
Horst AM, Hill AP, Gorman KB (2020). *palmerpenguins: Palmer Archipelago (Antarctica) penguin data*. R package version 0.1.0. https://allisonhorst.github.io/palmerpenguins/
Owner
- Name: Daniel Anderson
- Login: datalorax
- Kind: user
- Location: Eugene, OR
- Company: University of Oregon
- Website: http://www.datalorax.com
- Twitter: datalorax_
- Repositories: 10
- Profile: https://github.com/datalorax
Data scientist at Abl (https://github.com/ablschools). Formerly I was a Research Associate Professor in the College of Education at the University of Oregon.
GitHub Events
Total
- Issues event: 11
- Watch event: 7
- Issue comment event: 22
- Push event: 25
- Pull request event: 2
- Fork event: 1
Last Year
- Issues event: 11
- Watch event: 7
- Issue comment event: 22
- Push event: 25
- Pull request event: 2
- Fork event: 1
Committers
Last synced: about 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| Daniel Anderson | d****a@u****u | 335 |
| GitHub Actions | a****s@g****m | 79 |
| Andrew Heiss | a****w@a****m | 49 |
| Jay Sumners | j****s@g****m | 34 |
| Philippe Grosjean | p****n@s****g | 21 |
| Joshua Rosenberg | j****8@g****m | 9 |
| Indrajeet Patil | i****8@g****m | 9 |
| Thomas Fung | t****r@g****m | 7 |
| Joshua Rosenberg | j****g@g****m | 5 |
| Ellis Hughes | e****s@s****g | 4 |
| Daniel Anderson | d****7@i****m | 2 |
| Quinn White | q****e@s****u | 2 |
| iago-pssjd | 4****d | 2 |
| Ben Bolker | b****r@g****m | 1 |
| Darío Hereñú | m****a@g****m | 1 |
| yonicd | y****s@m****m | 1 |
| Jay Sumners | j****s@o****m | 1 |
| David Kane | d****e@g****m | 1 |
| Joshua Rosenberg | j****8@g****m | 1 |
Committer Domains (Top 20 + Academic)
github.com: 2
outloo.com: 1
metrumrg.com: 1
smith.edu: 1
scharp.org: 1
sciviews.org: 1
andrewheiss.com: 1
uoregon.edu: 1
Issues and Pull Requests
Last synced: 10 months ago
All Time
- Total issues: 75
- Total pull requests: 48
- Average time to close issues: 7 months
- Average time to close pull requests: 2 days
- Total issue authors: 58
- Total pull request authors: 10
- Average comments per issue: 5.25
- Average comments per pull request: 1.46
- Merged pull requests: 47
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 6
- Pull requests: 4
- Average time to close issues: 7 months
- Average time to close pull requests: 5 days
- Issue authors: 4
- Pull request authors: 2
- Average comments per issue: 0.17
- Average comments per pull request: 0.0
- Merged pull requests: 3
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- datalorax (5)
- mike-lawrence (4)
- davidkane9 (4)
- andrewheiss (3)
- d-morrison (3)
- benjaminwnelson (2)
- elbersb (2)
- JCruk (2)
- mymil (2)
- humburg (1)
- franzbischoff (1)
- Ax3man (1)
- ddsjoberg (1)
- mjbroerman (1)
- IlhemB (1)
Pull Request Authors
- datalorax (31)
- IndrajeetPatil (5)
- phgrosjean (5)
- JaySumners (2)
- GuyliannEngels (2)
- teunbrand (2)
- bbolker (1)
- davidkane9 (1)
- iago-pssjd (1)
- q-w-a (1)
Top Labels
Issue Labels
enhancement (17)
new model (6)
bug (5)
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 893 last-month
- Total dependent packages: 0
- Total dependent repositories: 5
- Total versions: 8
- Total maintainers: 1
cran.r-project.org: equatiomatic
Transform Models into 'LaTeX' Equations
- Homepage: https://github.com/datalorax/equatiomatic
- Documentation: http://cran.r-project.org/web/packages/equatiomatic/equatiomatic.pdf
- License: CC BY 4.0
-
Latest release: 0.4.4
published 10 months ago
Rankings
Stargazers count: 0.6%
Forks count: 2.0%
Downloads: 8.5%
Average: 11.0%
Dependent repos count: 13.9%
Dependent packages count: 29.8%
Maintainers (1)
Last synced:
10 months ago