crossreduce(basis, model=NULL, type="overall", value=NULL, coef=NULL, vcov=NULL,
model.link=NULL, at=NULL, from=NULL, to=NULL, by=NULL, ci.level=0.95)
## S3 method for class 'crossreduce':
summary(object, ...)
"crossbasis"
."overall"
(default) or "lag"
for reduction to the predictor space of overall or lag-specific effects, or "var"
fror reduction to the lag space. See Details below."crossreduce"
.summary
."crossreduce"
with the following (optional) components:predvar
or for the sequence of lags defined by lag
, depending on the chosen dimension.fit
.RRfit
.basis
object, some of them are discarded and the related parameters not included in model
. Then, crossreduce
will return an error. Check that the specification of the variables is meaningful through summary.crossbasis
.
The name of the object basis
will be used to extract the related estimated parameters from object
. If more than one variable is transformed by cross-basis functions in the same model, different names must be specified.model
is the model object including basis
. It must include methods for coef
and vcov
, applied to extract the parameters. For model
classes without these methods, the user can manually extract the related parameters and include them in coef
-vcov
, also specifying model.link
. In this case, the dimensions and order of the first two must match the variables included in basis
.
The dimension to which the fit is reduced is chosen by type
, computing summaries for overall or lag-specific effects in the predictor dimension, or predictor-specific effects in the lag dimension. For specific effects, the value at which the reduction is computed is chosen by value
. The function then re-express the original fit of the model, defined by the parameters of the bi-dimensional cross-basis functions, in summaries defined by the one-dimensional basis for the related space and a (usually smaller) set of modified parameters.
Similarly to crosspred
, the object basis
must be the same containing the cross-basis matrix included in object
, including its attributes and class. The optional arguments at
and from
/to
/by
provides the values for predicted effects when the reduction is in the dimension of predictor, and exponentiated outcomes and confidence intervals are also optionally returned (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.
plot.crossreduce
to plot several the graphs.
See dlnm-package
for an overview of the package and type 'vignette(dlnmOverview)'
for a detailed description.# CREATE THE CROSS-BASIS: DOUBLE THRESHOLD AND NATURAL SPLINE
cb4 <- crossbasis(chicagoNMMAPS$temp, lag=30, argvar=list(type="dthr",
knots=c(10,25)), arglag=list(df=5))
# RUN THE MODEL AND GET THE PREDICTION FOR TEMPERATURE
library(splines)
model4 <- glm(death ~ cb4 + ns(time, 7*14) + dow,
family=quasipoisson(), chicagoNMMAPS)
pred4 <- crosspred(cb4, model4, by=1)
# REDUCE TO OVERALL ASSOCIATION
redall <- crossreduce(cb4, model4)
summary(redall)
# REDUCE TO LAG-SPECIFIC ASSOCIATION FOR LAG 5
redlag <- crossreduce(cb4, model4, type="lag", value=5)
# REDUCE TO PREDICTOR-SPECIFIC ASSOCIATION AT VALUE 33
redvar <- crossreduce(cb4, model4, type="var", value=33)
# NUMBER OF PARAMETERS OF THE ORIGINAL MODEL
length(coef(pred4))
# REDUCED NUMBER OF PARAMETERS FOR OVERALL AND LAG-SPECIFIC ASSOCIATIONS
length(coef(redall)) ; length(coef(redlag))
# REDUCED NUMBER OF PARAMETERS FOR PREDICTOR-SPECIFIC ASSOCIATIONS
length(coef(redvar))
# TEST: IDENTICAL FIT BETWEEN ORIGINAL AND REDUCED FIT
plot(pred4, "overall", xlab="Temperature", ylab="RR",
ylim=c(0.8,1.6), main="Overall effects")
lines(redall, ci="lines",col=4,lty=2)
legend("top",c("Original","Reduced"),col=c(2,4),lty=1:2,ins=0.1)
# RECONSTRUCT THE FIT IN TERMS OF ONE-DIMENSIONAL BASIS
b4 <- onebasis(0:30,knots=attributes(cb4)$arglag$knots,int=TRUE,cen=FALSE)
pred4b <- crosspred(b4,coef=coef(redvar),vcov=vcov(redvar),model.link="log",by=1)
# TEST: IDENTICAL FIT BETWEEN ORIGINAL, REDUCED AND RE-CONSTRUCTED
plot(pred4, "slices", var=33, ylab="RR", ylim=c(0.9,1.2),
main="Predictor-specific effects at 33C")
lines(redvar, ci="lines", col=4, lty=2)
points(pred4b, col=1, pch=19, cex=0.6)
legend("top",c("Original","Reduced","Reconstructed"),col=c(2,4,1),lty=c(1:2,NA),
pch=c(NA,NA,19),pt.cex=0.6,ins=0.1)
Run the code above in your browser using DataLab