Skip to content

Commit 23f3358

Browse files
authored
Add support for "kenward" option (#1175)
* Support `"kenward"` option for glmmTMB * formatting * speed improvement * fix * fix * fix, tests * tests * satterthwaite * news, wordlist * URLs * fix * fix
1 parent 2d04732 commit 23f3358

17 files changed

+367
-619
lines changed

.github/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contributing to parameters
22

3-
This outlines how to propose a change to **parameters**.
3+
This outlines how to propose a change to **parameters**.
44

55
## Fixing typos
66

@@ -9,7 +9,7 @@ Small typos or grammatical errors in documentation may be edited directly using
99
## Filing an issue
1010

1111
The easiest way to propose a change or new feature is to file an issue. If you've found a
12-
bug, you may also create an associated issue. If possible, try to illustrate your proposal or the bug with a minimal [reproducible example](https://www.tidyverse.org/help/#reprex).
12+
bug, you may also create an associated issue. If possible, try to illustrate your proposal or the bug with a minimal reproducible example.
1313

1414
## Pull requests
1515

.github/SUPPORT.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ Start by making a minimal **repr**oducible **ex**ample using the
77
[reprex](http://reprex.tidyverse.org/) package. If you haven't heard of or used
88
reprex before, you're in for a treat! Seriously, reprex will make all of your
99
R-question-asking endeavors easier (which is a pretty insane ROI for the five to
10-
ten minutes it'll take you to learn what it's all about). For additional reprex
11-
pointers, check out the [Get help!](https://www.tidyverse.org/help/) resource
12-
used by the tidyverse team.
10+
ten minutes it'll take you to learn what it's all about).
1311

1412
Armed with your reprex, the next step is to figure out where to ask:
1513

@@ -26,4 +24,4 @@ default, the search will be pre-populated with `is:issue is:open`. You can
2624
(e.g. `is:pr`, `is:closed`) as needed. For example, you'd simply
2725
remove `is:open` to search _all_ issues in the repo, open or closed.
2826

29-
Thanks for your help!
27+
Thanks for your help!

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: parameters
33
Title: Processing of Model Parameters
4-
Version: 0.28.2.7
4+
Version: 0.28.2.8
55
Authors@R:
66
c(person(given = "Daniel",
77
family = "Lüdecke",

NAMESPACE

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ S3method(ci,systemfit)
114114
S3method(ci,varest)
115115
S3method(ci,zerocount)
116116
S3method(ci,zeroinfl)
117+
S3method(ci_kenward,default)
118+
S3method(ci_kenward,glmmTMB)
117119
S3method(cluster_discrimination,cluster_analysis)
118120
S3method(cluster_discrimination,default)
119121
S3method(cluster_performance,dbscan)
@@ -138,7 +140,6 @@ S3method(display,parameters_pca_summary)
138140
S3method(display,parameters_sem)
139141
S3method(display,parameters_simulate)
140142
S3method(display,parameters_standardized)
141-
S3method(dof_satterthwaite,lmerMod)
142143
S3method(equivalence_test,MixMod)
143144
S3method(equivalence_test,estimate_contrasts)
144145
S3method(equivalence_test,estimate_means)
@@ -568,7 +569,6 @@ S3method(p_value,wbm)
568569
S3method(p_value,zcpglm)
569570
S3method(p_value,zerocount)
570571
S3method(p_value,zeroinfl)
571-
S3method(p_value_kenward,lmerMod)
572572
S3method(plot,cluster_analysis)
573573
S3method(plot,cluster_analysis_summary)
574574
S3method(plot,compare_parameters)
@@ -660,6 +660,8 @@ S3method(reduce_parameters,lm)
660660
S3method(reduce_parameters,merMod)
661661
S3method(reshape_loadings,data.frame)
662662
S3method(reshape_loadings,parameters_efa)
663+
S3method(se_kenward,default)
664+
S3method(se_kenward,glmmTMB)
663665
S3method(se_satterthwaite,default)
664666
S3method(select_parameters,lm)
665667
S3method(select_parameters,merMod)

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
* Added support for package *lcmm*.
66

7+
* Added `ci_method` options `"kenward-roger"` and `"satterthwaite"` for models
8+
from package *glmmTMB*. Consequently, `se_kenward()`, `se_satterthwaite()`,
9+
`ci_kenward()`, `ci_satterthwaite()`, `p_value_kenward()` and
10+
`p_value_satterthwaite()` can now be used with `glmmTMB` models.
11+
712
# parameters 0.28.2
813

914
## Bug fixes

R/ci_generic.R

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
# generic function for CI calculation
2-
.ci_generic <- function(model,
3-
ci = 0.95,
4-
method = "wald",
5-
dof = NULL,
6-
effects = "fixed",
7-
component = "all",
8-
vcov = NULL,
9-
vcov_args = NULL,
10-
verbose = TRUE,
11-
...) {
2+
.ci_generic <- function(
3+
model,
4+
ci = 0.95,
5+
method = "wald",
6+
dof = NULL,
7+
effects = "fixed",
8+
component = "all",
9+
vcov = NULL,
10+
vcov_args = NULL,
11+
verbose = TRUE,
12+
...
13+
) {
1214
# check method
1315
if (is.null(method)) {
1416
method <- "wald"
1517
}
1618
method <- tolower(method)
19+
# fmt: skip
1720
method <- insight::validate_argument(
1821
method,
1922
c(
@@ -23,6 +26,7 @@
2326
)
2427

2528
effects <- insight::validate_argument(effects, c("fixed", "random", "all"))
29+
# fmt: skip
2630
component <- insight::validate_argument(
2731
component,
2832
c(
@@ -31,7 +35,8 @@
3135
)
3236
)
3337

34-
if (method == "ml1") { # nolint
38+
if (method == "ml1") {
39+
# nolint
3540
return(ci_ml1(model, ci = ci))
3641
} else if (method == "betwithin") {
3742
return(ci_betwithin(model, ci = ci))

R/ci_kenward.R

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
#' @rdname p_value_kenward
22
#' @export
3-
ci_kenward <- function(model, ci = 0.95) {
4-
.check_REML_fit(model)
3+
ci_kenward <- function(model, ci = 0.95, ...) {
4+
UseMethod("ci_kenward")
5+
}
6+
7+
#' @export
8+
ci_kenward.default <- function(model, ci = 0.95, ...) {
9+
if (!.check_REML_fit(model)) {
10+
model <- stats::update(model, . ~ ., REML = TRUE)
11+
}
12+
513
df_kr <- dof_kenward(model)
614
out <- lapply(ci, function(i) {
715
.ci_dof(
@@ -19,15 +27,43 @@ ci_kenward <- function(model, ci = 0.95) {
1927
out
2028
}
2129

30+
#' @export
31+
ci_kenward.glmmTMB <- function(model, ci = 0.95, ...) {
32+
if (!.check_REML_fit(model)) {
33+
model <- stats::update(model, . ~ ., REML = TRUE)
34+
}
35+
36+
df_kr <- dof_kenward(model)
37+
out <- lapply(ci, function(i) {
38+
.ci_dof(
39+
model = model,
40+
ci = i,
41+
dof = df_kr,
42+
effects = "fixed",
43+
component = "conditional", # for glmmTMB, only conditional
44+
method = "kenward",
45+
se = attr(df_kr, "se", exact = TRUE)
46+
)
47+
})
48+
out <- do.call(rbind, out)
49+
row.names(out) <- NULL
50+
out
51+
}
52+
2253

2354
.ci_kenward_dof <- function(model, ci = 0.95, df_kr) {
55+
if (inherits(model, "glmmTMB")) {
56+
component <- "conditional"
57+
} else {
58+
component <- "all"
59+
}
2460
out <- lapply(ci, function(i) {
2561
.ci_dof(
2662
model = model,
2763
ci = i,
2864
dof = df_kr$df_error,
2965
effects = "fixed",
30-
component = "all",
66+
component = component,
3167
method = "kenward",
3268
se = df_kr$SE
3369
)

R/ci_satterthwaite.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
#' @export
33
ci_satterthwaite <- function(model, ci = 0.95, ...) {
44
df_satter <- dof_satterthwaite(model)
5+
if (inherits(model, "glmmTMB")) {
6+
component <- "conditional"
7+
} else {
8+
component <- "all"
9+
}
510
out <- lapply(ci, function(i) {
611
.ci_dof(
712
model = model,
813
ci = i,
914
dof = df_satter,
1015
effects = "fixed",
11-
component = "all",
16+
component = component,
1217
method = "satterthwaite",
1318
...
1419
)

R/dof.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ dof <- degrees_of_freedom
154154
))
155155
}
156156
return(FALSE)
157-
}
157+
}
158158

159159
if (!info$is_linear && method %in% c("satterthwaite", "kenward", "kr")) {
160160
if (verbose) {

0 commit comments

Comments
 (0)