Learn R Programming

brms (version 2.15.0)

posterior_smooths.brmsfit: Posterior Predictions of Smooth Terms

Description

Compute posterior predictions of smooth s and t2 terms of models fitted with brms.

Usage

# S3 method for brmsfit
posterior_smooths(
  object,
  smooth,
  newdata = NULL,
  resp = NULL,
  dpar = NULL,
  nlpar = NULL,
  nsamples = NULL,
  subset = NULL,
  ...
)

posterior_smooths(object, ...)

Arguments

object

An object of class brmsfit.

smooth

Name of a single smooth term for which predictions should be computed.

newdata

An optional data.frame for which to evaluate predictions. If NULL (default), the original data of the model is used. Only those variables appearing in the chosen smooth term are required.

resp

Optional names of response variables. If specified, predictions are performed only for the specified response variables.

dpar

Optional name of a predicted distributional parameter. If specified, expected predictions of this parameters are returned.

nlpar

Optional name of a predicted non-linear parameter. If specified, expected predictions of this parameters are returned.

nsamples

Positive integer indicating how many posterior samples should be used. If NULL (the default) all samples are used. Ignored if subset is not NULL.

subset

A numeric vector specifying the posterior samples to be used. If NULL (the default), all samples are used.

...

Currently ignored.

Value

An S x N matrix, where S is the number of posterior samples and N is the number of observations.

Examples

Run this code
# NOT RUN {
set.seed(0) 
dat <- mgcv::gamSim(1, n = 200, scale = 2)
fit <- brm(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat)
summary(fit)

newdata <- data.frame(x2 = seq(0, 1, 10))
str(posterior_smooths(fit, smooth = "s(x2)", newdata = newdata))
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab