Generate DLNM Predictions from GHRmodels Objects
Description
This function takes an object of class GHRmodels, extracts the relevant coefficients and variance-covariance matrix, and then calls dlnm::crosspred to compute predictions over a range of covariate values (or at specified points).
crosspred_inla(
models,
basis,
mod_id,
at = NULL,
from = NULL,
to = NULL,
by = NULL,
lag,
bylag = 1,
cen = NULL,
ci.level = 0.95,
cumul = FALSE,
...
)Arguments
models: An object of classGHRmodels, containing fitted model output (e.g.,$fixedand$vcovlists).basis: A cross-basis or one-basis object, typically created bycrossbasis_inlaoronebasis_inla.mod_id: An integer or character string specifying which model within the inputGHRmodelsobject to use (e.g., ifmodel$fixedandmodel$vcovboth have multiple entries).at: A numeric vector of values at which to compute predictions (e.g.,seq(10,25, by=0.2))from, to: Numeric values specifying the range of the prediction sequence ifatis not specified (e.g.,from = 10andto = 25).by: Numeric increment for the sequence ifatis not specified (e.g.,by = 0.2).lag: A vector of two elements with min and max lag as declared in thecrossbasis_inlafunction.bylag: Numeric increment for lag steps (default is 1).cen: A centering value (e.g., a reference exposure level).ci.level: The credible interval level (default0.95).cumul: Logical; ifTRUE, cumulative predictions are computed (defaultFALSE)....: Additional arguments passed on to crosspred , such asbound,ci.arg, etc.
Details
The function identifies which coefficients in model$fixed[mod_id] and which rows/columns in model$vcov[mod_id] correspond to the one-basis or cross-basis terms (i.e., matching the column names in basis). Then it passes these slices to dlnm::crosspred to generate predictions. The centering value (cen), if specified, indicates the reference exposure (e.g., a mean temperature) at which to center the effect estimates (e.g., the effect a given temperature value on the outcome will be compared to the effect of the centering value on the outcome, in this case the mean temperature).
Returns
An object of class "GHRcrosspred", inheriting from "crosspred", with fields for the predicted values, credible intervals, and optionally cumulative predictions, as determined by crosspred .
See Also
dlnm::crosspred for details on how predictions are computed.
Examples
# Load example GHRmodels object from the package
model_dlnm_file <- system.file("examples", "model_dlnm.rds", package = "GHRmodel")
model_dlnm <- readRDS(model_dlnm_file)
# Load example cross-basis matrix from the package: 2-dimensional cross-basis matrix of the
# non-linear effect of dengue risk across tmin values and lags:
cb_tmin_file <- system.file("examples","cb_tmin.rds", package = "GHRmodel")
cb_tmin <- readRDS(cb_tmin_file) # loads cross-basis matrix into the environment
# Generate predictions
pred_result <- crosspred_inla(
models = model_dlnm,
basis = cb_tmin,
mod_id = "mod2",
at = seq(10, 30, by = 1), # e.g., temperature sequence
lag = 4,
cen = 20,
ci.level = 0.95
)
# Inspect predictions
pred_result$predvar # the sequence of 'at' values
pred_result$allfit # fitted values
pred_result$alllow # lower CI
pred_result$allhigh # upper CI