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

brms: wrong parameters info #1059

Merged
merged 2 commits into from
Jan 7, 2025
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.24.0.6
Version: 0.24.0.7
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 @@ -5,6 +5,9 @@
* `model_parameters()` now gives informative error messages for more model
classes than before when the function fails to extract model parameters.

* Improved information for credible intervals and sampling method from output
of `model_parameters()` for Bayesian models.

## Bug fixes

* Fixed issue when printing `model_parameters()` with models from `mgcv::gam()`.
Expand Down
3 changes: 3 additions & 0 deletions R/extract_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


#' @keywords internal
.extract_parameters_generic <- function(model,

Check warning on line 5 in R/extract_parameters.R

View workflow job for this annotation

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

file=R/extract_parameters.R,line=5,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 67 to at most 40.
ci,
component,
merge_by = c("Parameter", "Component"),
Expand Down Expand Up @@ -839,6 +839,9 @@
}

rownames(parameters) <- NULL
# indicate it's a Bayesian model
attr(parameters, "is_bayesian") <- TRUE

parameters
}

Expand Down
3 changes: 3 additions & 0 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @inheritParams print.parameters_model
#' @rdname print.parameters_model
#' @export
format.parameters_model <- function(x,

Check warning on line 6 in R/format.R

View workflow job for this annotation

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

file=R/format.R,line=6,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 71 to at most 40.
pretty_names = TRUE,
split_components = TRUE,
select = NULL,
Expand Down Expand Up @@ -240,7 +240,7 @@
#' @rdname print.compare_parameters
#' @inheritParams print.parameters_model
#' @export
format.compare_parameters <- function(x,

Check warning on line 243 in R/format.R

View workflow job for this annotation

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

file=R/format.R,line=243,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 43 to at most 40.
split_components = TRUE,
select = NULL,
digits = 2,
Expand Down Expand Up @@ -741,12 +741,13 @@


# footer: type of uncertainty interval
.print_footer_cimethod <- function(x) {

Check warning on line 744 in R/format.R

View workflow job for this annotation

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

file=R/format.R,line=744,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 46 to at most 40.
if (isTRUE(getOption("parameters_cimethod", TRUE))) {
# get attributes
ci_method <- .additional_arguments(x, "ci_method", NULL)
test_statistic <- .additional_arguments(x, "test_statistic", NULL)
bootstrap <- .additional_arguments(x, "bootstrap", FALSE)
is_bayesian <- .additional_arguments(x, "is_bayesian", FALSE)
simulated <- .additional_arguments(x, "simulated", FALSE)
residual_df <- .additional_arguments(x, "residual_df", NULL)
random_variances <- .additional_arguments(x, "ran_pars", FALSE)
Expand Down Expand Up @@ -825,6 +826,8 @@
# bootstrapped intervals
if (isTRUE(bootstrap)) {
msg <- paste0("\nUncertainty intervals (", string_tailed, ") are ", string_method, "intervals.")
} else if (isTRUE(is_bayesian)) {
msg <- paste0("\nUncertainty intervals (", string_tailed, ") computed using a ", string_method, "distribution ", string_approx, "approximation.") # nolint
} else {
msg <- paste0("\nUncertainty intervals (", string_tailed, ") and p-values (two-tailed) computed using a ", string_method, "distribution ", string_approx, "approximation.") # nolint
}
Expand Down
2 changes: 1 addition & 1 deletion R/p_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#' null hypothesis is correct (Wikipedia)._
#'
#' However, this definition or interpretation is inadequate because it only
#' referes to the test hypothesis (often the null hypothesis), which is only
#' refers to the test hypothesis (often the null hypothesis), which is only
#' one component of the entire model that is being tested. Thus,
#' _Greenland et al. 2022_ suggest an "unconditional" interpretation.
#'
Expand All @@ -77,7 +77,7 @@
#' A non-significant p-value could occur because the test hypothesis is false,
#' but could also be the result of any of the model assumptions being incorrect.
#'
#' \if{html}{\cr \figure{unconditional_interpretation.png}{options: alt="Conditional versus unconditional interpretations of P-values"} \cr}

Check warning on line 80 in R/p_function.R

View workflow job for this annotation

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

file=R/p_function.R,line=80,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 140 characters.
#'
#' "Emphasizing unconditional interpretations helps avoid overconfident and
#' misleading inferences in light of uncertainties about the assumptions used
Expand Down
2 changes: 1 addition & 1 deletion man/p_function.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/testthat/_snaps/brms.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
var_binom1:groupsb | 0.53 | [-1.70, 2.69] | 69.25% | 1.000 | 2699.00
Message

Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a MCMC distribution approximation.
Uncertainty intervals (equal-tailed) computed using a MCMC distribution
approximation.

The model has a log- or logit-link. Consider using `exponentiate =
TRUE` to interpret coefficients as ratios.
Expand All @@ -36,6 +36,6 @@
var_binom1:groupsb | 1.69 | [0.18, 14.80] | 69.25% | 1.000 | 2699.00
Message

Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a MCMC distribution approximation.
Uncertainty intervals (equal-tailed) computed using a MCMC distribution
approximation.

74 changes: 60 additions & 14 deletions tests/testthat/_snaps/printing-stan.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
sigma | 2.67 | [2.06, 3.51] | 100% | 1.000 | 2390.00
Message

Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a MCMC distribution approximation.
Uncertainty intervals (equal-tailed) computed using a MCMC distribution
approximation.

---

Expand Down Expand Up @@ -49,8 +49,8 @@
Cor (Intercept~wt: gear) | -0.25 | [-0.99, 0.83] | 62.48% | 1.106 | 36.00
Message

Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a MCMC distribution approximation.
Uncertainty intervals (equal-tailed) computed using a MCMC distribution
approximation.

---

Expand Down Expand Up @@ -79,8 +79,8 @@
Cor (Intercept~Days: Subject) | 0.09 | [-0.47, 0.67] | 60.42% | 1.003 | 899.00
Message

Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a MCMC distribution approximation.
Uncertainty intervals (equal-tailed) computed using a MCMC distribution
approximation.

---

Expand Down Expand Up @@ -109,8 +109,8 @@
SD (Intercept: Subject) | 38.51 | [26.89, 55.98] | 100% | 1.003 | 1254.00
Message

Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a MCMC distribution approximation.
Uncertainty intervals (equal-tailed) computed using a MCMC distribution
approximation.

---

Expand All @@ -137,8 +137,8 @@
SD (Intercept: Species) | 1.68 | [0.64, 3.64] | 100% | 1.003 | 796.00
Message

Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a MCMC distribution approximation.
Uncertainty intervals (equal-tailed) computed using a MCMC distribution
approximation.

---

Expand Down Expand Up @@ -168,8 +168,8 @@
Cor (Intercept~wt: gear) | -0.38 | [-0.99, 0.82] | 76.85% | 1.003 | 854.00
Message

Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a MCMC distribution approximation.
Uncertainty intervals (equal-tailed) computed using a MCMC distribution
approximation.

---

Expand Down Expand Up @@ -238,6 +238,52 @@
mpg | -1.80 | [ -3.20, -0.90] | 100% | 1.002 | 1021.00
Message

Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a MCMC distribution approximation.
Uncertainty intervals (equal-tailed) computed using a MCMC distribution
approximation.

# print-information

Code
out
Output
# Fixed Effects

Parameter | Median | 95% CI | pd | Rhat | ESS
----------------------------------------------------------------
(Intercept) | 39.68 | [36.12, 43.27] | 100% | 1.000 | 5242.00
wt | -3.20 | [-4.79, -1.65] | 99.95% | 1.000 | 2071.00
cyl | -1.49 | [-2.36, -0.64] | 99.95% | 1.000 | 1951.00

# Sigma

Parameter | Median | 95% CI | pd | Rhat | ESS
----------------------------------------------------------
sigma | 2.63 | [2.06, 3.51] | 100% | 1.000 | 2390.00
Message

Uncertainty intervals (equal-tailed) computed using a MCMC distribution
approximation.

---

Code
out
Output
# Fixed Effects

Parameter | Median | 95% CI | pd | Rhat | ESS
----------------------------------------------------------------
(Intercept) | 39.68 | [36.27, 43.34] | 100% | 1.000 | 5242.00
wt | -3.20 | [-4.70, -1.57] | 99.95% | 1.000 | 2071.00
cyl | -1.49 | [-2.38, -0.68] | 99.95% | 1.000 | 1951.00

# Sigma

Parameter | Median | 95% CI | pd | Rhat | ESS
----------------------------------------------------------
sigma | 2.63 | [1.99, 3.39] | 100% | 1.000 | 2390.00
Message

Uncertainty intervals (highest-density) computed using a MCMC
distribution approximation.

13 changes: 13 additions & 0 deletions tests/testthat/test-printing-stan.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,18 @@ withr::with_options(
mp9 <- model_parameters(m9, effects = "all", component = "all", centrality = "mean")
expect_snapshot(mp9)
})

test_that("print-information", {
skip_if_offline()
skip_if_not_installed("httr2")

m <- insight::download_model("brms_1")
out <- model_parameters(m)
expect_snapshot(out)
out <- model_parameters(m, ci_method = "HDI")
expect_snapshot(out)
m <- insight::download_model("stanreg_glm_1")
out <- model_parameters(m)
})
}
)
Loading