Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address changes in recent glmmTMB #1019

Merged
merged 5 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.22.2.13
Version: 0.22.2.14
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -136,7 +136,7 @@ Suggests:
ggeffects (>= 1.3.2),
ggplot2,
GLMMadaptive,
glmmTMB,
glmmTMB (>= 1.1.10),
glmtoolbox,
GPArotation,
gt,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

* Revision / enhancement of some documentation.

* Updated *glmmTMB* methods to work with the latest version of the package.

# parameters 0.22.2

## New supported models
Expand Down
13 changes: 10 additions & 3 deletions R/extract_random_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
out$CI_high <- out$Coefficient + fac * out$SE
ci_cols <- c("CI_low", "CI_high")
} else {
ci_cols <- c()
ci_cols <- NULL
for (i in ci) {
fac <- stats::qnorm((1 + i) / 2)
ci_low <- paste0("CI_low_", i)
Expand Down Expand Up @@ -66,7 +66,10 @@
out <- switch(component,
zi = ,
zero_inflated = out[out$Component == "zi", ],
cond = ,
conditional = out[out$Component == "cond", ],
disp = ,
dispersion = out[out$Component == "disp", ],
out
)

Expand All @@ -79,14 +82,15 @@
# rename
out$Component[out$Component == "zi"] <- "zero_inflated"
out$Component[out$Component == "cond"] <- "conditional"
out$Component[out$Component == "disp"] <- "dispersion"

if (length(ci) == 1) {
fac <- stats::qnorm((1 + ci) / 2)
out$CI_low <- out$Coefficient - fac * out$SE
out$CI_high <- out$Coefficient + fac * out$SE
ci_cols <- c("CI_low", "CI_high")
} else {
ci_cols <- c()
ci_cols <- NULL
for (i in ci) {
fac <- stats::qnorm((1 + i) / 2)
ci_low <- paste0("CI_low_", i)
Expand All @@ -104,7 +108,10 @@
out$df_error <- NA
out$p <- NA

out <- out[c("Parameter", "Level", "Coefficient", "SE", ci_cols, stat_column, "df_error", "p", "Component", "Effects", "Group")]
out <- out[c(
"Parameter", "Level", "Coefficient", "SE", ci_cols, stat_column,
"df_error", "p", "Component", "Effects", "Group"
)]

if (effects == "random") {
out[c(stat_column, "df_error", "p")] <- NULL
Expand Down
6 changes: 3 additions & 3 deletions R/methods_coxme.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#' @export
standard_error.coxme <- function(model, ...) {
beta <- model$coefficients
beta_coef <- model$coefficients

if (length(beta) > 0) {
if (length(beta_coef) > 0) {
.data_frame(
Parameter = .remove_backticks_from_string(names(beta)),
Parameter = .remove_backticks_from_string(names(beta_coef)),
SE = sqrt(diag(stats::vcov(model)))
)
}
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-glmmTMB.R
Original file line number Diff line number Diff line change
Expand Up @@ -683,5 +683,23 @@ withr::with_options(
mp <- model_parameters(m1, effects = "all", verbose = FALSE)
expect_snapshot(mp)
})

test_that("print-model_parameters, random dispersion", {
data(Salamanders, package = "glmmTMB")
m <- glmmTMB::glmmTMB(
count ~ spp + cover + mined + (1 | site),
ziformula = ~ spp + mined,
dispformula = ~ DOY + (1 | site),
data = Salamanders,
family = glmmTMB::nbinom1()
)
out <- as.data.frame(model_parameters(m, effects = "fixed", component = "all"))
expect_identical(nrow(out), 19L)
out <- as.data.frame(model_parameters(m, effects = "random", component = "all"))
expect_identical(nrow(out), 1L)
out <- as.data.frame(model_parameters(m, effects = "random", component = "all", group_level = TRUE))
expect_identical(nrow(out), 46L)
expect_equal(out$Coefficient, unlist(glmmTMB::ranef(m)), ignore_attr = TRUE, tolerance = 1e-4)
})
}
)
10 changes: 7 additions & 3 deletions tests/testthat/test-model_parameters.anova.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ test_that("linear hypothesis tests", {
expect_equal(p1, p3, ignore_attr = TRUE)
expect_equal(p1, p4, ignore_attr = TRUE)
expect_identical(nrow(p1), 2L)
expect_identical(p1$Parameter, c("(Intercept) = 0", "repwt = 1"))
## FIXME: this has changed since {car} 3.1.3
# expect_identical(p1$Parameter, c("(Intercept) = 0", "repwt = 1"))
expect_identical(p1$Parameter, c("1", "2"))

mod.duncan <- lm(prestige ~ income + education, data = Duncan)
p <- parameters(car::linearHypothesis(mod.duncan, "1*income - 1*education + 1 = 1"))
expect_identical(nrow(p), 1L)
expect_identical(p$Parameter, "income - education = 0")
expect_identical(nrow(p), 2L)
## FIXME: this has changed since {car} 3.1.3
# expect_identical(p$Parameter, "income - education = 0")
expect_identical(p1$Parameter, c("1", "2"))
})

test_that("print-model_parameters", {
Expand Down
Loading