-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathme.Rmd
63 lines (42 loc) · 1.4 KB
/
me.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
---
title: "``brms::me``"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(brms)
```
## ``me``
Predictors with Measurement Error in brms Models
#### Description
Specify predictors with measurement error. This function is almost solely useful when called in formulas passed to the brms package.
#### Usage
<pre><code>
me(x, sdx = NULL, gr = NULL)
</code></pre>
#### Arguments
* ``x``: The variable measured with error.
* ``sdx``: Known measurement error of x treated as standard deviation.
* ``gr``: Optional grouping factor to specify which values of ``x`` correspond to the same value of the latent variable. If NULL (the default) each observation will have its own value of the latent variable.
#### Examples
```{r}
# sample some data
N <- 100
dat <- data.frame(
y = rnorm(N), x1 = rnorm(N),
x2 = rnorm(N), sdx = abs(rnorm(N, 1))
)
# fit a simple error-in-variables model
fit1 <- brm(y ~ me(x1, sdx) + me(x2, sdx), data = dat, save_mevars = TRUE)
summary(fit1)
```
```{r]
# turn off modeling of correlations
bform <- bf(y ~ me(x1, sdx) + me(x2, sdx)) + set_mecor(FALSE)
fit2 <- brm(bform, data = dat, save_mevars = TRUE)
summary(fit2)
```
#### Details
For detailed documentation see help(brmsformula).
By default, latent noise-free variables are assumed to be correlated. To change that, add set_mecor(FALSE)
to your model formula object (see examples).