Learn R Programming

dlnm (version 1.6.2)

plot.crosspred: Plot Predictions for a DLNM

Description

High and low-level method functions for graphs (3d, contour, slices and overall) of predictions from distributed lag non-linear models (DLNM).

Usage

## S3 method for class 'crosspred':
plot(x, ptype, var=NULL, lag=NULL, ci="area", ci.arg,
  ci.level=x$ci.level, cumul=FALSE, exp=NULL, ...)

## S3 method for class 'crosspred':
lines(x, ptype, var=NULL, lag=NULL, ci="n", ci.arg,
  ci.level=x$ci.level, cumul=FALSE, exp=NULL, ...)

## S3 method for class 'crosspred':
points(x, ptype, var=NULL, lag=NULL, ci="n", ci.arg,
  ci.level=x$ci.level, cumul=FALSE, exp=NULL, ...)

Arguments

x
an object of class "crosspred".
ptype
type of plot. Default to "3d" for lagged relationship, otherwise "overall". See Details below.
var, lag
vectors (for plot) or numeric scalars (for lines-points) of predictor or lag values for which specific effects must be plotted. Used only if ptype="slices".
ci
type of confidence intervals representation: one of "area", "bars", "lines" or "n". Default to "area" in high level functions, "n" for low-level functions.
ci.arg
list of arguments to be passed to low-level plotting functions to draw the confidence intervals. See Details.
ci.level
confidence level for the computation of confidence intervals.
cumul
logical. If TRUE, cumulative effects along lags are reported. Used only if type="slices". See Details.
exp
logical. It forces the choice about the exponentiation of effects. See Details.
...
optional graphical arguments. See Details.

Warnings

The values in var must match those specified in the object crosspred (see crosspred), while the values in lag must be included in the lag period specified by crossbasis.

Details

Different plots can be obtained by choosing the following values for the argument ptype: "3d": a 3-D plot of predicted effects on the grid of predictor-lag values. Additional graphical arguments can be included, such as theta-phi (perspective), border-shade (surface), xlab-ylab-zlab (axis labelling) or col. See persp for additional information. "contour": a contour/level plot of predicted effects on the grid of predictor-lag values. Additional graphical arguments can be included, such as plot.title-plot.axes-key.title for titles and axis and key labelling. Arguments x-y-z and col-level are automatically set and cannot be specified by the user. See filled.contour for additional information. "overall": a plot of the overall effects (summing up all the single lag contributions). See plot.default, lines and points for information on additional graphical arguments. "slices": a (optionally multiple) plot of predictor-specific effects along the lag space, and/or lag-specific effects along the predictor space. Predictor and lag values are chosen by var and lag, respectively. See plot.default, lines and points for information on additional graphical arguments. The method function plot calls the high-level functions listed above for each ptype, while lines-points add lines or points for ptype equal to "overall" or "slices". These methods allow a great flexibility in the choice of graphical parameters, specified through arguments of the original plotting functions. Some arguments, if not specified, are set to different default values than the original functions. Confidence intervals are plotted for ptype equal to "overall" or "slices". Their type is determined by ci, with options "area" (default for plot), "bars", "lines" or "n" (no confidence intervals, default for points and lines). The appearance may be modified through ci.arg, a list of arguments passed to to low-level plotting functions: polygon for "area", segments for "bars" and lines for "lines". See the original functions for a complete list of the arguments. This option offers flexibility in the choice of confidence intervals display. As above, some unspecified arguments are set to different default values. For ptype="slices", up to 4 plots for each dimension of predictor and lags are allowed in plot, while for lines-points a single plot in one of the two dimension must be chosen. Cumulative effects along lags are reported if cumul=TRUE: in this case, the same option must have been set to obtain the prediction saved in the crosspred object (see crosspred). For a detailed illustration of the use of the functions, see: vignette("dlnmOverview")

References

Gasparrini A. Distributed lag linear and non-linear models in R: the package dlnm. Journal of Statistical Software. 2011; 43(8):1-20. [freely available http://www.jstatsoft.org/v43/i08/{here}]. Gasparrini A., Armstrong, B.,Kenward M. G. Distributed lag non-linear models. Statistics in Medicine. 2010; 29(21):2224-2234. [freely available http://www.ncbi.nlm.nih.gov/pubmed/20812303{here}]

See Also

crossbasis to generate cross-basis matrices. crosspred to obtain predictions after model fitting. See dlnm-package for an overview of the package and type 'vignette(dlnmOverview)' for a detailed description.

Examples

Run this code
### complex DLNM
### space of predictor: 5df quadratic spline for temperature
### space of predictor: linear effect for PM10
### lag function: 5df natural cubic spline for temperature up to lag30
### lag function: single strata at lag 0-1 for PM10

# CREATE THE CROSS-BASIS FOR EACH PREDICTOR AND CHECK WITH SUMMARY
cb3.pm <- crossbasis(chicagoNMMAPS$pm10, lag=1, argvar=list(type="lin",cen=0),
  arglag=list(type="strata"))
cb3.temp <- crossbasis(chicagoNMMAPS$temp, lag=30, argvar=list(type="bs",
  df=5,degree=2,cen=21), arglag=list(df=5))
summary(cb3.pm)
summary(cb3.temp)

# RUN THE MODEL AND GET THE PREDICTION FOR TEMPERATURE
library(splines)
model3 <- glm(death ~  cb3.pm + cb3.temp + ns(time, 7*14) + dow,
  family=quasipoisson(), chicagoNMMAPS)
pred3.temp <- crosspred(cb3.temp, model3, by=1)

# 3-D AND CONTOUR PLOTS
plot(pred3.temp, xlab="Temperature", col="red", zlab="RR", shade=0.6,
  main="3D graph of temperature effect")
plot(pred3.temp, "contour", xlab="Temperature", key.title=title("RR"),
	plot.title=title("Contour plot",xlab="Temperature",ylab="Lag"))

# MULTIPLE SLICES
plot(pred3.temp, "slices", var=-20, ci="n", col=1, ylim=c(0.95,1.15), lwd=1.5,
	main="Lag-specific effects at different temperature, ref. 21C")
for(i in 1:3) lines(pred3.temp, "slices", var=c(0,27,33)[i], col=i+1, lwd=1.5)
legend("topright",paste("Temperature =",c(-20,0,27,33)), col=1:4, lwd=1.5)
plot(pred3.temp, "slices", var=c(-20,0,27,33), lag=c(0,5,15,28), col=4,
	ci.arg=list(density=40,col=grey(0.7)))

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

Run the code above in your browser using DataLab