@@ -25,8 +25,7 @@ suppressMessages({
25
25
Reaction ~ Days + (1 | grp / subgrp ) + (1 | Subject ),
26
26
data = study_data
27
27
)
28
- fm6 <-
29
- lme4 :: lmer(diameter ~ 0 + sample + (1 | plate ), data = Penicillin )
28
+ fm6 <- lme4 :: lmer(diameter ~ 0 + sample + (1 | plate ), data = Penicillin )
30
29
})
31
30
32
31
v1 <- suppressWarnings(get_variance(fm1 ))
@@ -108,10 +107,10 @@ test_that("get_variance-6", {
108
107
109
108
# further examples
110
109
111
- model <- lme4 :: lmer(Reaction ~ Days + (1 + Days || Subject ), data = sleepstudy )
112
- vmodel <- get_variance(model )
113
-
114
110
test_that(" get_variance-7" , {
111
+ model <- lme4 :: lmer(Reaction ~ Days + (1 + Days || Subject ), data = sleepstudy )
112
+ vmodel <- get_variance(model )
113
+
115
114
expect_equal(
116
115
vmodel ,
117
116
list (
@@ -127,10 +126,11 @@ test_that("get_variance-7", {
127
126
)
128
127
})
129
128
130
- model <- lme4 :: lmer(Reaction ~ Days + (0 + Days || Subject ), data = study_data )
131
- vmodel <- get_variance(model )
132
129
133
130
test_that(" get_variance-8" , {
131
+ model <- lme4 :: lmer(Reaction ~ Days + (0 + Days || Subject ), data = study_data )
132
+ vmodel <- get_variance(model )
133
+
134
134
expect_equal(
135
135
vmodel ,
136
136
list (
@@ -148,14 +148,14 @@ test_that("get_variance-8", {
148
148
149
149
# categorical rnd slope
150
150
151
- data(sleepstudy , package = " lme4" )
152
- sleepstudy $ Days2 <- cut(sleepstudy $ Days , breaks = c(- 1 , 3 , 6 , 10 ))
153
- study_data2 <<- sleepstudy
151
+ test_that(" get_variance-9" , {
152
+ data(sleepstudy , package = " lme4" )
153
+ sleepstudy $ Days2 <- cut(sleepstudy $ Days , breaks = c(- 1 , 3 , 6 , 10 ))
154
+ study_data2 <<- sleepstudy
154
155
155
- model <- lme4 :: lmer(Reaction ~ Days2 + (1 + Days2 | Subject ), data = study_data2 )
156
- vmodel <- get_variance(model )
156
+ model <- lme4 :: lmer(Reaction ~ Days2 + (1 + Days2 | Subject ), data = study_data2 )
157
+ vmodel <- get_variance(model )
157
158
158
- test_that(" get_variance-9" , {
159
159
expect_equal(
160
160
vmodel ,
161
161
list (
@@ -180,10 +180,11 @@ test_that("get_variance-9", {
180
180
)
181
181
})
182
182
183
- model <- suppressMessages(lme4 :: lmer(Reaction ~ Days2 + (1 + Days2 || Subject ), data = study_data2 ))
184
- vmodel <- suppressWarnings(get_variance(model ))
185
183
186
184
test_that(" get_variance-10" , {
185
+ model <- suppressMessages(lme4 :: lmer(Reaction ~ Days2 + (1 + Days2 || Subject ), data = study_data2 ))
186
+ vmodel <- suppressWarnings(get_variance(model ))
187
+
187
188
expect_equal(
188
189
vmodel ,
189
190
list (
@@ -203,10 +204,11 @@ test_that("get_variance-10", {
203
204
)
204
205
})
205
206
206
- model <- lme4 :: lmer(Reaction ~ Days2 + (0 + Days2 | Subject ), data = study_data2 )
207
- vmodel <- get_variance(model )
208
207
209
208
test_that(" get_variance-11" , {
209
+ model <- lme4 :: lmer(Reaction ~ Days2 + (0 + Days2 | Subject ), data = study_data2 )
210
+ vmodel <- get_variance(model )
211
+
210
212
expect_equal(
211
213
vmodel ,
212
214
list (
@@ -230,10 +232,11 @@ test_that("get_variance-11", {
230
232
)
231
233
})
232
234
233
- model <- lme4 :: lmer(Reaction ~ Days2 + (0 + Days2 || Subject ), data = study_data2 )
234
- vmodel <- get_variance(model )
235
235
236
236
test_that(" get_variance-12" , {
237
+ model <- lme4 :: lmer(Reaction ~ Days2 + (0 + Days2 || Subject ), data = study_data2 )
238
+ vmodel <- get_variance(model )
239
+
237
240
expect_equal(
238
241
vmodel ,
239
242
list (
@@ -260,12 +263,13 @@ test_that("get_variance-12", {
260
263
261
264
# test random slope correlation for categorical random slope
262
265
263
- data(cake , package = " lme4" )
264
- suppressMessages({
265
- m <- lme4 :: lmer(angle ~ temperature + (temperature | recipe ), data = cake )
266
- })
267
266
test_that(" get_variance-cat_random_slope" , {
267
+ data(cake , package = " lme4" )
268
+ suppressMessages({
269
+ m <- lme4 :: lmer(angle ~ temperature + (temperature | recipe ), data = cake )
270
+ })
268
271
vc <- suppressWarnings(get_variance(m ))
272
+
269
273
expect_equal(
270
274
vc $ cor.slopes ,
271
275
c(
@@ -328,13 +332,14 @@ test_that("random effects CIs, simple slope", {
328
332
)
329
333
})
330
334
331
- data(cake , package = " lme4" )
332
- suppressMessages({
333
- m <- lme4 :: lmer(angle ~ poly(temp , 2 ) + (poly(temp , 2 ) | replicate ) + (1 | recipe ), data = cake )
334
- })
335
335
336
336
test_that(" random effects CIs, poly slope" , {
337
+ data(cake , package = " lme4" )
338
+ suppressMessages({
339
+ m <- lme4 :: lmer(angle ~ poly(temp , 2 ) + (poly(temp , 2 ) | replicate ) + (1 | recipe ), data = cake )
340
+ })
337
341
vc <- suppressWarnings(get_variance(m ))
342
+
338
343
expect_equal(
339
344
vc $ cor.slopes ,
340
345
c(`replicate.poly(temp, 2)1-poly(temp, 2)2` = 0.940016422944175 ),
0 commit comments