Skip to contents

Generates posterior predictive draws at new spatial locations, times, or both. For every retained MCMC iteration, the method draws each active random effect from its GP predictive distribution conditional on the stored fitted random effect, adds it to the corresponding fixed-effect predictor, and draws a zero-inflated negative-binomial response.

Usage

# S3 method for class 'zinb_gp_fit'
predict(
  object,
  X,
  Ds_new = NULL,
  Dt_new = NULL,
  Vs_new = NULL,
  Vt_new = NULL,
  kern = NULL,
  ...
)

Arguments

object

A fitted zinb_gp_fit object returned by ZINB_GP().

X

Fixed-effect design matrix for the prediction observations.

Ds_new

Augmented spatial distance matrix produced by make_prediction_inputs(), or NULL for a temporal-only fit.

Dt_new

Augmented temporal distance matrix produced by make_prediction_inputs(), or NULL for a spatial-only fit.

Vs_new

Spatial design matrix produced by make_prediction_inputs().

Vt_new

Temporal design matrix produced by make_prediction_inputs().

kern

Kernel function used to fit the model. The default is kernel(); supply the fitting kernel again if a custom kernel was used.

...

Unused.

Value

An object of class zinb_gp_prediction containing posterior draws Y_pred, eta_at_risk, and eta_count. Active predicted GP effects are returned under A, B, C, and D, matching the fitted object.

Examples

# Fit a small spatial model, then predict at two new locations.
cells <- expand.grid(spatial = seq_len(4), replicate = seq_len(12))
Vs <- diag(4)[cells$spatial, -1, drop = FALSE]
y <- c(
  0, 0, 0, 0, 15, 1, 0, 0, 6, 0, 0, 0, 1, 6, 0, 0,
  0, 0, 0, 1, 11, 0, 0, 0, 2, 0, 0, 0, 8, 0, 5, 0,
  0, 4, 0, 0, 34, 0, 1, 0, 0, 2, 0, 1, 0, 0, 0, 3
)
X <- cbind("(Intercept)" = 1, x = as.numeric(scale(seq_along(y))))
coords <- rbind(c(0, 0), c(1000, 0), c(0, 1000), c(1000, 1000))

set.seed(1)
fit <- ZINB_GP(
  X = X,
  y = y,
  coords = coords,
  nsim = 5,
  burn = 1,
  thin = 2,
  use_count_gp = TRUE,
  use_inflation_gp = FALSE,
  Vs = Vs,
  Ds = as.matrix(stats::dist(coords))
)

coords_new <- rbind(c(500, 500), c(250, 750))
inputs <- make_prediction_inputs(coords = coords, coords_new = coords_new)
X_new <- cbind("(Intercept)" = 1, x = c(-0.5, 0.5))
predictions <- predict(
  fit,
  X = X_new,
  Ds_new = inputs$Ds_new,
  Vs_new = inputs$Vs_new
)
predictions$Y_pred
#>      [,1] [,2]
#> [1,]    0    0
#> [2,]    0    0