Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tidymodels/multilevelmod
Parsnip wrappers for mixed-level and hierarchical models
https://github.com/tidymodels/multilevelmod
Last synced: 3 days ago
JSON representation
Parsnip wrappers for mixed-level and hierarchical models
- Host: GitHub
- URL: https://github.com/tidymodels/multilevelmod
- Owner: tidymodels
- License: other
- Created: 2020-04-23T22:54:06.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-17T13:48:01.000Z (27 days ago)
- Last Synced: 2024-10-31T22:03:17.213Z (12 days ago)
- Language: R
- Homepage: https://multilevelmod.tidymodels.org/
- Size: 3.14 MB
- Stars: 74
- Watchers: 9
- Forks: 3
- Open Issues: 10
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Support: .github/SUPPORT.md
Awesome Lists containing this project
- jimsghstars - tidymodels/multilevelmod - Parsnip wrappers for mixed-level and hierarchical models (R)
README
---
output: github_document
---```{r}
#| include: false
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![Codecov test coverage](https://codecov.io/gh/tidymodels/multilevelmod/branch/main/graph/badge.svg)](https://app.codecov.io/gh/tidymodels/multilevelmod?branch=main)
[![R-CMD-check](https://github.com/tidymodels/multilevelmod/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tidymodels/multilevelmod/actions/workflows/R-CMD-check.yaml)multilevelmod enables the use of multi-level models (a.k.a mixed-effects models, Bayesian hierarchical models, etc.) with the parsnip package.
(meme courtesy of [`@ChelseaParlett`](https://twitter.com/ChelseaParlett))
## Installation
You can install the released version of multilevelmod from [CRAN](https://cran.r-project.org) with:
``` r
install.packages("multilevelmod")
```For the development version:
``` r
# install.packages("pak")
pak::pak("tidymodels/multilevelmod")
```## Available Engines
The multilevelmod package provides engines for the models in the following table.
```{r}
#| echo: false
#| message: false
library(parsnip)parsnip_models <- get_from_env("models") %>%
setNames(., .) %>%
purrr::map_dfr(get_from_env, .id = "model")library(multilevelmod)
multilevelmod_models <- get_from_env("models") %>%
setNames(., .) %>%
purrr::map_dfr(get_from_env, .id = "model")dplyr::anti_join(
multilevelmod_models, parsnip_models,
by = c("model", "engine", "mode")
) %>%
knitr::kable()
```## Example
Loading mixedlevelmod will trigger it to add a few modeling _engines_ to the parsnip model database. For Bayesian models, there are now `stan-glmer` engines for `linear_reg()`, `logistic_reg()`, and `poisson_reg()`.
To use these, the function `parsnip::fit()` function should be used instead of `parsnip::fit_xy()` so that the model terms can be specified using the `lme`/`lme4` syntax.
The `sleepstudy` data is used as an example:
```{r}
#| label: sleep-lme
library(multilevelmod)
set.seed(1234)
data(sleepstudy, package = "lme4")mixed_model_spec <- linear_reg() %>% set_engine("lmer")
mixed_model_fit <-
mixed_model_spec %>%
fit(Reaction ~ Days + (Days | Subject), data = sleepstudy)mixed_model_fit
```For a Bayesian model:
```{r}
#| label: sleep-stan
hier_model_spec <- linear_reg() %>% set_engine("stan_glmer")hier_model_fit <-
hier_model_spec %>%
fit(Reaction ~ Days + (Days | Subject), data = sleepstudy)hier_model_fit
```## Contributing
This project is released with a [Contributor Code of Conduct](https://www.contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
- For questions and discussions about tidymodels packages, modeling, and machine learning, please [post on RStudio Community](https://community.rstudio.com/new-topic?category_id=15&tags=tidymodels,question).
- If you think you have encountered a bug, please [submit an issue](https://github.com/tidymodels/multilevelmod/issues).
- Either way, learn how to create and share a [reprex](https://community.rstudio.com/new-topic?category_id=15&tags=tidymodels,question) (a minimal, reproducible example), to clearly communicate about your code.
- Check out further details on [contributing guidelines for tidymodels packages](https://www.tidymodels.org/contribute/) and [how to get help](https://www.tidymodels.org/help/).