-
-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Labels
Bug 🐛Something isn't workingSomething isn't working
Description
Hi
The bayestestR::bayesfactor_parameters()
applied to the brms linear model respects effects
, component
and parameters
options that allows for computing bayes_factor
for a single parameter.
However, for nonlinear model, these options are ignored, and results are computed for all parameters including the group level effects (in a sense option 'full').
This difference could be resulting from the insight::find_parameters()
Below, I first show the results for the linear fit and then the nonlinear
Linear model
library(brms)
library(bayestestR)
contrasts(sleep$group) <- contr.equalprior_pairs # see vingette
my_custom_priors <-
set_prior("student_t(3, 0, 1)", class = "b") +
set_prior("student_t(3, 0, 1)", class = "sd", group = "ID")
brms_model <- suppressWarnings(brm(extra ~ group + (1 | ID),
data = sleep,
prior = my_custom_priors,
refresh = 0
))
bayesfactor_parameters(brms_model,
effects = "fixed",
parameters = "b_Intercept",
verbose = T)
#> Sampling priors, please wait...
#> Warning: Bayes factors might not be precise.
#> For precise Bayes factors, sampling at least 40,000 posterior samples is
#> recommended.
#> Bayes Factor (Savage-Dickey density ratio)
#>
#> Parameter | BF
#> ------------------
#> (Intercept) | 5.72
#>
#> * Evidence Against The Null: 0
Created on 2025-05-26 with [reprex v2.1.1](https://reprex.tidyverse.org/)
Nonlinear model
library(brms)
library(bayestestR)
brms_nl <- fit_loss <- brm(
bf(cum ~ ult * (1 - exp(-(dev/theta)^omega)),
ult ~ 1 + (1|AY), omega ~ 1, theta ~ 1,
nl = TRUE),
data = brms::loss, family = gaussian(),
prior = c(
prior(normal(5000, 1000), nlpar = "ult"),
prior(normal(1, 2), nlpar = "omega"),
prior(normal(45, 10), nlpar = "theta")
),
control = list(adapt_delta = 0.9),
refresh = 0
)
bayestestR::bayesfactor_parameters(brms_nl,
effects = "fixed",
parameters = "b_ult_Intercept",
verbose = T)
#> Sampling priors, please wait...
#> Warning: Bayes factors might not be precise.
#> For precise Bayes factors, sampling at least 40,000 posterior samples is
#> recommended.
#> Bayes Factor (Savage-Dickey density ratio) (sigma)
#>
#> Parameter | BF
#> --------------------
#> sigma | 2.77e+10
#>
#> # Fixed effects (ult)
#>
#> Parameter | BF
#> ----------------------
#> (Intercept) | 8.59e+11
#>
#> # Fixed effects (omega)
#>
#> Parameter | BF
#> ----------------------
#> (Intercept) | 1.01e+27
#>
#> # Fixed effects (theta)
#>
#> Parameter | BF
#> ----------------------
#> (Intercept) | 5.17e+30
#>
#> # Random effects (ult) (Intercept: AY)
#>
#> Parameter | BF
#> ------------------
#> AY.1991 | 983.54
#> AY.1992 | 0.516
#> AY.1993 | 0.509
#> AY.1994 | 0.781
#> AY.1995 | 2.04
#> AY.1996 | 0.464
#> AY.1997 | 1.82
#> AY.1998 | 25.77
#> AY.1999 | 1.20
#> AY.2000 | 1.05
#>
#> # Random effects (ult) (SD/Cor: AY)
#>
#> Parameter | BF
#> ----------------------
#> (Intercept) | 8.57e+05
#>
#> * Evidence Against The Null: 0
Created on 2025-05-26 with [reprex v2.1.1](https://reprex.tidyverse.org/)
Metadata
Metadata
Assignees
Labels
Bug 🐛Something isn't workingSomething isn't working