library(performance)
-if (require("rstanarm") && require("rstantools")) {
- model <- suppressWarnings(stan_glm(
- mpg ~ wt + cyl,
- data = mtcars,
- chains = 1,
- iter = 500,
- refresh = 0,
- show_messages = FALSE
- ))
- r2_bayes(model)
+# \donttest{
+model <- suppressWarnings(rstanarm::stan_glm(
+ mpg ~ wt + cyl,
+ data = mtcars,
+ chains = 1,
+ iter = 500,
+ refresh = 0,
+ show_messages = FALSE
+))
+r2_bayes(model)
+#> # Bayesian R2 with Compatibility Interval
+#>
+#> Conditional R2: 0.811 (95% CI [0.681, 0.884])
- model <- suppressWarnings(stan_lmer(
- Petal.Length ~ Petal.Width + (1 | Species),
- data = iris,
- chains = 1,
- iter = 500,
- refresh = 0
- ))
- r2_bayes(model)
-}
+model <- suppressWarnings(rstanarm::stan_lmer(
+ Petal.Length ~ Petal.Width + (1 | Species),
+ data = iris,
+ chains = 1,
+ iter = 500,
+ refresh = 0
+))
+r2_bayes(model)
#> # Bayesian R2 with Compatibility Interval
#>
#> Conditional R2: 0.953 (95% CI [0.942, 0.966])
#> Marginal R2: 0.824 (95% CI [0.737, 0.899])
+# }
-if (require("BayesFactor")) {
- BFM <- generalTestBF(mpg ~ qsec + gear, data = mtcars, progress = FALSE)
- FM <- lmBF(mpg ~ qsec + gear, data = mtcars)
+BFM <- BayesFactor::generalTestBF(mpg ~ qsec + gear, data = mtcars, progress = FALSE)
+FM <- BayesFactor::lmBF(mpg ~ qsec + gear, data = mtcars)
- r2_bayes(FM)
- r2_bayes(BFM[3])
- r2_bayes(BFM, average = TRUE) # across all models
+r2_bayes(FM)
+#> # Bayesian R2 with Compatibility Interval
+#>
+#> Conditional R2: 0.463 (95% CI [0.222, 0.627])
+r2_bayes(BFM[3])
+#> # Bayesian R2 with Compatibility Interval
+#>
+#> Conditional R2: 0.465 (95% CI [0.210, 0.625])
+r2_bayes(BFM, average = TRUE) # across all models
+#> # Bayesian R2 with Compatibility Interval
+#>
+#> Conditional R2: 0.460 (95% CI [0.208, 0.632])
- # with random effects:
- mtcars$gear <- factor(mtcars$gear)
- model <- lmBF(
- mpg ~ hp + cyl + gear + gear:wt,
- mtcars,
- progress = FALSE,
- whichRandom = c("gear", "gear:wt")
- )
+# with random effects:
+mtcars$gear <- factor(mtcars$gear)
+model <- BayesFactor::lmBF(
+ mpg ~ hp + cyl + gear + gear:wt,
+ mtcars,
+ progress = FALSE,
+ whichRandom = c("gear", "gear:wt")
+)
- r2_bayes(model)
-}
+r2_bayes(model)
#> # Bayesian R2 with Compatibility Interval
#>
#> Conditional R2: 0.367 (95% CI [0.260, 0.633])
#> Marginal R2: 0.209 (95% CI [2.871e-05, 0.500])
# \donttest{
-if (require("brms")) {
- model <- suppressWarnings(brms::brm(
- mpg ~ wt + cyl,
- data = mtcars,
- silent = 2,
- refresh = 0
- ))
- r2_bayes(model)
+model <- suppressWarnings(brms::brm(
+ mpg ~ wt + cyl,
+ data = mtcars,
+ silent = 2,
+ refresh = 0
+))
+#> Error in .fun(model_code = .x1) :
+#> Boost not found; call install.packages('BH')
+#> Error in .fun(model_code = .x1): Boost not found; call install.packages('BH')
+r2_bayes(model)
+#> # Bayesian R2 with Compatibility Interval
+#>
+#> Conditional R2: 0.365 (95% CI [0.254, 0.649])
+#> Marginal R2: 0.207 (95% CI [5.278e-05, 0.506])
- model <- suppressWarnings(brms::brm(
- Petal.Length ~ Petal.Width + (1 | Species),
- data = iris,
- silent = 2,
- refresh = 0
- ))
- r2_bayes(model)
-}
-#> Loading required package: brms
-#> Loading 'brms' package (version 2.20.4). Useful instructions
-#> can be found by typing help('brms'). A more detailed introduction
-#> to the package is available through vignette('brms_overview').
-#>
-#> Attaching package: ‘brms’
-#> The following objects are masked from ‘package:rstanarm’:
-#>
-#> dirichlet, exponential, get_y, lasso, ngrps
-#> The following object is masked from ‘package:mclust’:
-#>
-#> me
-#> The following object is masked from ‘package:psych’:
-#>
-#> cs
-#> The following object is masked from ‘package:glmmTMB’:
-#>
-#> lognormal
-#> The following object is masked from ‘package:lme4’:
-#>
-#> ngrps
-#> The following object is masked from ‘package:stats’:
-#>
-#> ar
+model <- suppressWarnings(brms::brm(
+ Petal.Length ~ Petal.Width + (1 | Species),
+ data = iris,
+ silent = 2,
+ refresh = 0
+))
+#> Error in .fun(model_code = .x1) :
+#> Boost not found; call install.packages('BH')
+#> Error in .fun(model_code = .x1): Boost not found; call install.packages('BH')
+r2_bayes(model)
#> # Bayesian R2 with Compatibility Interval
#>
-#> Conditional R2: 0.954 (95% CI [0.951, 0.957])
-#> Marginal R2: 0.386 (95% CI [0.171, 0.590])
+#> Conditional R2: 0.368 (95% CI [0.254, 0.639])
+#> Marginal R2: 0.209 (95% CI [1.543e-04, 0.501])
# }
diff --git a/reference/r2_coxsnell.html b/reference/r2_coxsnell.html
index 2690f2b4d..b22be3d2e 100644
--- a/reference/r2_coxsnell.html
+++ b/reference/r2_coxsnell.html
@@ -10,7 +10,7 @@