Skip to content
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
2 changes: 1 addition & 1 deletion 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.29.3.2
Version: 0.29.3.3
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

## Bug fixes

* `model_parameters(..., effects = "grouplevel")` now formats categorical
random-slope labels consistently across all grouping levels.

* `standard_error()` and hence `model_parameters()` returned wrong (recycled)
standard errors for models of class `glmmTMB` fitted with the new `ordinal()`
family, because the thresholds are not part of the summary coefficient table.
Expand Down
4 changes: 3 additions & 1 deletion R/format_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ format_parameters.parameters_model <- function(model, ...) {
# missing labels return original parameter name (e.g., variance components in mixed models)
out <- stats::setNames(params$Parameter, params$Parameter)
pretty_labels <- pretty_labels[names(pretty_labels) %in% params$Parameter]
out[match(names(pretty_labels), params$Parameter)] <- pretty_labels
label_idx <- match(params$Parameter, names(pretty_labels))
has_label <- !is.na(label_idx)
out[has_label] <- pretty_labels[label_idx[has_label]]

out
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-glmmTMB.R
Original file line number Diff line number Diff line change
Expand Up @@ -853,14 +853,14 @@
`(Intercept)` = "(Intercept)",
child = "child",
camper1 = "camper [1]",
`(Intercept)` = "(Intercept)",

Check warning on line 856 in tests/testthat/test-glmmTMB.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-glmmTMB.R,line=856,col=9,[duplicate_argument_linter] Avoid duplicate arguments in function calls.
child = "child",

Check warning on line 857 in tests/testthat/test-glmmTMB.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-glmmTMB.R,line=857,col=9,[duplicate_argument_linter] Avoid duplicate arguments in function calls.
camper1 = "camper1", # nolint
camper1 = "camper [1]",

Check warning on line 858 in tests/testthat/test-glmmTMB.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-glmmTMB.R,line=858,col=9,[duplicate_argument_linter] Avoid duplicate arguments in function calls.
`SD (Intercept)` = "SD (Intercept)",
`SD (xb)` = "SD (xb)",
`Cor (Intercept~xb)` = "Cor (Intercept~xb)",
`SD (Intercept)` = "SD (Intercept)",

Check warning on line 862 in tests/testthat/test-glmmTMB.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-glmmTMB.R,line=862,col=9,[duplicate_argument_linter] Avoid duplicate arguments in function calls.
`SD (zg)` = "SD (zg)", # nolint
`SD (zg)` = "SD (zg)",
`Cor (Intercept~zg)` = "Cor (Intercept~zg)"
)
)
Expand Down Expand Up @@ -1098,16 +1098,16 @@
family = glmmTMB::nbinom1()
)
out <- as.data.frame(model_parameters(m, effects = "fixed", component = "all"))
expect_identical(nrow(out), 19L)

Check warning on line 1101 in tests/testthat/test-glmmTMB.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-glmmTMB.R,line=1101,col=5,[expect_shape_linter] expect_shape(x, nrow = n) is better than expect_identical(nrow(x), n)
out <- as.data.frame(model_parameters(m, effects = "random", component = "all"))
expect_identical(nrow(out), 1L)

Check warning on line 1103 in tests/testthat/test-glmmTMB.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-glmmTMB.R,line=1103,col=5,[expect_shape_linter] expect_shape(x, nrow = n) is better than expect_identical(nrow(x), n)
out <- as.data.frame(model_parameters(
m,
effects = "random",
component = "all",
group_level = TRUE
))
expect_identical(nrow(out), 46L)

Check warning on line 1110 in tests/testthat/test-glmmTMB.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-glmmTMB.R,line=1110,col=5,[expect_shape_linter] expect_shape(x, nrow = n) is better than expect_identical(nrow(x), n)
expect_equal(
out$Coefficient,
unlist(glmmTMB::ranef(m)),
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-model_parameters.mixed.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

test_that("model_parameters.mixed", {
params <- model_parameters(m3, keep = "^cyl", effects = "fixed")
expect_identical(dim(params), c(1L, 10L))

Check warning on line 11 in tests/testthat/test-model_parameters.mixed.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-model_parameters.mixed.R,line=11,col=3,[expect_shape_linter] expect_shape(x, dim = d) is better than expect_identical(dim(x), d)
expect_message({
params <- model_parameters(m3, keep = "^abc", effects = "fixed")
})
expect_identical(dim(params), c(3L, 10L))

Check warning on line 15 in tests/testthat/test-model_parameters.mixed.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-model_parameters.mixed.R,line=15,col=3,[expect_shape_linter] expect_shape(x, dim = d) is better than expect_identical(dim(x), d)

params <- model_parameters(m1, ci_method = "normal", effects = "fixed")
expect_identical(c(nrow(params), ncol(params)), c(2L, 10L))
Expand Down Expand Up @@ -116,6 +116,20 @@
expect_equal(params$Coefficient, c(0.1692, 0.0566, -0.2259), tolerance = 1e-2)
})

test_that("model_parameters.mixed-random, grouplevel factor labels", {
dat <- transform(lme4::sleepstudy, treatment = factor(ifelse(Days > 4, "1", "0")))
model <- lme4::lmer(Reaction ~ treatment + (1 + treatment | Subject), data = dat)
params <- model_parameters(model, effects = "grouplevel")
pretty_labels <- attr(params, "pretty_labels")
treatment_labels <- pretty_labels[grepl("^treatment", names(pretty_labels))]

Check warning on line 124 in tests/testthat/test-model_parameters.mixed.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-model_parameters.mixed.R,line=124,col=43,[string_boundary_linter] Use !is.na(x) & startsWith(x, "treatment") to detect a fixed initial substring, or, if missingness is not a concern, just startsWith(x, "treatment"). Doing so is more readable and avoids regular expression overhead.

expect_length(treatment_labels, length(unique(dat$Subject)))
expect_identical(
as.character(treatment_labels),
rep("treatment [1]", length(treatment_labels))
)
})

test_that("model_parameters.mixed-ran_pars", {
params <- model_parameters(m1, effects = "random")
expect_identical(c(nrow(params), ncol(params)), c(2L, 8L))
Expand Down
Loading