-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathREADME.Rmd
More file actions
122 lines (83 loc) · 4.39 KB
/
README.Rmd
File metadata and controls
122 lines (83 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r}
#| include: false
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# multilevelmod <a href="https://multilevelmod.tidymodels.org/"><img src="man/figures/logo.png" align="right" height="138" alt="3 nesting dolls on an orange background" /></a>
<!-- badges: start -->
[](https://lifecycle.r-lib.org/articles/stages.html)
[](https://app.codecov.io/gh/tidymodels/multilevelmod)
[](https://github.com/tidymodels/multilevelmod/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
multilevelmod enables the use of multi-level models (a.k.a mixed-effects models, Bayesian hierarchical models, etc.) with the parsnip package.
<a href="https://pbs.twimg.com/media/FD1_OIhVIAE4H5l?format=jpg&name=small"><img src="man/figures/FD1_OIhVIAE4H5l.jpeg" align="center" alt="A sweaty Comic character trying to decide which button to push. The buttons read: 'mixed effect model', 'hierarchical linear model', 'random effects model', 'variance component model', 'mixed model', 'random intercepts/slopes', 'regularized regression', 'multilevel model', 'nested data model', and 'random parameter model'". /></a>
(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")
names(parsnip_models) <- parsnip_models
parsnip_models <- parsnip_models |>
purrr::map_dfr(get_from_env, .id = "model")
library(multilevelmod)
multilevelmod_models <- get_from_env("models")
names(multilevelmod_models) <- multilevelmod_models
multilevelmod_models <- multilevelmod_models |>
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/).