## 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, ...)
"crosspred"
."3d"
for lagged relationship, otherwise "overall"
. See Details below.plot
) or numeric scalars (for lines
-points
) of predictor or lag values at which specific associations must be plotted. Used only if ptype="slices"
."area"
, "bars"
, "lines"
or "n"
. Default to "area"
in high level functions, "n"
for low-level functions.TRUE
, incremental cumulative associations along lags are plotted. Used only if type="slices"
. See Details.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
.ptype
:
"3d"
: a 3-D plot of predicted associations 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 associations 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 cumulative associations in the whole lag period. See plot.default
, lines
and points
for information on additional graphical arguments.
"slices"
: a (optionally multiple) plot of predictor-specific associations along the lag space, and/or lag-specific associations 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. Incremental cumulative associations 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")
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.### 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 associations 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