# SMHS TimeSeriesAnalysis LOS

(Difference between revisions)
IvoDinov (Talk | contribs)
(Created page with '== Scientific Methods for Health Sciences - Applications of Time Series Analysis == ==Time series regression studies in environmental epidemiology (London Ozone Study 2…')

## Time series regression studies in environmental epidemiology (London Ozone Study 2002-2006)

A time series regression analysis of a London ozone dataset including daily observations from 1 January 2002 to 31 December 2006. Each day has records of (mean) ozone levels that day, and the total number of deaths that occurred in the city.

### Questions

• Is there an association between day-to-day variation in ozone levels and daily risk of death?
• Is ozone exposure associated with the outcome is death or other confounders - temperature and relative humidity?

Reference: Bhaskaran K, Gasparrini A, Hajat S, Smeeth L, Armstrong B. Time series regression studies in environmental epidemiology. International Journal of Epidemiology. 2013;42(4):1187-1195. doi:10.1093/ije/dyt092. http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3780998/

library(foreign)
# 07_LondonOzonPolutionData_2006_TS.csv

# Set the Default Action for Missing Data to na.exclude
options(na.action="na.exclude")


### Exploratory Analyses

# set the plotting parameters for the plot
par(mex=0.8,mfrow=c(2,1))

# sub-plot for daily deaths, with vertical lines defining years
plot(data$\$$date,data\$$numdeaths,pch=".",main="Daily deaths over time",  ylab="Daily number of deaths",xlab="Date") abline(v=data$\$$date[grep("-01-01",data\$$date)],col=grey(0.6),lty=2)

# plot for ozone levels
plot(data$\$$date,data\$$ozone,pch=".",main="Ozone levels over time", ylab="Daily mean ozone level (ug/m3)",xlab="Date") abline(v=data$\$$date[grep("-01-01",data\$$date)],col=grey(0.6),lty=2)
par(oldpar)
layout(1)

# descriptive statistics
summary(data)
# correlations
cor(data[,2:4])
# scale exposure
data$\$$ozone10 <- data\$$ozone/10  ### Modelling Seasonality and Long-Term Trend # option 1: time-stratified model  # generate month and year  data$\$$month <- as.factor(months(data\$$date,abbr=TRUE))

data$\$$year <- as.factor(substr(data\$$date,1,4)) # fit a Poisson model with a stratum for each month nested in year  # (use of quasi-Poisson family for scaling the standard errors)  model1 <- glm(numdeaths ~ month/year,data,family=quasipoisson) summary(model1) # compute predicted number of deaths from this model  pred1 <- predict(model1,type="response") # Figure 2a: Three alternative ways of modelling long-term patterns in the data (seasonality and trends)  plot(data$\$$date,data\$$numdeaths,ylim=c(100,300),pch=19,cex=0.2,col=grey(0.6),

main="Time-stratified model (month strata)",ylab="Daily number of deaths", xlab="Date")

tempdecile <- cut(data$\$$temperature,breaks=cutoffs,include.lowest=TRUE) model6 <- update(model5,.~.+tempdecile) summary(model6) (eff6 <- ci.lin(model6,subset="ozone10",Exp=T)) ### Build a summary table with effect as percent increase tabeff <- rbind(eff4,eff5,eff6)[,5:7] tabeff <- (tabeff-1)*100 dimnames(tabeff) <- list(c("Unadjusted","Plus season/trend","Plus temperature"), c("RR","ci.low","ci.hi")) round(tabeff,2)  # explore the lagged (delayed) effects # SINGLE-LAG MODELS  # prepare the table with estimates tablag <- matrix(NA,7+1,3,dimnames=list(paste("Lag",0:7), c("RR","ci.low","ci.hi")))  1. iterate for(i in 0:7) { # lag ozone and temperature variables ozone10lag <- Lag(data\$$ozone10,i) tempdecilelag <- cut(Lag(data$\$$temperature,i),breaks=cutoffs, include.lowest=TRUE) # define the transformation for temperature # lag same as above, but with strata terms instead than linear mod <- glm(numdeaths ~ ozone10lag + tempdecilelag + spl,data, family=quasipoisson) tablag[i+1,] <- ci.lin(mod,subset="ozone10lag",Exp=T)[5:7] } tablag <mark> FIX # SIGNS!! </mark> 1. Figure 4A: Modelling lagged (delayed) associations between ozone exposure and survival/death outcome. plot(0:7,0:7,type="n",ylim=c(0.99,1.03),main="Lag terms modelled one at a time", xlab="Lag (days)", ylab="RR and 95%CI per 10ug/m3 ozone increase") abline(h=1) arrows(0:7,tablag[,2],0:7,tablag[,3],length=0.05,angle=90,code=3) points(0:7,tablag[,1],pch=19) ### Model Checking 1. generate deviance residuals from unconstrained distributed lag model res6 <- residuals(model6,type="deviance") 1. Figure A1: Plot of deviance residuals over time (London data) plot(data\$$date,res6,ylim=c(-5,10),pch=19,cex=0.7,col=grey(0.6),

main="Residuals over time",ylab="Deviance residuals",xlab="Date")

abline(h=0,lty=2,lwd=2)

1. Figure A2a: Residual plot for Model6: the residuals relate to the unconstrained distributed lag model with ozone
2. (lag days 0 to 7 inclusive), adjusted for temperature at the same lags. The spike in the plot of residuals relate to
3. the 2003 European heat wave, and indicate that the current model does not explain the data over this period well.

pacf(res6,na.action=na.omit,main="From original model")

1. Include the 1-Day Lagged Residual in the Model

model9 <- update(model6,.~.+Lag(res6,1))

1. Figure A2b: residuals related to the unconstrained distributed lag model with ozone (lag days 0 to 7 inclusive),
2. adjusted for temperature at the same lags

pacf(residuals(model9,type="deviance"),na.action=na.omit,

main="From model adjusted for residual autocorrelation")

## Irish Longitudinal Study on Ageing Example

The Irish Longitudinal Study on Ageing (TILDA), 2009-2011 http://www.icpsr.umich.edu/icpsrweb/ICPSR/studies/34315 Kenny, Rose Anne. The Irish Longitudinal Study on Ageing (TILDA), 2009-2011. ICPSR34315-v1. Ann Arbor, MI: Inter-university Consortium Bibliographic Citation: for Political and Social Research [distributor], 2014-07-16. http://doi.org/10.3886/ICPSR34315.v1