1
- # ' Variability-Over-Uncertainty Ratio (d-vour) for Random Effects Reliability
1
+ # ' Random Effects Reliability
2
+ # '
3
+ # ' Variability-Over-Uncertainty Ratio (d-vour).
2
4
# '
3
5
# ' @description TODO: Add description.
4
6
# '
5
7
# ' @param x A model object (or from [`modelbased::estimate_grouplevel()`]).
6
- # ' @param n_trials to do...
7
8
# ' @param ... Currently not used.
8
9
# '
9
10
#
18
19
# '
19
20
# ' @references TODO.
20
21
# '
21
- # ' @family functions to check model assumptions and and assess model quality
22
22
# '
23
- # ' @examplesIf require("lme4") & require("glmmTMB")
23
+ # ' @examplesIf require("lme4") && require("glmmTMB")
24
24
# ' df <- read.csv("https://raw.githubusercontent.com/easystats/circus/refs/heads/main/data/illusiongame.csv")
25
25
# '
26
26
# ' m <- lme4::lmer(RT ~ (1 | Participant), data = df)
27
- # ' check_reliability(m)
27
+ # ' performance_reliability(m)
28
+ # ' performance_dvour(m)
28
29
# ' m <- glmmTMB::glmmTMB(RT ~ (1 | Participant), data = df)
29
- # ' check_reliability(m)
30
+ # ' performance_reliability(m)
31
+ # ' performance_dvour(m)
30
32
# '
31
33
# ' m <- lme4::lmer(RT ~ (1 | Participant) + (1 | Trial), data = df)
32
- # ' check_reliability(m)
34
+ # ' performance_reliability(m)
35
+ # ' performance_dvour(m)
33
36
# ' m <- glmmTMB::glmmTMB(RT ~ (1 | Participant) + (1 | Trial), data = df)
34
- # ' check_reliability(m)
37
+ # ' performance_reliability(m)
38
+ # ' performance_dvour(m)
35
39
# '
36
40
# ' m <- lme4::lmer(RT ~ Illusion_Difference + (Illusion_Difference | Participant) + (1 | Trial), data = df)
37
- # ' check_reliability(m)
41
+ # ' performance_reliability(m)
42
+ # ' performance_dvour(m)
38
43
# ' m <- glmmTMB::glmmTMB(RT ~ Illusion_Difference + (Illusion_Difference | Participant) + (1 | Trial), data = df)
39
- # ' check_reliability(m)
44
+ # ' performance_reliability(m)
45
+ # ' performance_dvour(m)
40
46
# ' @export
41
- check_reliability <- function (x , ... ) {
42
- UseMethod(" check_reliability " )
47
+ performance_reliability <- function (x , ... ) {
48
+ UseMethod(" performance_reliability " )
43
49
}
44
50
45
51
46
52
# ' @export
47
- check_reliability.default <- function (x , ... ) {
48
- insight :: check_if_installed(" modelbased" , minimum_version = " 0.10.0" )
49
- check_reliability(modelbased :: estimate_grouplevel(x , ... ), ... )
53
+ performance_reliability.default <- function (x , ... ) {
54
+ # Find how many observations per random effect (n-trials)
55
+ random <- lapply(insight :: get_random(x ), function (z ) min(table(z )))
56
+ v <- insight :: get_variance(x ) # Extract variance components
57
+
58
+ params <- as.data.frame(parameters :: parameters(x , effects = " random" , group_level = TRUE ))
59
+
60
+ reliability <- data.frame ()
61
+ for (grp in unique(params $ Group )) {
62
+ for (param in unique(params $ Parameter )) {
63
+ # Store group-level results
64
+ rez <- data.frame (
65
+ Group = grp ,
66
+ Parameter = param
67
+ )
68
+
69
+
70
+ # Based on Rouder's (2024) paper https://journals.sagepub.com/doi/10.1177/09637214231220923
71
+ # "What part of reliability is invariant to trial size? Consider the ratio sigma_B^2 / sigma_W^2.
72
+ # This is a signal-to-noise variance ratio - it is how much more variable people are relative to
73
+ # trial noise. Let gamma2 denote this ratio. With it, the reliability coefficient follows (eq. 1):
74
+ # E(r) = gamma2 / (gamma2 + 2/L)" (or 1/L for non-contrast tasks, see annotation 4)
75
+
76
+ # Number of trials per group
77
+ L <- random [[grp ]]
78
+
79
+ # Extract variances
80
+ if (param %in% c(" (Intercept)" , " Intercept" )) {
81
+ var_between <- v $ var.intercept [grp ]
82
+ } else {
83
+ var_between <- v $ var.slope [paste0(grp , " ." , param )]
84
+ }
85
+
86
+ # Non-adjusted index
87
+ # rez$Reliability <- var_between / (var_between + v$var.residual)
88
+
89
+ # Adjusted index:
90
+ # Rouder & Mehrvarz suggest 1/L for non-contrast tasks and 2/L for contrast tasks.
91
+ rez $ Reliability <- var_between / (var_between + v $ var.residual + 1 / L )
92
+
93
+ # The parameter γ is the signal-to-noise standard-deviation ratio. It is often convenient for
94
+ # communication as standard deviations are sometimes more convenient than variances.
95
+ # rez$Reliability_adjusted <- sqrt(rez$Reliability_adjusted)
96
+
97
+ reliability <- rbind(reliability , rez )
98
+ }
99
+ }
100
+
101
+ reliability
50
102
}
51
103
52
104
53
- # ' @rdname check_reliability
105
+
106
+
107
+
108
+
109
+
110
+ # d-vour ------------------------------------------------------------------
111
+
112
+
113
+
114
+ # ' @rdname performance_reliability
54
115
# ' @export
55
- check_reliability.estimate_grouplevel <- function (x , ... ) {
116
+ performance_dvour <- function (x , ... ) {
117
+ UseMethod(" performance_dvour" )
118
+ }
56
119
57
- coefname <- attributes(x )$ coef_name
58
- dispname <- grep(" SE|SD|MAD" , colnames(x ), value = TRUE )
59
120
60
- # Extract model information
61
- model <- attributes(x )$ model
121
+ # ' @export
122
+ performance_dvour.default <- function (x , ... ) {
123
+ insight :: check_if_installed(" modelbased" , minimum_version = " 0.10.0" )
124
+ performance_dvour(modelbased :: estimate_grouplevel(x , ... ), ... )
125
+ }
62
126
63
- # Find how many observations per random effect (n-trials)
64
- random <- lapply(insight :: get_random(model ), function (x ) min(table(x )))
65
- v <- insight :: get_variance(model ) # Extract variance components
66
127
128
+ # ' @export
129
+ performance_dvour.estimate_grouplevel <- function (x , ... ) {
130
+
131
+ coefname <- attributes(x )$ coef_name
132
+ dispname <- grep(" SE|SD|MAD" , colnames(x ), value = TRUE )
67
133
68
134
# Sanity checks
69
135
if (insight :: n_unique(x $ Level ) < = 3 ) {
@@ -97,11 +163,6 @@ check_reliability.estimate_grouplevel <- function(x, ...) {
97
163
98
164
reliability <- data.frame ()
99
165
100
- # TODO: need to decide on which indices we want to use.
101
-
102
- # we need these nested loops only if we need to calculate the reliability
103
- # index for the different random effects parameters. If we want an "overall"
104
- # reliability index, we can simply call ".expected_reliability()".
105
166
for (comp in unique(x $ Component )) {
106
167
for (grp in unique(x $ Group )) {
107
168
for (param in unique(x $ Parameter )) {
@@ -115,42 +176,12 @@ check_reliability.estimate_grouplevel <- function(x, ...) {
115
176
Parameter = param
116
177
)
117
178
118
-
119
- # Rouder (2024) --------------------------------------------------------
120
- # Based on Rouder's (2024) paper https://journals.sagepub.com/doi/10.1177/09637214231220923
121
- # "What part of reliability is invariant to trial size? Consider the ratio sigma_B^2 / sigma_W^2.
122
- # This is a signal-to-noise variance ratio - it is how much more variable people are relative to
123
- # trial noise. Let gamma2 denote this ratio. With it, the reliability coefficient follows (eq. 1):
124
- # E(r) = gamma2 / (gamma2 + 2/L)" (or 1/L for non-contrast tasks, see annotation 4)
125
-
126
- # Number of trials per group
127
- L <- random [[grp ]]
128
-
129
- # Extract variances
130
- if (param %in% c(" (Intercept)" , " Intercept" )) {
131
- var_between <- v $ var.intercept [grp ]
132
- } else {
133
- var_between <- v $ var.slope [paste0(grp , " ." , param )]
134
- }
135
-
136
- # Non-adjusted index
137
- # rez$Reliability <- var_between / (var_between + v$var.residual)
138
-
139
- # Adjusted index:
140
- # Rouder & Mehrvarz suggest 1/L for non-contrast tasks and 2/L for contrast tasks.
141
- rez $ Reliability <- var_between / (var_between + v $ var.residual + 1 / L )
142
-
143
- # The parameter γ is the signal-to-noise standard-deviation ratio. It is often convenient for
144
- # communication as standard deviations are sometimes more convenient than variances.
145
- # rez$Reliability_adjusted <- sqrt(rez$Reliability_adjusted)
146
-
147
- # d-vour ------------------------------------------------------------------
148
179
# Variability-Over-Uncertainty Ratio (d-vour)
149
180
# This index is based on the information contained in the group-level estimates.
150
181
var_between <- stats :: sd(d [[coefname ]]) # Variability
151
182
var_within <- mean(d [[dispname ]]) # Average Uncertainty
152
183
153
- rez $ Dvour <- var_between ^ 2 / (var_between ^ 2 + var_within ^ 2 )
184
+ rez $ D_vour <- var_between ^ 2 / (var_between ^ 2 + var_within ^ 2 )
154
185
155
186
# Alternative 1: average of level-specific reliability
156
187
# Inspired by the hlmer package (R version of HLM7 by Raudenbush et al., 2014)
0 commit comments