Applies the same newdata preparation pipeline as predict.gwr_fit():
non-point geometries are coerced to points, the data is projected to the
CRS used during fitting (via ensure_projected()), and rows with
missing or non-finite values are dropped. Coordinate scaling and predictor
standardisation stored at fit time are then applied before delegating to
brms::posterior_epred() or brms::posterior_predict().
Arguments
- object
A
bayesian_fitobject.- newdata
An sf object with the same predictors. The response variable need not be present (true out-of-sample prediction is supported). NULL = fitted values.
- summary
"mean" (default) or "median" over posterior draws.
- type
"epred" (default) for expected predictions (no obs noise), or "predict" for full posterior predictive draws (includes obs noise).
- draws
If TRUE, return the full posterior draw matrix instead of a point summary. Default FALSE.
- ...
Ignored.
Value
Numeric vector of length nrow(newdata), or a
n_draws x nrow(newdata) matrix when draws = TRUE. If the
posterior draw fails the result is all NA (a 1-row matrix for
draws = TRUE) and the cause is logged. An ordinal or categorical
family is not a failed draw and is an error under
type = "epred": its expected value is a probability per response
category, not one number per row. Use type = "predict",
draws = TRUE for posterior draws of the predicted category, as category
indices; the share of draws in each category estimates its probability.
Without draws = TRUE, type = "predict" returns the mean (or
median) category index, an expected rank for an ordinal family and an
error for brms::categorical(), whose categories have no order.
With newdata = NULL the cached fitted() values are returned only
for the default summary = "mean", type = "epred",
draws = FALSE combination; any other combination is recomputed
against the training data, because the cache holds epred column means and
nothing else.
The GP boundary is held at its fitted value
brms 2.17 to 2.22 do not store the Hilbert-space boundary \(L\) in a
fitted GP basis, so brms:::.data_gp() recomputes it from whatever
rows predict() is handed, which moved every eigenfunction of the
approximation with the newdata bounding box while the fitted basis
coefficients stayed put. Two synthetic rows at the training coordinate
extrema are therefore appended before the posterior draw and dropped from
the result, and when newdata reaches past the training range the
c of the gp() term is scaled down by as much as the range
grew, so brms rebuilds exactly the boundary the model was fitted with. A
prediction therefore does not depend on which other rows share the call:
chunked, fold-wise and single-call predictions agree, and
predict_surface() does not depend on chunk_size.
brms 2.23.0 and later store \(L\) and reuse it, so there c is left
alone and the two extra rows change nothing.
Predictions outside the training coordinate envelope are extrapolation (a
notice is written to the log). A row further than \(L\) from the centre
of the training coordinates on either axis is past the edge of the basis,
where the approximate GP is an odd reflection of the fitted surface rather
than an estimate of anything, so it is returned as NA (a column of
NA with draws = TRUE) with a warning. The default boundary
factor puts that edge well outside the training data, so only
newdata reaching far past it is affected.
See also
Other methods on a fitted model:
coef.bayesian_fit(),
coef.gwr_fit(),
coef.rf_fit(),
fitted.bayesian_fit(),
fitted.gwr_fit(),
fitted.rf_fit(),
model_metrics(),
predict.gwr_fit(),
predict.rf_fit(),
print.rf_fit(),
print.spatial_fit(),
residuals.bayesian_fit(),
residuals.gwr_fit(),
residuals.rf_fit(),
summary.spatial_fit()