Skip to content

Commit a67c5b1

Browse files
committed
fix
1 parent 20b8435 commit a67c5b1

File tree

2 files changed

+37
-161
lines changed

2 files changed

+37
-161
lines changed

R/standard_error_kenward.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#' @rdname p_value_kenward
22
#' @export
3-
se_kenward <- function(model) {
3+
se_kenward <- function(model, component = "conditional") {
44
if (!.check_REML_fit(model)) {
55
model <- stats::update(model, . ~ ., REML = TRUE)
66
}
77

88
vcov_adjusted <- insight::get_varcov(model, vcov = "kenward-roger")
9-
params <- insight::get_parameters(model, effects = "fixed", component)
9+
params <- insight::get_parameters(model, effects = "fixed", component = component)
1010

1111
.data_frame(Parameter = params$Parameter, SE = abs(sqrt(diag(vcov_adjusted))))
1212
}

tests/testthat/test-model_parameters_df_method.R

Lines changed: 35 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,251 +1,125 @@
11
skip_if_not_installed("lmerTest")
22
skip_if_not_installed("pbkrtest")
33
skip_if_not_installed("lme4")
4+
skip_if_not_installed("glmmTMB")
45

56
mtcars$cyl <- as.factor(mtcars$cyl)
6-
model <- suppressMessages(lme4::lmer(mpg ~ as.factor(gear) * hp + as.factor(am) + wt + (1 | cyl), data = mtcars))
7-
model2 <- suppressMessages(lmerTest::lmer(mpg ~ as.factor(gear) * hp + as.factor(am) + wt + (1 | cyl), data = mtcars))
7+
model <- suppressMessages(lme4::lmer(
8+
mpg ~ as.factor(gear) * hp + as.factor(am) + wt + (1 | cyl),
9+
data = mtcars
10+
))
11+
model2 <- suppressMessages(lmerTest::lmer(
12+
mpg ~ as.factor(gear) * hp + as.factor(am) + wt + (1 | cyl),
13+
data = mtcars
14+
))
15+
model3 <- suppressMessages(glmmTMB::glmmTMB(
16+
mpg ~ as.factor(gear) * hp + as.factor(am) + wt + (1 | cyl),
17+
data = mtcars,
18+
REML = TRUE
19+
))
820

921
mp0 <- model_parameters(model, digits = 5, effects = "fixed")
1022
mp1 <- model_parameters(model, digits = 5, ci_method = "normal", effects = "fixed")
1123
mp2 <- model_parameters(model, digits = 5, ci_method = "s", effects = "fixed")
1224
mp3 <- model_parameters(model, digits = 5, ci_method = "kr", effects = "fixed")
1325
mp4 <- model_parameters(model, digits = 5, ci_method = "wald", effects = "fixed")
26+
mp5 <- model_parameters(model3, digits = 5, ci_method = "kr", effects = "fixed")
1427

1528
test_that("model_parameters, ci_method default (residual)", {
1629
expect_equal(
1730
mp0$SE,
18-
c(
19-
2.77457,
20-
3.69574,
21-
3.521,
22-
0.01574,
23-
1.58514,
24-
0.86316,
25-
0.02973,
26-
0.01668
27-
),
31+
c(2.77457, 3.69574, 3.521, 0.01574, 1.58514, 0.86316, 0.02973, 0.01668),
2832
tolerance = 1e-3
2933
)
3034
expect_equal(mp0$df, c(22, 22, 22, 22, 22, 22, 22, 22), tolerance = 1e-3)
3135
expect_equal(
3236
mp0$p,
33-
c(
34-
0,
35-
0.00258,
36-
0.14297,
37-
0.17095,
38-
0.84778,
39-
0.00578,
40-
0.00151,
41-
0.32653
42-
),
37+
c(0, 0.00258, 0.14297, 0.17095, 0.84778, 0.00578, 0.00151, 0.32653),
4338
tolerance = 1e-3
4439
)
4540
expect_equal(
4641
mp0$CI_low,
47-
c(
48-
24.54722,
49-
4.89698,
50-
-1.95317,
51-
-0.05493,
52-
-2.97949,
53-
-4.42848,
54-
-0.16933,
55-
-0.05133
56-
),
42+
c(24.54722, 4.89698, -1.95317, -0.05493, -2.97949, -4.42848, -0.16933, -0.05133),
5743
tolerance = 1e-3
5844
)
5945
})
6046

6147
test_that("model_parameters, ci_method normal", {
6248
expect_equal(
6349
mp1$SE,
64-
c(
65-
2.77457,
66-
3.69574,
67-
3.521,
68-
0.01574,
69-
1.58514,
70-
0.86316,
71-
0.02973,
72-
0.01668
73-
),
74-
tolerance = 1e-3
75-
)
76-
expect_equal(
77-
mp1$df,
78-
c(22, 22, 22, 22, 22, 22, 22, 22),
50+
c(2.77457, 3.69574, 3.521, 0.01574, 1.58514, 0.86316, 0.02973, 0.01668),
7951
tolerance = 1e-3
8052
)
53+
expect_equal(mp1$df, c(22, 22, 22, 22, 22, 22, 22, 22), tolerance = 1e-3)
8154
expect_equal(
8255
mp1$p,
8356
c(0, 0.00068, 0.12872, 0.15695, 0.846, 0.00224, 0.00029, 0.31562),
8457
tolerance = 1e-3
8558
)
8659
expect_equal(
8760
mp1$CI_low,
88-
c(
89-
24.86326,
90-
5.31796,
91-
-1.5521,
92-
-0.05313,
93-
-2.79893,
94-
-4.33015,
95-
-0.16595,
96-
-0.04943
97-
),
61+
c(24.86326, 5.31796, -1.5521, -0.05313, -2.79893, -4.33015, -0.16595, -0.04943),
9862
tolerance = 1e-3
9963
)
10064
})
10165

10266
test_that("model_parameters, ci_method satterthwaite", {
10367
expect_equal(
10468
mp2$SE,
105-
c(
106-
2.77457,
107-
3.69574,
108-
3.521,
109-
0.01574,
110-
1.58514,
111-
0.86316,
112-
0.02973,
113-
0.01668
114-
),
69+
c(2.77457, 3.69574, 3.521, 0.01574, 1.58514, 0.86316, 0.02973, 0.01668),
11570
tolerance = 1e-3
11671
)
11772
expect_equal(mp2$df, c(24, 24, 24, 24, 24, 24, 24, 24), tolerance = 1e-3)
11873
expect_equal(
11974
mp2$p,
120-
c(
121-
0,
122-
0.00236,
123-
0.14179,
124-
0.16979,
125-
0.84763,
126-
0.00542,
127-
0.00136,
128-
0.32563
129-
),
75+
c(0, 0.00236, 0.14179, 0.16979, 0.84763, 0.00542, 0.00136, 0.32563),
13076
tolerance = 1e-3
13177
)
13278
expect_equal(
13379
mp2$CI_low,
134-
c(
135-
24.57489,
136-
4.93385,
137-
-1.91805,
138-
-0.05477,
139-
-2.96368,
140-
-4.41987,
141-
-0.16904,
142-
-0.05117
143-
),
80+
c(24.57489, 4.93385, -1.91805, -0.05477, -2.96368, -4.41987, -0.16904, -0.05117),
14481
tolerance = 1e-3
14582
)
14683
})
14784

14885
test_that("model_parameters, ci_method kenward", {
14986
expect_equal(
15087
mp3$SE,
151-
c(
152-
2.97608,
153-
6.10454,
154-
3.98754,
155-
0.02032,
156-
1.60327,
157-
0.91599,
158-
0.05509,
159-
0.01962
160-
),
88+
c(2.97608, 6.10454, 3.98754, 0.02032, 1.60327, 0.91599, 0.05509, 0.01962),
16189
tolerance = 1e-3
16290
)
16391
expect_equal(
16492
mp3$df,
165-
c(
166-
19.39553,
167-
5.27602,
168-
23.57086,
169-
8.97297,
170-
22.7421,
171-
23.76299,
172-
2.72622,
173-
22.82714
174-
),
93+
c(19.39553, 5.27602, 23.57086, 8.97297, 22.7421, 23.76299, 2.72622, 22.82714),
17594
tolerance = 1e-3
17695
)
17796
expect_equal(
17897
mp3$p,
179-
c(
180-
0,
181-
0.09176,
182-
0.19257,
183-
0.30147,
184-
0.84942,
185-
0.00828,
186-
0.15478,
187-
0.40248
188-
),
98+
c(0, 0.09176, 0.19257, 0.30147, 0.84942, 0.00828, 0.15478, 0.40248),
18999
tolerance = 1e-3
190100
)
191101
expect_equal(
192102
mp3$CI_low,
193-
c(
194-
24.08091,
195-
-2.887,
196-
-2.88887,
197-
-0.06828,
198-
-3.01082,
199-
-4.5299,
200-
-0.29339,
201-
-0.05735
202-
),
103+
c(24.08091, -2.887, -2.88887, -0.06828, -3.01082, -4.5299, -0.29339, -0.05735),
203104
tolerance = 1e-3
204105
)
205106
})
206107

207108
test_that("model_parameters, ci_method wald (t)", {
208109
expect_equal(
209110
mp4$SE,
210-
c(
211-
2.77457,
212-
3.69574,
213-
3.521,
214-
0.01574,
215-
1.58514,
216-
0.86316,
217-
0.02973,
218-
0.01668
219-
),
111+
c(2.77457, 3.69574, 3.521, 0.01574, 1.58514, 0.86316, 0.02973, 0.01668),
220112
tolerance = 1e-3
221113
)
222114
expect_equal(mp4$df, c(22, 22, 22, 22, 22, 22, 22, 22), tolerance = 1e-3)
223115
expect_equal(
224116
mp4$p,
225-
c(
226-
0,
227-
0.00258,
228-
0.14297,
229-
0.17095,
230-
0.84778,
231-
0.00578,
232-
0.00151,
233-
0.32653
234-
),
117+
c(0, 0.00258, 0.14297, 0.17095, 0.84778, 0.00578, 0.00151, 0.32653),
235118
tolerance = 1e-3
236119
)
237120
expect_equal(
238121
mp4$CI_low,
239-
c(
240-
24.54722,
241-
4.89698,
242-
-1.95317,
243-
-0.05493,
244-
-2.97949,
245-
-4.42848,
246-
-0.16933,
247-
-0.05133
248-
),
122+
c(24.54722, 4.89698, -1.95317, -0.05493, -2.97949, -4.42848, -0.16933, -0.05133),
249123
tolerance = 1e-3
250124
)
251125
})
@@ -268,8 +142,10 @@ test_that("model_parameters, satterthwaite Conf Int-1", {
268142

269143
test_that("model_parameters, satterthwaite Conf Int-2", {
270144
coef.table <- as.data.frame(summary(model2)$coefficients)
271-
coef.table$CI_low <- coef.table$Estimate - (coef.table$"Std. Error" * qt(0.975, df = coef.table$df))
272-
coef.table$CI_high <- coef.table$Estimate + (coef.table$"Std. Error" * qt(0.975, df = coef.table$df))
145+
coef.table$CI_low <- coef.table$Estimate -
146+
(coef.table$"Std. Error" * qt(0.975, df = coef.table$df))
147+
coef.table$CI_high <- coef.table$Estimate +
148+
(coef.table$"Std. Error" * qt(0.975, df = coef.table$df))
273149

274150
expect_equal(mp2$CI_low, coef.table$CI_low, tolerance = 1e-4)
275151
expect_equal(mp2$CI_high, coef.table$CI_high, tolerance = 1e-4)

0 commit comments

Comments
 (0)