@@ -90,12 +90,12 @@ test_that("icc", {
90
90
skip_if_not_installed(" lme4" )
91
91
data(sleepstudy , package = " lme4" )
92
92
set.seed(12345 )
93
- sleepstudy $ grp <- sample( 1 : 5 , size = 180 , replace = TRUE )
93
+ sleepstudy $ grp <- sample.int( 5 , size = 180 , replace = TRUE )
94
94
sleepstudy $ subgrp <- NA
95
95
for (i in 1 : 5 ) {
96
96
filter_group <- sleepstudy $ grp == i
97
97
sleepstudy $ subgrp [filter_group ] <-
98
- sample( 1 : 30 , size = sum(filter_group ), replace = TRUE )
98
+ sample.int( 30 , size = sum(filter_group ), replace = TRUE )
99
99
}
100
100
model <- lme4 :: lmer(
101
101
Reaction ~ Days + (1 | grp ) + (1 | Subject ),
@@ -125,3 +125,50 @@ test_that("icc", {
125
125
expect_equal(out $ ICC_adjusted , 0.9104331 , tolerance = 0.01 )
126
126
expect_equal(out $ ICC_unadjusted , 0.3109478 , tolerance = 0.01 )
127
127
})
128
+
129
+
130
+ test_that(" icc, glmmTMB 1.1.9+" , {
131
+ skip_on_cran()
132
+ skip_if_not_installed(" glmmTMB" , min_version = " 1.1.9" )
133
+ set.seed(101 )
134
+ dd <- data.frame (
135
+ z = rnorm(1000 ),
136
+ x1 = 1 : 1000 ,
137
+ x2 = runif(1000 , 0 , 10 ),
138
+ re = rep(1 : 20 , each = 50 )
139
+ )
140
+ dd <- transform(dd , x3 = as.factor(ifelse(
141
+ x1 < = 500 , " Low" , sample(c(" Middle" , " High" ), 1000 , replace = TRUE )
142
+ )))
143
+ dd <- transform(dd , x4 = as.factor(ifelse(
144
+ x1 > 500 , " High" , sample(c(" Absent" , " Low" ), 1000 , replace = TRUE )
145
+ )))
146
+ dd <- transform(dd , z = z + re * 5 )
147
+ expect_message({
148
+ mod_TMB <- glmmTMB :: glmmTMB(
149
+ z ~ x1 + x2 + x3 + x4 + (1 | re ),
150
+ data = dd ,
151
+ start = list (theta = 3 ),
152
+ control = glmmTMB :: glmmTMBControl(rank_check = " adjust" )
153
+ )
154
+ })
155
+ expect_equal(
156
+ icc(mod_TMB ),
157
+ data.frame (
158
+ ICC_adjusted = 0.995480998331767 ,
159
+ ICC_conditional = 0.244468078371849 ,
160
+ ICC_unadjusted = 0.244468078371849
161
+ ),
162
+ ignore_attr = TRUE ,
163
+ tolerance = 1e-4
164
+ )
165
+ expect_equal(
166
+ r2(mod_TMB ),
167
+ list (
168
+ R2_conditional = c(`Conditional R2` = 0.998890233308478 ),
169
+ R2_marginal = c(`Marginal R2` = 0.754422154936629 )
170
+ ),
171
+ ignore_attr = TRUE ,
172
+ tolerance = 1e-4
173
+ )
174
+ })
0 commit comments