-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmo.Rmd
63 lines (53 loc) · 1.33 KB
/
mo.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
58
59
60
61
62
63
---
title: "``brms::mo``"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(brms)
```
``mo`` Monotonic Predictors in brms Models
#### Description
Monotonic Predictors in brms Models
#### Usage
<pre><code>
mo(x)
</code></pre>
#### Arguments
* ``x``: An integer variable or an ordered factor to be modeled as monotonic.
#### Examples
```{r}
## Not run:
# generate some data
income_options <- c("below_20", "20_to_40", "40_to_100", "greater_100")
income <- factor(sample(income_options, 100, TRUE),
levels = income_options, ordered = TRUE)
mean_ls <- c(30, 60, 70, 75)
ls <- mean_ls[income] + rnorm(100, sd = 7)
dat <- data.frame(income, ls)
# fit a simple monotonic model
fit1 <- brm(ls ~ mo(income), data = dat)
```
```{r}
# summarise the model
summary(fit1)
plot(fit1, N = 6)
plot(marginal_effects(fit1), points = TRUE)
```
```{r}
# model interaction with other variables
110 model_weights.brmsfit
dat$x <- sample(c("a", "b", "c"), 100, TRUE)
fit2 <- brm(ls ~ mo(income)*x, data = dat)
```
```{r}
# summarise the model
summary(fit2)
plot(marginal_effects(fit2), points = TRUE)
## End(Not run)
```
#### Details
For detailed documentation see help(brmsformula) as well as vignette("brms_monotonic").
This function is almost solely useful when called in formulas passed to the brms package.
See Also
brmsformula