casecross: Case-crossover Analysis to Control for Seasonality

View source: R/casecross.R

casecrossR Documentation

Case–crossover Analysis to Control for Seasonality


Fits a time-stratified case–crossover to regularly spaced time series data. The function is not suitable for irregularly spaced individual data. The function only uses a time-stratified design, and other designs such as the symmetric bi-directional design, are not available.


  exclusion = 2,
  stratalength = 28,
  matchdow = FALSE,
  usefinalwindow = FALSE,
  matchconf = "",
  confrange = 0,
  stratamonth = FALSE



formula. The dependent variable should be an integer count (e.g., daily number of deaths).


data set as a data frame.


exclusion period (in days) around cases, set to 2 (default). Must be greater than or equal to zero and smaller than stratalength.


length of stratum in days, set to 28 (default).


match case and control days using day of the week (TRUE/default=FALSE). This matching is in addition to the strata matching.


use the last stratum in the time series, which is likely to contain less days than all the other strata (TRUE/default=FALSE).


match case and control days using an important confounder (optional; must be in quotes). matchconf is the variable to match on. This matching is in addition to the strata matching.


range of the confounder within which case and control days will be treated as a match (optional). Range = matchconf (on case day) +/- confrange.


use strata based on months, default=FALSE. Instead of a fixed strata size when using stratalength.


The case–crossover method compares “case” days when events occurred (e.g., deaths) with control days to look for differences in exposure that might explain differences in the number of cases. Control days are selected to be nearby to case days, which means that only recent changes in the independent variable(s) are compared. By only comparing recent values, any long-term or seasonal variation in the dependent and independent variable(s) can be eliminated. This elimination depends on the definition of nearby and on the seasonal and long-term patterns in the independent variable(s).

Control and case days are only compared if they are in the same stratum. The stratum is controlled by stratalength, the default value is 28 days, so that cases and controls are compared in four week sections. Smaller stratum lengths provide a closer control for season, but reduce the available number of controls. Control days that are close to the case day may have similar levels of the independent variable(s). To reduce this correlation it is possible to place an exclusion around the cases. The default is 2, which means that the smallest gap between a case and control will be 3 days.

To remove any confounding by day of the week it is possible to additionally match by day of the week (matchdow), although this usually reduces the number of available controls. This matching is in addition to the strata matching.

It is possible to additionally match case and control days by an important confounder (matchconf) in order to remove its effect. Control days are matched to case days if they are: i) in the same strata, ii) have the same day of the week if matchdow=TRUE, iii) have a value of matchconf that is within plus/minus confrange of the value of matchconf on the case day. If the range is set too narrow then the number of available controls will become too small, which in turn means the number of case days with at least one control day is compromised.

The method uses conditional logistic regression (see coxph and so the parameter estimates are odds ratios.)

The code assumes that the data frame contains a date variable (in Date format) called ‘date’.



the original call to the casecross function.


conditional logistic regression model of class coxph.


total number of cases.


number of case days with at least one control day.


average number of control days per case day.


Adrian Barnett


Janes, H., Sheppard, L., Lumley, T. (2005) Case-crossover analyses of air pollution exposure data: Referent selection strategies and their implications for bias. Epidemiology 16(6), 717–726.

Barnett, A.G., Dobson, A.J. (2010) Analysing Seasonal Health Data. Springer.

See Also

summary.casecross, coxph


# cardiovascular disease data
CVDdaily = subset(CVDdaily, date<=as.Date('1987-12-31')) # subset for example
# Effect of ozone on CVD death
model1 = casecross(cvd ~ o3mean+tmpd+Mon+Tue+Wed+Thu+Fri+Sat, data=CVDdaily)
# match on day of the week
model2 = casecross(cvd ~ o3mean+tmpd, matchdow=TRUE, data=CVDdaily)
# match on temperature to within a degree
model3 = casecross(cvd ~ o3mean+Mon+Tue+Wed+Thu+Fri+Sat, data=CVDdaily,
                   matchconf='tmpd', confrange=1)

season documentation built on March 21, 2022, 9:10 a.m.