Skip to content

Commit e29719b

Browse files
committed
fix, add test
1 parent 8136b22 commit e29719b

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

R/estimate_grouplevel.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ estimate_grouplevel <- function(model, type = "random", dispersion = TRUE, test
7575
)
7676

7777
# get cleaned parameter names with additional information
78-
clean_parameters <- attributes(params)$clean_parameters$Group
78+
clean_parameters <- attributes(params)$clean_parameters
7979

8080
## TODO: for now, rstanarm has no random effects on the sigma parameter
8181
## however, if this changes, we need another solution here (and in

tests/testthat/test-estimate_grouplevel.R

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
skip_if(utils::packageVersion("insight") <= "1.1.0")
22
skip_if(utils::packageVersion("parameters") <= "0.24.1")
33

4+
test_that("estimate_grouplevel - errors", {
5+
m <- lm(mpg ~ gear, data = mtcars)
6+
expect_error(estimate_grouplevel(m), regex = "Model must be a mixed")
7+
})
8+
49
test_that("estimate_grouplevel - lme4", {
510
skip_if_not_installed("lme4")
611
set.seed(333)
@@ -83,7 +88,7 @@ test_that("estimate_grouplevel - glmmTMB", {
8388
expect_named(out, c("Group", "Level", "Parameter", "Coefficient"))
8489
})
8590

86-
test_that("estimate_grouplevel - Bayesian", {
91+
test_that("estimate_grouplevel - Bayesian, brms", {
8792
skip_on_cran()
8893
skip_if_not_installed("curl")
8994
skip_if_offline()
@@ -112,3 +117,33 @@ test_that("estimate_grouplevel - Bayesian", {
112117
expect_identical(dim(out), c(12L, 9L))
113118
expect_named(out, c("Component", "Group", "Level", "Parameter", "Median", "MAD", "CI", "CI_low", "CI_high"))
114119
})
120+
121+
test_that("estimate_grouplevel - Bayesian, rstanarm", {
122+
skip_on_cran()
123+
skip_if_not_installed("curl")
124+
skip_if_offline()
125+
skip_if_not_installed("httr2")
126+
skip_if_not_installed("rstanarm")
127+
128+
m <- insight::download_model("brms_mixed_10")
129+
skip_if(is.null(m))
130+
131+
out <- estimate_grouplevel(m)
132+
expect_identical(dim(out), c(6L, 8L))
133+
expect_named(out, c("Group", "Level", "Parameter", "Median", "MAD", "CI", "CI_low", "CI_high"))
134+
135+
out <- estimate_grouplevel(m, type = "total", dispersion = FALSE)
136+
expect_identical(dim(out), c(6L, 7L))
137+
expect_named(out, c("Group", "Level", "Parameter", "Median", "CI", "CI_low", "CI_high"))
138+
139+
m <- insight::download_model("brms_sigma_3")
140+
skip_if(is.null(m))
141+
142+
out <- estimate_grouplevel(m)
143+
expect_identical(dim(out), c(12L, 9L))
144+
expect_named(out, c("Component", "Group", "Level", "Parameter", "Median", "MAD", "CI", "CI_low", "CI_high"))
145+
146+
out <- estimate_grouplevel(m, type = "total")
147+
expect_identical(dim(out), c(12L, 9L))
148+
expect_named(out, c("Component", "Group", "Level", "Parameter", "Median", "MAD", "CI", "CI_low", "CI_high"))
149+
})

0 commit comments

Comments
 (0)