-
Notifications
You must be signed in to change notification settings - Fork 0
/
mm.Rmd
57 lines (48 loc) · 1.74 KB
/
mm.Rmd
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
---
title: "``brms::make_standata`` Data for brms Models"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(brms)
```
mm Set up multi-membership grouping terms in brms
#### Description
Function to set up a multi-membership grouping term in brms. The function does not evaluate its
#### Arguments
– it exists purely to help set up a model with grouping terms.
#### Usage
<pre><code>
mm(..., weights = NULL, scale = TRUE, dist = "gaussian")
</code></pre>
#### Arguments
* ``...``: One or more terms containing grouping factors.
* ``weights``: A matrix specifying the weights of each member. It should have as many columns as grouping terms specified in .... If NULL (the default), equally weights are used.
* ``scale``: Logical; if TRUE (the default), weights are standardized in order to sum to one per row. If negative weights are specified, scale needs to be set to FALSE.
* ``dist``: Name of the distribution of the group-level effects. Currently "gaussian" is the only option.
#### Examples
```{r}
# simulate some data
dat <- data.frame(
y = rnorm(100), x1 = rnorm(100), x2 = rnorm(100),
g1 = sample(1:10, 100, TRUE), g2 = sample(1:10, 100, TRUE)
)
# multi-membership model with two members per group and equal weights
fit1 <- brm(y ~ x1 + (1|mm(g1, g2)), data = dat)
summary(fit1)
```
```{r}
# weight the first member two times for than the second member
dat$w1 <- rep(2, 100)
dat$w2 <- rep(1, 100)
fit2 <- brm(y ~ x1 + (1|mm(g1, g2, weights = cbind(w1, w2))), data = dat)
summary(fit2)
```
```{r}
# multi-membership model with level specific covariate #### Values
dat$xc <- (dat$x1 + dat$x2) / 2
fit3 <- brm(y ~ xc + (1 + mmc(x1, x2) | mm(g1, g2)), data = dat)
summary(fit3)
```
#### See Also
brmsformula, mmc