-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
134 lines (104 loc) · 2.86 KB
/
README.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
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
122
123
124
125
126
127
128
129
130
131
132
133
---
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-"
)
```
# varde
<!-- badges: start -->
<!-- badges: end -->
The goal of varde is to provide functions for decomposing the variance in multilevel models, e.g., for g studies in generalizability theory or intraclass correlation analyses in interrater reliability.
## Installation
You can install the development version of varde from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("jmgirard/varde")
```
## Example
In the `ppa` example dataset, 72 human "raters" judged the perceived physical attractiveness of 36 human "targets" in 6 different conditions (i.e., stimulus "types").
```{r}
library(varde)
# Extract only type 1 observations (to simplify the example)
ppa_type1 <- ppa[ppa$Type == 1, ]
```
### Simple Frequentist G Study
```{r}
fit_0 <- lme4::lmer(
formula = Sepal.Length ~ 1 + (1 | Species),
data = iris
)
varde(fit_0)
```
### Simple Generalizability Study
```{r res_1, message=FALSE}
# Fit a mixed effects model with target and rater effects
fit_1 <- brms::brm(
formula = Score ~ 1 + (1 | Target) + (1 | Rater),
data = ppa_type1,
chains = 4,
cores = 4,
init = "random",
warmup = 5000,
iter = 10000,
seed = 2022,
file = "m1"
)
```
```{r}
# Extract variance component estimates
res_1 <- varde(fit_1)
res_1
```
```{r p1a, fig.width=9, fig.height=4, out.width="100%"}
# Create river plot of variance percentages
plot(res_1, type = "river")
```
```{r p1b, fig.width=9, fig.height=2.5, out.width="100%", warning=FALSE}
# Create density plot of variance posteriors
plot(res_1, type = "variances")
```
```{r p1c, fig.width=9, fig.height=2.5, out.width="100%"}
# Create jitter plot of random intercepts
plot(res_1, type = "intercepts")
```
### Simple Two-Way ICC for Inter-Rater Reliability
```{r res_2, message=FALSE}
# Calculate variance components and ICCs
res_2 <- calc_icc(
.data = ppa_type1,
subject = "Target",
rater = "Rater",
scores = "Score",
k = 12,
file = "m2"
)
res_2
```
```{r p2a, fig.width=9, fig.height=5, out.width="100%", warning=FALSE}
# Create density plot of all posteriors
plot(res_2)
```
```{r p2b, fig.width=9, fig.height=2, out.width="100%", warning=FALSE}
# Create density plot of specific posteriors
plot(res_2, parameters = c("ICC(A,k)", "ICC(C,k)"))
```
### Multivariate MCMC for Many ICCs
In `posneg`, 110 images were rated by between 2 and 5 raters on how "Negative" and "Positive" they appeared.
```{r res_3, message=FALSE}
# Calculate variance components and ICCs
res_3 <- calc_icc(
.data = posneg,
subject = "Image",
rater = "Rater",
scores = c("Negative", "Positive"),
file = "m3",
cores = 4,
control = list(adapt_delta = 0.999)
)
res_3
```