| compare | R Documentation |
Compares two Bayesian models by calculating the proportion of posterior samples where the comparison model's parameters exceed (or fall below) the reference model's summary statistic. This is useful for model comparison and assessing incremental variance explained (e.g., R-squared differences).
compare(
model0,
model,
use = "mean",
greaterThan = TRUE,
suffixes = c("R2: Coefficients", "R2: Level-2 Random Intercepts",
"R2: Level-2 Random Slopes", "R2: Level-3 Random Slopes",
"R2: Level-3 Random Intercepts", "R2: Residual Variation",
"R2: Level-1 Residual Variation")
)
model0 |
A |
model |
A |
use |
Summary statistic to use as the cutpoint from
|
greaterThan |
Logical. If |
suffixes |
Character vector of parameter name suffixes to compare. Defaults to all R-squared values (coefficients, random effects, residual variation). |
The comparison works by:
Computing a summary statistic (e.g., mean) from model0's posterior samples
Calculating what proportion of model's posterior samples exceed this value
Reporting this proportion for each parameter matching the specified suffixes
A blimp_cp object containing a matrix of comparison proportions.
Due to R restrictions, lists of functions will not give useful printed names.
# Generate data
mydata <- rblimp_sim(
c(
'x1 ~ normal(0, 1)',
'x2 ~ normal(0, 1)',
'y ~ normal(10 + 0.5*x1 + 0.3*x2, 1)'
),
n = 200,
seed = 123
)
# Fit baseline model (x1 only)
model0 <- rblimp(
'y ~ x1',
mydata,
seed = 123,
burn = 1000,
iter = 1000
)
# Fit comparison model (x1 + x2)
model1 <- rblimp(
'y ~ x1 x2',
mydata,
seed = 123,
burn = 1000,
iter = 1000
)
# Compare models - proportion of model1 R-squared > mean(model0 R-squared)
compare(model0, model1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.