Title: | Time Series Modeling for Air Pollution and Health |
---|---|
Description: | Tools for specifying time series regression models. |
Authors: | Roger D. Peng <[email protected]>, with contributions from Aidan McDermott |
Maintainer: | Roger D. Peng <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.6-2 |
Built: | 2024-11-01 11:18:54 UTC |
Source: | CRAN |
Mortality, air pollution, and weather data for Baltimore City, Maryland, USA, 1987–2000.
data(balt)
data(balt)
A data frame with 15342 observations on the following 20 variables.
daily counts of deaths from cardiovascular disease
daily counts of deaths from all causes excluding accident
daily counts of deaths from respiratory disease
daily average temperature (Fahrenheit)
daily running mean of temperature for lags 1–3
daily average dew point temperature
daily running mean of dew point temperature for lags 1–3
day/time indicator
date
a factor with levels under65
65to74
75p
a factor with levels Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
daily detrended PM10
lag 1 PM10
lag 2 PM10
lag 3 PM10
lag 4 PM10
lag 5 PM10
lag 6 PM10
lag 7 PM10
indicator for age category 2 (65 to 74)
indicator for age category 3 (75 and above)
Samet, Jonathan M., Scott L. Zeger, Francesca Dominici, Frank Curriero, Ivan Coursac, Douglas W. Dockery, Joel Schwartz, and Antonella Zanobetti. "The National Morbidity, Mortality, and Air Pollution Study." (2000).
Tools for creating model/formula terms in time series models
Lag(v, k, group = NULL) runMean(v, lags = 0, group = NULL, filter = NULL) harmonic(x, nfreq, period, intercept = FALSE)
Lag(v, k, group = NULL) runMean(v, lags = 0, group = NULL, filter = NULL) harmonic(x, nfreq, period, intercept = FALSE)
v , x
|
a numeric vector |
k , lags
|
an integer vector giving lag numbers |
group |
a factor or a list of factors defining groups of observations |
filter |
a vector specifying a linear filter |
nfreq |
number of sine/cosine pairs to include |
period |
period |
intercept |
should basis matrix include a column of 1s? |
Lag
returns a length(v)
by length(k)
matrix of
lagged variables. runMean
returns a numeric vector of length
length(v)
. harmonic
returns a matrix of sine/cosine
basis functions.
Roger D. Peng
## Ten day "time series" x <- rnorm(10) ## Lag 1 of `x' Lag(x, 1) ## Lag 0, 1, and 2 of `x' Lag(x, 0:2) ## Running mean of lag 0, 1, and 2 runMean(x, 0:2)
## Ten day "time series" x <- rnorm(10) ## Lag 1 of `x' Lag(x, 1) ## Lag 0, 1, and 2 of `x' Lag(x, 0:2) ## Running mean of lag 0, 1, and 2 runMean(x, 0:2)
This function fits a Normal hierarchical model with a spatial covariance structure via MCMC.
spatialgibbs(b, v, x, y, phi = 0.1, scale = 1, maxiter = 1000, burn = 500, a0 = 10, b0 = 100000)
spatialgibbs(b, v, x, y, phi = 0.1, scale = 1, maxiter = 1000, burn = 500, a0 = 10, b0 = 100000)
b |
a vector of regression coefficients |
v |
a vector of regression coefficient variances |
x |
a vector of x-coordinates |
y |
a vector of y-coordinates |
phi |
scale parameter for exponential covariance function |
scale |
scaling parameter for the prior variance of the national average estimate |
maxiter |
maximum number of iterations in the Gibbs sampler |
burn |
number of iterations to discard |
a0 |
parameter for Gamma prior on heterogeneity variance |
b0 |
parameter for Gamma prior on heterogeneity variance |
This function is used to produce pooled national average estimates of air pollution risks taking into account potential spatial correlation between the risks. The function uses a Markov chain Monte Carlo sampler to produce the posterior distribution of the national average estimate and the heterogeneity variance. See the reference below for more details.
Roger D. Peng [email protected]
Peng RD, Dominic F (2008). Statistical Methods for Environmental Epidemiology in R: A Case Study in Air Pollution and Health, Springer.
Decompose a vector into frequency components
tsdecomp(x, breaks)
tsdecomp(x, breaks)
x |
a numeric vector with no missing data |
breaks |
a numeric constant or a vector of break points into which
|
A matrix with dimension n x m where n is the length of x
and m
is the number of break categories.
Original by Aidan McDermott; revised by Roger Peng [email protected]
Dominici FD, McDermott A, Zeger SL, Samet JM (2003). “Airborne particulate matter and mortality: Timescale effects in four US cities”, American Journal of Epidemiology, 157 (12), 1055–1065.
x <- rnorm(101) freq.x <- tsdecomp(x, c(1, 10, 30, 80)) ## decompose x into 3 frequency categories. ## x[,1] represents from 1 to 9 cycles in 101 data points ## x[,2] represents from 10 to 29 cycles in 101 data points ## x[,3] represents from 30 to 50 cycles in 101 data points ## you can only have up to 50 cycles in 101 data points.
x <- rnorm(101) freq.x <- tsdecomp(x, c(1, 10, 30, 80)) ## decompose x into 3 frequency categories. ## x[,1] represents from 1 to 9 cycles in 101 data points ## x[,2] represents from 10 to 29 cycles in 101 data points ## x[,3] represents from 30 to 50 cycles in 101 data points ## you can only have up to 50 cycles in 101 data points.