R/post_processing.R
mixmustr_bayes_R2.Rd
Compute a Bayesian version of R-squared for MixMustR mixture models
mixmustr_bayes_R2(modfit, summary = TRUE, ...)
A fitted Stan model object containing posterior draws.
Typically produced by function run_mixmustr_models
.
Should summary statistics be returned
instead of the raw values? Default is TRUE
.
Additional unused arguments.
If summary = TRUE
, a (J + 1) x 4 matrix is returned
(J + 1 = number of sampled + 1 unsampled source). Columns contain source
names and summary statistics (mean +/- 95% HDI) of the Bayesian R-squared
values. If summary = FALSE
, the posterior draws of the Bayesian
R-squared values are returned in an S x (J + 1) matrix (S is the number of
draws).
For an introduction to the approach, see Gelman et al. (2019) and https://github.com/jgabry/bayes_R2/.
Andrew Gelman, Ben Goodrich, Jonah Gabry & Aki Vehtari. (2019).
R-squared for Bayesian regression models, The American Statistician,
73(3):307-309. 10.1080/00031305.2018.1549100
if (FALSE) { # \dontrun{
library(MixMustR)
# mixmustr_models[6, ] runs quickest
model_fits <- run_mixmustr_models(
mixmustr_models[6, ], synthetic_df_convergent, tracer_parameters,
sigma_ln_rho = 0.1, iter = 1e4, warmup = 5e3, chains = 4, cores = 4
)
# Now compute R2, using data stream 2 as point of comparison
mixmustr_bayes_R2(
model_fits[[1]]$model, data_streams_list = synthetic_df_convergent,
target = "df_stream_2", order_ref = tracer_parameters$mus$source
)
} # }