Title: | Time Series Modeling for Air Pollution and Health |
Depends: | R (≥ 3.0.0) |
Imports: | splines, stats |
Suggests: | testthat |
Version: | 0.6-2 |
Author: | Roger D. Peng <roger.peng@austin.utexas.edu>, with contributions from Aidan McDermott |
Maintainer: | Roger D. Peng <roger.peng@austin.utexas.edu> |
Description: | Tools for specifying time series regression models. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
NeedsCompilation: | no |
Packaged: | 2024-06-25 14:08:56 UTC; rp34949 |
Repository: | CRAN |
Date/Publication: | 2024-06-25 21:20:01 UTC |
Model terms for time series models
Description
Tools for creating model/formula terms in time series models
Usage
Lag(v, k, group = NULL)
runMean(v, lags = 0, group = NULL, filter = NULL)
harmonic(x, nfreq, period, intercept = FALSE)
Arguments
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? |
Value
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.
Author(s)
Roger D. Peng
Examples
## 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)
Baltimore City data
Description
Mortality, air pollution, and weather data for Baltimore City, Maryland, USA, 1987–2000.
Usage
data(balt)
Format
A data frame with 15342 observations on the following 20 variables.
- cvd
daily counts of deaths from cardiovascular disease
- death
daily counts of deaths from all causes excluding accident
- resp
daily counts of deaths from respiratory disease
- tmpd
daily average temperature (Fahrenheit)
- rmtmpd
daily running mean of temperature for lags 1–3
- dptp
daily average dew point temperature
- rmdptp
daily running mean of dew point temperature for lags 1–3
- time
day/time indicator
- date
date
- agecat
a factor with levels
under65
65to74
75p
- dow
a factor with levels
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
- pm10tmean
daily detrended PM10
- l1pm10tmean
lag 1 PM10
- l2pm10tmean
lag 2 PM10
- l3pm10tmean
lag 3 PM10
- l4pm10tmean
lag 4 PM10
- l5pm10tmean
lag 5 PM10
- l6pm10tmean
lag 6 PM10
- l7pm10tmean
lag 7 PM10
- Age2Ind
indicator for age category 2 (65 to 74)
- Age3Ind
indicator for age category 3 (75 and above)
Source
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).
Fit Hierarchical Model with Spatial Covariance
Description
This function fits a Normal hierarchical model with a spatial covariance structure via MCMC.
Usage
spatialgibbs(b, v, x, y, phi = 0.1, scale = 1, maxiter = 1000,
burn = 500, a0 = 10, b0 = 100000)
Arguments
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 |
Details
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.
Author(s)
Roger D. Peng rpeng@jhsph.edu
References
Peng RD, Dominic F (2008). Statistical Methods for Environmental Epidemiology in R: A Case Study in Air Pollution and Health, Springer.
Time scale decomposition
Description
Decompose a vector into frequency components
Usage
tsdecomp(x, breaks)
Arguments
x |
a numeric vector with no missing data |
breaks |
a numeric constant or a vector of break points into which
|
Value
A matrix with dimension n x m where n is the length of x
and m
is the number of break categories.
Author(s)
Original by Aidan McDermott; revised by Roger Peng rpeng@jhsph.edu
References
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.
Examples
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.