GHRtools
  • Home
  • data4health
    • Overview
  • clim4health
    • Overview
  • GHRexplore
    • Overview
    • Reference
    • Changelog

    • Vignettes
    • Getting started
  • GHRmodel
    • Overview
    • Reference
    • Changelog

    • Vignettes
    • Getting started
    • Covariate structures
    • DLNMs in GHRmodel
  • GHRpredict
    • Overview
  • About GHR

On this page

  • Generate DLNM Predictions from GHRmodels Objects
    • Description
    • Arguments
    • Details
    • Returns
    • See Also
    • Examples

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 class GHRmodels, containing fitted model output (e.g., $fixed and $vcov lists).
  • basis: A cross-basis or one-basis object, typically created by crossbasis_inla or onebasis_inla.
  • mod_id: An integer or character string specifying which model within the input GHRmodels object to use (e.g., if model$fixed and model$vcov both 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 if at is not specified (e.g., from = 10 and to = 25).
  • by: Numeric increment for the sequence if at is not specified (e.g., by = 0.2).
  • lag: A vector of two elements with min and max lag as declared in the crossbasis_inla function.
  • 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 (default 0.95).
  • cumul: Logical; if TRUE, cumulative predictions are computed (default FALSE).
  • ...: Additional arguments passed on to crosspred , such as bound, 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

Copyright 2025, GHR