predict.semireg: Predictions from a semireg fit

View source: R/semireg-methods.R

predict.semiregR Documentation

Predictions from a semireg fit

Description

Population predictions of a semireg() or semireg_tmb() fit at new data: the fixed effects and the smooth terms, with the other random effects (and random curves s(x) | g) at zero. For the fitted values with every random effect, use fitted().

Usage

## S3 method for class 'semireg'
predict(
  object,
  newdata = NULL,
  type = c("link", "response", "lpmatrix"),
  se.fit = FALSE,
  unconditional = NULL,
  sm_term = NULL,
  ...
)

Arguments

object

A semireg() or semireg_tmb() fit.

newdata

A data frame with the variables of the fixed part and of the smooths; default: the data of the fit.

type

"link" (the linear predictor), "response" (the inverse link of it; an identity link gives the same), or "lpmatrix": the (sparse) matrix [X, Z] whose product with attr(, "coef") (fixed effects, then the predicted smooth coefficients; as.numeric() of the product) is the linear predictor without the offset (attr(, "offset")).

se.fit

Return standard errors as well (a list with fit and se.fit). On the response scale by the delta method.

unconditional

Include the uncertainty of the smoothing parameters (the first-order correction of semipred()). NULL: as semipred(), with the correction for generalized fits only.

sm_term

The smooth blocks to include (default all; names as in print(fit)).

...

Not used.

Details

semipred() answers another question: curves on a reference grid, averaged over the factors not in modelterm, with other covariates at reference values. predict() gives one value per row of newdata, from that row's own values; averaged over the same grid it gives semipred()'s means.

The design is that of semipred() (mgcv::PredictMat() of the stored smooths, then the map to the fit's random-effect columns), so predict() at the points of a semipred() grid gives its estimates and SEs. Offsets written in the formula (offset(o)) are taken from newdata; an offset given as the offset argument of the fit is not (as predict.gam()).

Value

A vector of predictions, a list with fit and se.fit, or the "lpmatrix". The attribute "unconditional" says whether the correction was used.

Examples

set.seed(1)
d <- data.frame(x = runif(100), g = gl(10, 10))
d$y <- sin(2 * pi * d$x) + rnorm(10, sd = 0.3)[d$g] + rnorm(100, sd = 0.3)
fit <- semireg(y ~ s(x) + (1 | g), data = d)
predict(fit, data.frame(x = c(0.25, 0.5)), se.fit = TRUE)

predictmeans documentation built on Dec. 3, 2026, 5:07 p.m.