spCF-predict: Prediction from a fitted coarse-to-fine model

spCF-predictR Documentation

Prediction from a fitted coarse-to-fine model

Description

Predicts at new sites from a cf_lm or cf_glm fit. The fitted object keeps, for every selected scale, the local estimates at the knots of that scale; prediction only spreads these to the new sites, so its cost does not depend on the size of the training data, and the training data are not needed. The result is identical to fitting the model with the same sites given as coords0 (and x0, offset0).

Usage

## S3 method for class 'cf_lm'
predict(object, x0 = NULL, coords0 = NULL, probs = NULL, se_type = NULL, ...)

## S3 method for class 'cf_glm'
predict(
  object,
  x0 = NULL,
  coords0 = NULL,
  offset0 = NULL,
  probs = NULL,
  se_type = NULL,
  ...
)

## S3 method for class 'cf_dglm'
predict(
  object,
  x0 = NULL,
  coords0 = NULL,
  time0 = NULL,
  offset0 = NULL,
  probs = NULL,
  se_type = NULL,
  ...
)

Arguments

object

A fitted model from cf_lm or cf_glm.

x0

Covariates at the prediction sites, with the same columns as x in the fit. Required when the model has covariates.

coords0

Coordinates of the prediction sites (matrix or data.frame with two columns). If NULL, the predictions at the sample sites are returned.

probs

Probability levels of the predictive quantiles. Defaults to the levels of pred_q in the fit (0.005, 0.025, 0.05, 0.1, ..., 0.9, 0.95, 0.975, 0.995).

se_type

"prediction" for the predictive distribution of a new observation or "mean" for that of the mean. Defaults to the se_type of the fit; "prediction" needs a fit with se_type = "prediction".

...

Not used.

offset0

Offset at the prediction sites (cf_glm only; zero if NULL).

time0

Time points of the prediction sites (cf_dglm only), one per row of coords0. They may be training time points, time points between them (bridged between the smoothed states of the neighbouring training times), or time points before or after the training period (AR(1) backcast or forecast, the number of steps being the time difference over the median spacing of the training times).

Details

With an additional learner (add_learn in cf_lm_hv), the learner's model is kept in the fit and the quantiles of the combined predictive are simulated, as in cf_lm; they then vary slightly from call to call.

Value

A data.frame with one row per site: the predictive mean (pred), the predictive standard deviation (pred_sd) and the predictive quantiles (q<level>, e.g. q0.025), on the response scale.

Examples

set.seed(1)
n      <- 300
coords <- cbind(px = runif(n), py = runif(n))
x      <- data.frame(x1 = rnorm(n))
y      <- 0.5 * x$x1 + sin(4 * coords[, 1]) + rnorm(n, sd = 0.3)
hv     <- cf_lm_hv(y = y, x = x, coords = coords)
mod    <- cf_lm(y = y, x = x, coords = coords, mod_hv = hv)

coords0 <- cbind(px = runif(5), py = runif(5))
x0      <- data.frame(x1 = rnorm(5))
predict(mod, x0 = x0, coords0 = coords0, probs = c(0.025, 0.975))

spCF documentation built on Oct. 5, 2026, 5:07 p.m.