Attributable risk from distributed lag nonlinear models
Attributable risk from distributed lag nonlinear models
This is a general function that computes attributable risk (attributable numbers or fractions) from distributed lag nonlinear models.
attrdl(x, basis, cases, model =NULL, coef =NULL, vcov =NULL, type ="af", dir ="back", tot =TRUE, cen, range =NULL, sim =FALSE, nsim =5000, sub =1:length(cases))
Arguments
x: An exposure vector OR (only for dir="back") a matrix of lagged exposures, for which the attributable risk needs to be computed.
basis: The object of class "crossbasis" used for fitting the model.
cases: The cases vector OR (only for dir="forw") the matrix of future cases corresponding to x.
model: The fitted model. You need to provide either this, or arguments coef and vcov. The model MUST have a log link function.
coef: Coefficients for basis IF model is not provided
vcov: Variance-covariance matrix for basis IF model is not provided
type: Either "an" or "af" for attributable number or attributable fraction
dir: Either "back" or "forw" for backward or forward perspectives of attributable risk
tot: If TRUE, the total attributable risk is computed (number or fraction, depending on argument type)
cen: The reference value used as the counterfactual scenario (the comparator)
range: The range of exposure (for which the attributable risk, compared to cen, is calculated). If NULL, the whole range is used.
sim: Set to TRUE if Monte Carlo simulation samples should be returned.
nsim: Number of simulation samples desired (only for nsim=TRUE).
sub: Subset of cases for which to calculate the attributable risk (as an integer index vector). Defaults to 1:length(cases). Argument cases should be a vector (not a matrix).
Returns
By default, a numeric scalar representing the total attributable fraction or number. If sim=TRUE, a vector of the simulated samples with length nsim. If tot=FALSE, a vector with contributions for all the observations (see Note below). These quantities are defined versus a counterfactual scenario defined through the argument cen.
Details
Original function and documentation written by Antonio Gasparrini and available here. Slightly amended by Theodore Lytras for use with FluMoDL.
This function computes the attributable fraction or number for a specific exposure scenario and associated cases, given an estimated exposure-lag-response association defined by a DLNM. Either forward or backward versions of attributable risk measures are available in this setting. The method is described by Gasparrini and Leone (2014), see references below. The function works in combination with other functions in the package dlnm, which is assumed to be available.
The exposure and cases are provided by the arguments x and cases, respectively. The original cross-basis and fitted model containg it used for estimation are provided by the arguments basis and model, respectively. Alternatively, the user can provide estimated coefficients and (co)variance matrix with coef and vcov.
The function works both with time series and non-time series data. In a time series setting, both x and cases represent a complete series of ordered observations. More generally, the user can apply this function for any kind of data: in this case x must be a matrix of lagged exposures when dir="back", and cases must be a matrix of future cases dir="forw". The function can compute the total attributable risk (if tot=TRUE, the default) or the contribution for each observation. The argument cen defines the value used as counterfactual scenario.
If sim=TRUE, the function computes samples of the attributable risk measures by simulating from the assumed normal distribution of the estimated coefficients (only implemented for total estimates). These samples can be used to defined empirical confidence intervals.
Note
The function handles missing values in both the x and cases objects, excluding incomplete observations (also due to lagging) accordingly. However, the total attributable number is rescaled to match the fraction using as denominator the total observed number in cases. This approach uses the all the available information even in the presence of missing values in x. All of this under the assumption that the missing mechanism is unrelated with both exposure and cases values.
The functions can be also used with estimates from DLNMs reduced to the overall cumulative exposure-response through the function crossreduce in the package dlnm. In this case, the modified coefficients and (co)variance matrix of the reduced cross-basis in basis must be passed using the arguments coef and vcov. This option can be useful when the original estimates from the full cross-basis are not available any more, for example following a meta-analysis. Given the lag-specific estimates are not available in this case, only the forward version of attributable risk (dir="forw") can be computed. See Gasparrini and Leone (2014) for further info.
Examples
# load the packagelibrary(FluMoDL)# package dlnm is automatically loaded# define the cross-basis and fit the modelcb <- crossbasis(chicagoNMMAPS$temp, lag=30, argvar=list(fun="bs", knots=c(-10,3,18)), arglag=list(knots=c(1,3,10)))library(splines)model <- glm(death ~ cb + ns(time,7*14)+ dow, family=quasipoisson(), chicagoNMMAPS)# global backward attributable risk of temperature (number and fraction)attrdl(chicagoNMMAPS$temp,cb,chicagoNMMAPS$death,model,type="an",cen=21)attrdl(chicagoNMMAPS$temp,cb,chicagoNMMAPS$death,model,cen=21)# global forward attributable fractionattrdl(chicagoNMMAPS$temp,cb,chicagoNMMAPS$death,model,dir="forw",cen=21)# empirical confidence intervalsafsim <- attrdl(chicagoNMMAPS$temp,cb,chicagoNMMAPS$death,model,cen=21, sim=TRUE,nsim=1000)quantile(afsim,c(2.5,97.5)/100)# attributable fraction component due to heat and coldattrdl(chicagoNMMAPS$temp,cb,chicagoNMMAPS$death,model,cen=21,range=c(21,100))attrdl(chicagoNMMAPS$temp,cb,chicagoNMMAPS$death,model,cen=21,range=c(-100,21))# daily attributable deaths in the second monthattrdl(chicagoNMMAPS$temp,cb,chicagoNMMAPS$death,model,type="an", tot=FALSE,cen=21)[31:60]
References
Gasparrini A, Leone M. Attributable risk from distributed lag models. BMC Med Res Methodol 2014;14:55.