Skip to contents

The adapter generic for Bayesian model classes (see pm_coef): an S x p matrix of posterior draws of the fixed-effect coefficients, columns named as pm_coef() names them, or NULL for a fit that has none. A class whose pm_draws() gives draws is analysed by the draws in predictmeans and contrastmeans: posterior medians, posterior SDs, equal-tailed credible intervals and the probability of direction, with no df and no p-values.

brmsfit (brms), stanreg (rstanarm) and MCMCglmm fits have their own methods: the draws of the coefficients of the mean, named as the columns of its design. An MCMCglmm fit keeps no data: give them (predictmeans(fit, ..., data = d)) or store them once (fit$data <- d); families gaussian, poisson and categorical (two classes) and ordinal (the units variance fixed in the prior; latent means on the standard probit scale; class probabilities of an observation, on the latent sd sqrt(1 + units), and with bias_adjust = TRUE also over the random effects), random intercepts and us() / idh() structures; for poisson and categorical the means are at units (the additive overdispersion) = 0, a typical observation, and bias_adjust = TRUE averages over units and the random effects (the mean). For another Bayesian class write a pm_draws() method, with pm_coef() (the posterior means), pm_vcov() and pm_basis().

Usage

pm_draws(model, ...)

# Default S3 method
pm_draws(model, ...)

# S3 method for class 'pm_foreign'
pm_draws(model, ...)

# S3 method for class 'pm_bayesfit'
pm_draws(model, ...)

# S3 method for class 'brmsfit'
pm_draws(model, ...)

# S3 method for class 'stanreg'
pm_draws(model, ...)

# S3 method for class 'MCMCglmm'
pm_draws(model, ...)

Arguments

model

A fitted model.

...

Not used.

Value

A numeric matrix (draws in rows, coefficients in columns), or NULL.

What is done for Bayesian fits

  • predictmeans(), contrastmeans(), covariatemeans() (curves, and with contr the difference of two curves, with a simultaneous band over the covariate for band = "simultaneous") and pm_slopes(): means, pairs, contrasts, curves and slopes from the draws; the inverse link (or trans) of each draw; bias_adjust = TRUE: the mean over the random effects of each draw; with adj, simultaneous bands (Besag et al. 1995) and letters; equivalence: the posterior probability within the margins (p.rope).

  • varcomp(): the variance components; R2_model(): Nakagawa's R2 of each draw; pm_check(): Rhat, effective sample sizes, divergent transitions; residplot(): trace and density of each coefficient by chain; autoplot(): means, pairs and the posterior of each (type = "draws").

  • brms weibull(), exponential() and lognormal() with cens(): time ratios, hazard ratios exp(-k d) per draw (Weibull, exponential), and survmeans() curves and medians, of a typical cluster or averaged over the random effects (marginal = TRUE).

  • brms cox(): hazard ratios per draw (means relative to the data's average linear predictor, as for coxph()), and survival curves from its spline baseline hazard (survmeans(); NA beyond the spline's range). Zero-inflated and hurdle families: the mean of the count (or non-zero) part, and with mean_type = "overall" the overall mean per draw ((1 - zi) mu; (1 - hu) E(y | y > 0); per trial for zero_inflated_binomial) at each cell, averaged over the cells on the response scale, and the pairs as ratios of overall means (pd, bands and letters on their log); a zi or hu modelled by predictors enters each cell (its variables not in the mean: over their levels, equally), and bias_adjust = TRUE integrates over the random effects of mu and of zi / hu (not when the two are correlated). cumulative(), sratio(), cratio() and acat() (logit): latent means x'b - mean(thresholds) (cumulative logit: odds ratios of a higher class), and with mean_type = "prob" or "mean_class" the class probabilities or the mean class per draw, each cell's probabilities averaged over the cells of the mean (as posterior_epred() averaged over the other factors, and as for clm fits).

  • pm_joint() and contrastmeans(joint = TRUE): the posterior region through 0 of several contrasts (d2, the Mahalanobis distance of 0 from the posterior, and p.contour = (b + 1) / (S + 1), b of the S draws at least as far from the posterior mean; Box and Tiao's contour probability), in place of the F test.

  • Random intercepts and slopes in bias_adjust, R2_model() and survmeans(marginal = TRUE): the variance at a row is z' Sigma z for each draw (z the row's values of the random-effect terms).

What is not done (it stops with a message)

  • df_term(), permmodels(), permlmer(), bootmodels(), CookD(), se_ranef(), heritability(), residvariogram(), semipred(), the test of equal curves of covariatemeans(contr = ), varcomp(test = TRUE), permlist.

  • brms: families other than gaussian, student, skew_normal, binomial, bernoulli, beta_binomial, poisson, negbinomial, geometric, gamma, inverse.gaussian, beta, lognormal, weibull, exponential, cox, cumulative, the zero-inflated poisson, negbinomial, binomial and beta, the hurdle poisson, negbinomial, lognormal and gamma, and sratio, cratio, acat, categorical (class probabilities as for nnet::multinom fits: the class a factor of the means, mean_type = "prob", "prob_diff" or "link"; random effects at zero, or with bias_adjust = TRUE averaged over them for up to 4 classes), and mixture() (the overall mean sum_k theta_k E_k by default; with mean_type = "conditional" the mean of each component, only for ordered components; fixed mixing proportions), so no zero-one-inflated models; ordinal models with a modelled disc or thresholds that are not flexible; multivariate and non-linear formulas; smooths, Gaussian processes, mo(), me(), mi(), category-specific and autocorrelation terms, offsets. A modelled sigma or shape leaves the means of mu as they are, but survival curves and hazard ratios need one shape or sigma for all rows.

  • rstanarm: models other than stan_glm(), stan_glmer(), stan_lmer(), stan_lm(), stan_glm.nb(), stan_glmer.nb() and stan_aov(). MCMCglmm: other families, several responses, other random structures than intercepts, us() and idh(); R2_model() of non-gaussian MCMCglmm fits.

  • A random slope whose variable is not a column of the fixed-effect design (its value at the means is not known); R2_model() for families other than gaussian and binomial.

  • Model checks of the data (posterior predictive checks): use pp_check() of brms or rstanarm.

Accuracy and checks

The summaries are exact for the draws: medians and quantiles of the draws of each quantity (type 7, as bayestestR::eti()); with an even number of draws the median averages two draws, so the median of a back-transformed quantity and the back-transformation of the median differ in the last digits. Their Monte Carlo error is that of the draws: the advice says when the draws have not converged (Rhat above 1.01, bulk or tail effective sample size below 400) or are too few for the limits (fewer than 1,000). Checked against emmeans' draws, bayestestR, brms' VarCorr() and posterior_epred() (overall means of zero-inflated and hurdle models and class probabilities of ordinal ones, averaged over the other factors), integrate() (tests/testthat/test-bayes.R). Nakagawa's R2 of each draw equals performance::r2_nakagawa() of a glmmTMB fit held at the draw's parameter values (gaussian with random slopes, Bernoulli); for an aggregated binomial response (cbind()) performance uses another observation-level variance, where predictmeans uses the latent pi^2/3. The survival quantities of brms fits are checked against their closed forms per draw, integrate() for the marginal curves, and survreg() within 5% with flat priors, and against SAS's own Bayesian fits of the same data (LIFEREG and PHREG with a BAYES statement, PROC MCMC with a random institution effect; dev/sas/survival-bayes.sas): time ratios within 0.5%, hazard ratios within 1.1%, survival probabilities and medians of the frailty model within 4.5% (different samplers and priors). On SAS's own draws (PROC MCMC, PHREG), predictmeans' survival formulas reproduce SAS's time ratios, hazard ratios, S(t), marginal S(t) and medians to SAS's printed digits.

References

Besag, J., Green, P., Higdon, D. and Mengersen, K. (1995). Bayesian computation and stochastic systems. Statistical Science, 10, 3-41.

Examples

# \donttest{
if (requireNamespace("rstanarm", quietly = TRUE) && requireNamespace("emmeans", quietly = TRUE)) {
  fit <- rstanarm::stan_glm(weight ~ group, data = PlantGrowth, chains = 1, iter = 1000,
                            refresh = 0, seed = 1)
  dim(pm_draws(fit))
  predictmeans(fit, "group", pairwise = TRUE)
}
# }