Learn R Programming

dlnm (version 1.2.3)

crosspred: Generate predicted effects for a DLNM

Description

Generate predicted effects from a distributed lag non-linear model (DLNM) for a set of values of the original predictor. It returns specific effects for each combination of values and lags, plus overall and (optionally) cumulative effects (summed up along lags).

Usage

crosspred(crossbasis, model, at=NULL, 
	from=NULL, to=NULL, by=NULL, cumul=FALSE)

Arguments

crossbasis
an object of class "crossbasis".
model
a model object for which the prediction is desired. See Details below.
at
vector of values used for prediction.
from, to
range of values used for prediction.
by
increment of the sequence.
cumul
logical. If TRUE, cumulative effects are predicted. See details.

Value

  • A list object of class "crosspred" with the following components:
  • predvarvector of observations used for prediction.
  • maxlaga positive value defining the maximum lag.
  • coef, vcovrelated coefficients and variance-covariance matrix from model.
  • matfit, matsematrices of effects and related standard errors for each value of predvar and lag.
  • allfit, allsevectors of total effects and related standard errors for each value of predvar.
  • cumfit, cumsematrices of cumulative effects (along lags) and related standard errors for each value of predvar and lag. Computed if cumul=TRUE.
  • matRRfitexponentiated effects from matfit.
  • matRRlow, matRRhighmatrices with low and high 95% confidence intervals for matRRfit.
  • allRRfitexponentiated total effects from allfit.
  • cumRRfitexponentiated effects from cumfit. Computed if cumul=TRUE.
  • cumRRlow, cumRRhighmatrices with low and high 95% confidence intervals for cumRRfit. Computed if cumul=TRUE.
  • model.classclass of the model command used for estimation.
  • model.linka specification for the model link function.

Warnings

In case of collinear variables in the crossbasis object, some of them are discarded and the related parameters not included in model. crosspred will return an error. Check that the specification of the variables in crossbasis is meaningful. The name of the object crossbasis will be used by to extract the related estimated parameters from model. This name must not match the names of other predictors in the model formula. In addition, if more than one variable is transformed by cross-basis functions in the same model, different names must be specified.

Details

model can be an object created by the following regression functions: lm, glm, gam (package mgcv), glm.nb (package MASS) or gee (package geepack), clogit and coxph (package survival). The model formula can contain more than one crossbasis objects. The object crossbasis must be the same containing the cross-basis matrix included in model, including its attributes and class. The set of values for which the effects must be computed can be specified by at or alternatively by from/to/by. If specified by at, the values are automatically ordered and made unique. By default, from and to correspond to the range of the original vector of observation stored in the crossbasis object (see crossbasis). If by is not provided, 30 equally spaced values are returned. Matrices with cumulative effects summed upon lags for each values used for prediction are included if cumul=TRUE. For a long lag series (i.e. 1000 lags) the routine can be slow. These matrices are required by crossplot to graph the cumulative effects along lags. For a detailed illustration of the use of the functions, see: vignette("dlnmOverview")

References

Armstrong, B. Models for the relationship between ambient temperature and daily mortality. Epidemiology. 2006, 17(6):624-31.

See Also

crossbasis, crossplot

Examples

Run this code
# Example 2. See crossbasis and crossplot for other examples

### seasonal analysis
### space of predictor: linear effect above 40.3 microgr/m3 for O3
### space of predictor: linear effects below 15C and above 25C for temperature
### lag function: integer lag parameterization (unconstrained) for O3 up to lag5
### lag function: strata intervals at lag 0-1, 2-5 and 6-10 for temperature

data(chicagoNMMAPS)
chicagoNMMAPSseas <- subset(chicagoNMMAPS, month>5 & month<10)
basis.o3 <- crossbasis(chicagoNMMAPSseas$o3, group=chicagoNMMAPSseas$year,
	vartype="hthr", varknots=40.3, lagtype="integer", maxlag=5)
basis.temp <- crossbasis(chicagoNMMAPSseas$temp, group=chicagoNMMAPSseas$year,
	vartype="dthr", varknots=c(15,25), lagtype="strata",
	lagknots=c(2,6), maxlag=10)
summary(basis.o3)
summary(basis.temp)
model <- glm(death ~  basis.o3 + basis.temp + ns(doy, 4) + dow,
	family=quasipoisson(), chicagoNMMAPSseas)
pred.o3 <- crosspred(basis.o3, model, at=c(0:65,40.3,50.3))

crossplot(pred.o3, "slices", var=50.3, ci="bars",
	title="Effects of a 10-unit increase in ozone along lags")
crossplot(pred.o3,"overall",label="Ozone", ylim=c(0.9,1.3),
	title="Overall effects of ozone over 5 days of lag")
# overall effect for a 10-unit increase in ozone over 15 days of lag, with CI
pred.o3$allRRfit["50.3"]
cbind(pred.o3$allRRlow, pred.o3$allRRhigh)["50.3",]
crossplot(pred.o3, label="Ozone", title="3D graph of ozone effect")

### See the vignette 'dlnmOverview' for a detailed explanation of this example

Run the code above in your browser using DataLab