Skip to content

Commit

Permalink
fix labelling
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 3, 2024
1 parent 13826c5 commit 6b57d38
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

* `get_dispersion()` is now an exported function.

## Bug fix

* `clean_parameters()` now uses the correct labels for the random effects
variances (`"SD/Cor"` has changed to `"Var/Cov"`).

# insight 0.20.5

## General
Expand Down
6 changes: 3 additions & 3 deletions R/clean_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ clean_parameters.mlm <- function(x, ...) {
if (any(rand_cor)) {
out$Cleaned_Parameter[which(cor_sd)[rand_cor]] <- paste0(parm1[rand_cor], " ~ ", parm2[rand_cor])
}
out$Group[cor_sd] <- paste("SD/Cor:", gsub("^Sigma\\[(.*):(.*),(.*)\\]", "\\1", out$Parameter[cor_sd], perl = TRUE))
out$Group[cor_sd] <- paste("Var/Cov:", gsub("^Sigma\\[(.*):(.*),(.*)\\]", "\\1", out$Parameter[cor_sd], perl = TRUE))

Check warning on line 655 in R/clean_parameters.R

View workflow job for this annotation

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

file=R/clean_parameters.R,line=655,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 121 characters.

Check warning on line 655 in R/clean_parameters.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/clean_parameters.R,line=655,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 121 characters.
}


Expand All @@ -669,9 +669,9 @@ clean_parameters.mlm <- function(x, ...) {
out$Group[rand_effects] <- r_grps
out$Level[rand_effects] <- r_levels
# fix labelling of SD and correlation component
sd_cor <- grepl("SD/Cor:", out$Group, fixed = TRUE)
sd_cor <- grepl("Var/Cov:", out$Group, fixed = TRUE)
if (any(sd_cor)) {
out$Group[sd_cor] <- gsub("SD/Cor: (.*)", "\\1", out$Group[sd_cor])
out$Group[sd_cor] <- gsub("Var/Cov: (.*)", "\\1", out$Group[sd_cor])
}
} else {
re_grp_level <- gsub("b\\[(.*) (.*):(.*)\\]", "\\2", out$Cleaned_Parameter[rand_effects])
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-clean_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,30 @@ test_that("clean_parameters blavaan", {
out <- clean_parameters(bfit)
expect_true(inherits(out, "clean_parameters")) # nolint
})


test_that("clean_parameters stanrag", {
skip_on_cran()
skip_if_not_installed("rstanarm")
skip_if_not_installed("lme4")

data(sleepstudy, package = "lme4")
m <- insight::download_model("stanreg_merMod_6")
out <- clean_parameters(m)

expect_identical(
out$Group,
c(
"", "", "Intercept: Subject", "Days: Subject", "Intercept: Subject",
"Days: Subject", "Intercept: Subject", "Days: Subject", "Intercept: Subject",
"Days: Subject", "Intercept: Subject", "Days: Subject", "Intercept: Subject",
"Days: Subject", "Intercept: Subject", "Days: Subject", "Intercept: Subject",
"Days: Subject", "Intercept: Subject", "Days: Subject", "Intercept: Subject",
"Days: Subject", "Intercept: Subject", "Days: Subject", "Intercept: Subject",
"Days: Subject", "Intercept: Subject", "Days: Subject", "Intercept: Subject",
"Days: Subject", "Intercept: Subject", "Days: Subject", "Intercept: Subject",
"Days: Subject", "Intercept: Subject", "Days: Subject", "Intercept: Subject",
"Days: Subject", "Var/Cov: Subject", "Var/Cov: Subject", "Var/Cov: Subject", ""
)
)
})

0 comments on commit 6b57d38

Please sign in to comment.