crossbasis(var, vartype="ns", vardf=1, varknots=NULL, varbound=range(var),
varint=FALSE, cen=TRUE, cenvalue=mean(var), maxlag=0, lagtype="ns",
lagdf=1, lagknots=NULL, lagbound=c(-1,maxlag), lagint=TRUE)
## S3 method for class 'crossbasis':
summary(object, ...)
varknots
and lagknots
if provided."ns"
, the cut-off points for "strata"
(defining right-open intervals) and the threshold(s) for "lthr"
, "hthr"
and "thr"
type="ns"
.TRUE
, an 'intercept' is included in the basis. The default values should not be changed: see Warnings below.TRUE
, the basis functions for the space of predictor are centered. See Note below."crossbasis"
.summary
."crossbasis"
which can be included in a model formula in order to fit a DLNM. It contains the attributes crossdf
(global number of degrees of freedom) and range
(range of the original vector of observations). Additional attributes are returned that correspond to the arguments to crossbasis
, and explicitly give type
, df
, knots
, bound
, cen
, cenvalue
and maxlag
related to the corresponding basis ( with stub var-
or lag-
) for use of crosspred
. The function summary.crossbasis
returns a summary of the cross-basis matrix and the related attributes.var
, otherwise the presence of the additional intercept in the model used to fit the data will cause some of the cross-basis variables to be excluded. Conversely, an intercept should always be included in the basis for the space of lags when lagtype
is equal to "ns"
, "strata"
or "poly"
.type
defines the basis for each space (predictor and lags). It must be one of:
"ns"
: natural cubic splines, specified by knots
(internal knots) and bound
(boundary knots). See the function ns
for additional information. An intercept is included if int=T
. The transformed variables can be centered at cenvalue
.
"strata"
: strata variables (dummy parameterization) determined by internal cut-off values specified in knots
, which represent the lower boundaries for the right-open intervals. A dummy variable for the reference stratum (the first one by default) is included if int=T
, generating a full rank basis. Never centered.
"poly"
: polynomial with degree equal to df-int
. An intercept, corresponding to a vector of 1's (the power 0 of the polynomial) is included if int=T
. The transformed variables can be centered at cenvalue
.
"integer"
: strata variables (dummy parameterization) for each integer values, expressly created to specify an unconstrained function in the space of lags. df
is set automatically to the number of integer values. A dummy variable for the reference stratum (the first one by default) is included if int=T
, generating a full rank basis. Never centered.
"hthr","lthr"
: high and low threshold parameterization (linear relationship above or below the threshold, respectively, flat otherwise). The threshold is chosen by knots
(if more than one are provided, the last and the first one is chosen, respectively). df
is automatically set to 1. No intercept. Never centered.
"thr"
: double threshold parameterization (2 independent linear relationships above the second and below the first threshold, flat between them). The thresholds are chosen by knots
. If only one is provided, the threshold is unique (V-model). If more than 2 are provided, the first 2 are chosen. df
is automatically set to 2. No intercept. Never centered.
"lin"
: linear relationship (untransformed apart from optional centering). df
is automatically set to 1. No intercept. It can be centered at cenvalue
.
The values in knots
, if provided, automatically determine the value of "df"
(equal to length(knots)+int
for "strata"
and length(knots)+int+1
for "ns"
and "poly"
). If not provided, varknots
are placed at equally spaced quantiles, and lagknots
at equally spaced values on the log scale of lags. Some arguments can be automatically changed for not sensible combinations, or set to NULL
if not required.
A vignette with a detailed overview of all the functionalities of the package will be added in the next releases.crosspred
, crossplot
# Example 1. See crosspred and crossplot for other examples
# load and prepare the dataset
initDB()
data <- readCity("chic", collapseAge=TRUE)
data$temp <- (data$tmpd-32)*5/9
data$pm10 <- with(data, pm10mean+pm10trend)
### simple DLM for the effect of PM10 on mortality up to 15 days of lag
### space of predictor: linear effect for PM10
### space of predictor: 5df spline for temperature
### lag function: 4th degree polynomial for PM10
### lag function: strata at lag 0 and 1-3 for temperature
basis.pm <- crossbasis(data$pm10, vartype="lin", lagtype="poly",
lagdf=5,cen=FALSE,maxlag=15)
basis.temp <- crossbasis(data$temp, vardf=5, lagtype="strata",
lagknots=1, cenvalue=21, maxlag=3)
summary(basis.pm)
summary(basis.temp)
model <- glm(death ~ basis.pm + basis.temp, family=quasipoisson(), data)
pred.pm <- crosspred(basis.pm, model, at=0:20)
crossplot(pred.pm,"slices",var=10,
title="Effect of a 10-unit increase in PM10 along lags")
# overall effect for a 10-unit increase in PM over 15 days of lag, with CI
pred.pm$allRRfit["10"]
cbind(pred.pm$allRRlow, pred.pm$allRRhigh)["10",]
crossplot(pred.pm, "overall", label="PM10",
title="Overall effect of PM10 over 15 days of lag")
Run the code above in your browser using DataLab