Applied Time Series Analysis
Preface
Book package
Authors
Citation
License
1
Basic matrix math in R
1.1
Creating matrices in R
1.2
Matrix multiplication, addition and transpose
1.3
Subsetting a matrix
1.4
Replacing elements in a matrix
1.5
Diagonal matrices and identity matrices
1.6
Taking the inverse of a square matrix
1.7
Problems
2
Linear regression in matrix form
Data and packages
2.1
A simple regression: one explanatory variable
2.2
Matrix Form 1
2.2.1
Solving for the parameters
2.2.2
Form 1 with multiple explanatory variables
2.2.3
When does Form 1 arise?
2.2.4
Matrix Form 1b: The transpose of Form 1
2.3
Matrix Form 2
2.3.1
Form 2 with multiple explanatory variables
2.3.2
When does Form 2 arise?
2.4
Groups of intercepts
2.4.1
North/South intercepts in Form 1
2.4.2
North/South intercepts in Form 2
2.5
Groups of
\(\beta\)
’s
2.5.1
Owner
\(\beta\)
’s in Form 1
2.5.2
Owner
\(\beta\)
’s in Form 2
2.6
Seasonal effect as a factor
2.6.1
Seasonal intercepts written in Form 1
2.6.2
Seasonal intercepts written in Form 2
2.7
Seasonal effect plus other explanatory variables*
2.8
Models with confounded parameters*
2.9
Solving for the parameters for Form 2*
2.10
Problems
3
Introduction to time series
3.1
Examples of time series
3.2
Classification of time series
3.2.1
By some
index set
3.2.2
By the
underlying process
3.2.3
By the
number of values recorded
3.2.4
By the
type of values recorded
3.3
Statistical analyses of time series
3.4
What is a time series model?
3.5
Two simple and classic time series models
3.6
Classical decomposition
3.6.1
1. The trend (
\(m_t\)
)
3.6.2
Example of linear filtering
3.6.3
2. Seasonal effect (
\(s_t\)
)
3.6.4
3. Remainder (
\(e_t\)
)
3.7
Decomposition on log-transformed data
3.7.1
The trend (
\(m_t\)
)
3.7.2
Seasonal effect (
\(s_t\)
) with error (
\(e_t\)
)
3.7.3
Mean seasonal effect (
\(s_t\)
)
3.7.4
Remainder (
\(e_t\)
)
4
Basic time series functions in R
Data and packages
4.1
Time series plots
4.1.1
ts
objects and
plot.ts()
4.1.2
Combining and plotting multiple
ts
objects
4.2
Decomposition of time series
4.2.1
Estimating trends
4.2.2
Estimating seasonal effects
4.2.3
Completing the model
4.2.4
Using
decompose()
for decomposition
4.3
Differencing to remove a trend or seasonal effects
4.3.1
Using the
diff()
function
4.4
Correlation within and among time series
4.4.1
Autocorrelation function (ACF)
4.4.2
Partial autocorrelation function (PACF)
4.4.3
Cross-correlation function (CCF)
4.5
White noise (WN)
4.5.1
Simulating white noise
4.6
Random walks (RW)
4.6.1
Simulating a random walk
4.6.2
Alternative formulation of a random walk
4.7
Autoregressive (AR) models
4.7.1
Simulating an AR(
\(p\)
) process
4.7.2
Correlation structure of AR(
\(p\)
) processes
4.8
Moving-average (MA) models
4.8.1
Simulating an MA(
\(q\)
) process
4.8.2
Correlation structure of MA(
\(q\)
) processes
4.9
Autoregressive moving-average (ARMA) models
4.9.1
Fitting ARMA(
\(p,q\)
) models with
arima()
4.9.2
Searching over model orders
4.10
Problems
5
Box-Jenkins method
Data and packages
5.1
Box-Jenkins method
5.2
Stationarity
5.2.1
Look at stationarity in simulated data
5.2.2
Stationary around a linear trend
5.2.3
Greek landing data
5.3
Dickey-Fuller and Augmented Dickey-Fuller tests
5.3.1
Dickey-Fuller test
5.3.2
Augmented Dickey-Fuller test
5.3.3
ADF test using
adf.test()
5.3.4
ADF test using
ur.df()
5.4
KPSS test
5.4.1
Test on simulated data
5.4.2
Test the anchovy data
5.5
Dealing with non-stationarity
5.5.1
ndiffs()
5.6
Summary: stationarity testing
5.7
Estimating ARMA parameters
5.7.1
AR(2) data
5.7.2
Fit with
Arima()
5.7.3
AR(1) simulated data
5.7.4
ARMA(1,2) simulated data
5.7.5
These functions work for data with missing values
5.8
Estimating the ARMA orders
5.8.1
Example: model selection for AR(2) data
5.8.2
Fitting to 100 simulated data sets
5.8.3
Trace=TRUE
5.8.4
stepwise=FALSE
5.8.5
Fit to the anchovy data
5.9
Check residuals
5.10
Forecast from a fitted ARIMA model
5.11
Seasonal ARIMA model
5.11.1
Plot seasonal data
5.11.2
auto.arima()
for seasonal ts
5.12
Forecast using a seasonal model
5.13
Problems
6
Univariate state-space models
Data and packages
6.1
Fitting a state-space model with MARSS
6.2
Examples using the Nile river data
6.2.1
Flat level model
6.2.2
Linear trend in flow model
6.2.3
Stochastic level model
6.2.4
Stochastic level model with drift
6.3
The StructTS function
6.4
Comparing models with AIC and model weights
6.5
Basic diagnostics
6.5.1
Outlier diagnostics
6.6
Fitting with JAGS
6.7
Fitting with Stan
6.8
A random walk model of animal movement
6.9
Problems
7
MARSS models
Data and packages
7.1
Overview
7.2
West coast harbor seals counts
7.2.1
Load the harbor seal data
7.3
A single well-mixed population
7.3.1
The observation process
7.3.2
Fitting the model
7.3.3
Model residuals
7.4
Four subpopulations with temporally uncorrelated errors
7.4.1
The observation process
7.4.2
Fitting the model
7.5
Four subpopulations with temporally correlated errors
7.5.1
Fitting the model
7.5.2
Model residuals
7.6
Using MARSS models to study spatial structure
7.7
Hypotheses regarding spatial structure
7.8
Set up the hypotheses as different models
7.8.1
Fit the models
7.9
Fitting a MARSS model with JAGS
7.9.1
Writing the model in JAGS
7.9.2
Fit the JAGS model
7.9.3
Plot the posteriors for the estimated states
7.10
Fitting a MARSS model with Stan
7.11
Problems
8
MARSS models with covariates
Data and packages
8.1
Overview
8.2
Prepare the plankton data
8.3
Observation-error only model
8.4
Process-error only model
8.5
Both process- and observation-error
8.6
Including seasonal effects in MARSS models
8.6.1
Seasonal effects as fixed factors
8.6.2
Seasonal effects as a polynomial
8.6.3
Seasonal effects as a Fourier series
8.7
Model diagnostics
8.8
Homework data and discussion
8.9
Problems
9
Dynamic linear models
Data
9.1
Overview
9.2
DLM in state-space form
9.3
Stochastic level models
9.3.1
Stochastic level with drift
9.4
Stochastic regression model
9.5
DLM with seasonal effect
9.6
Analysis of salmon survival
9.7
Fitting with
MARSS()
9.8
Forecasting
9.8.1
Estimate of the regression parameters
9.8.2
Prediction of the response variable
\(y_t\)
9.8.3
Computing the prediction
9.8.4
Forecasting salmon survival
9.8.5
Forecasting using MARSS
9.9
Forecast diagnostics
9.10
Homework discussion and data
9.10.1
Spawner-recruit data
9.11
Problems
10
Dynamic Factor Analysis
Data and packages
10.1
Introduction
10.2
Example of a DFA model
10.3
Constraining a DFA model
10.4
Different error structures
10.5
Lake Washington phytoplankton data
10.5.1
Plots of the data
10.6
Fitting DFA models with the MARSS package
10.6.1
The observation model
10.6.2
The process model
10.6.3
Fit the model in MARSS
10.7
Interpreting the MARSS output
10.8
Rotating trends and loadings
10.9
Estimated states and loadings
10.10
Plotting the data and model fits
10.11
Covariates in DFA models
10.12
Example from Lake Washington
10.13
Problems
11
Covariates with Missing Values
Data and packages
11.1
Covariates with missing values or observation error
11.2
Example: Snotel Data
11.2.1
Estimate missing Feb SWE using AR(1) with spatial correlation
11.2.2
Estimate missing Feb SWE using only correlation
11.2.3
Estimate missing Feb SWE using DFA
11.2.4
Diagnostics
11.2.5
Plot the fitted or mean Feb SWE using DFA
11.3
Modeling Seasonal SWE
11.3.1
Modeling season across sites
12
JAGS for Bayesian time series analysis
Data and packages
12.1
Overview
12.2
Univariatate response models
12.2.1
Linear regression with no covariates
12.2.2
Linear regression with covariates
12.2.3
Random walk with drift
12.2.4
Autoregressive AR(1) time series models
12.2.5
Regression with AR(1) errors
12.2.6
Univariate state space model
12.3
Multivariate state-space models
12.3.1
One hidden state
12.3.2
\(m\)
hidden states
12.4
Non-Gaussian observation errors
12.4.1
Poisson observation errors
12.4.2
Negative binomial observation errors
12.5
Forecasting with JAGS models
12.6
Problems
13
Stan for Bayesian time series analysis
Data and packages
13.1
Linear regression
13.1.1
Burn-in and thinning
13.2
Linear regression with correlated errors
13.3
Random walk model
13.4
Autoregressive models
13.5
Univariate state-space models
13.6
Dynamic factor analysis
13.6.1
Using leave one out cross-validation to select models
13.7
Uncertainty intervals on states
13.8
NEON EFI Aquatics Challenge
13.9
NEON EFI Aquatics Challenge
13.10
NEON EFI Aquatics Challenge
13.11
NEON EFI Aquatics Challenge
13.12
Problems
More examples
14
Detecting a signal from noisy sensors
14.1
Overview
14.2
Prep
14.3
Create a signal
14.4
Create data
14.5
Model Shared stochastic level with AR-1 observation errors
14.6
Fit the model
14.7
Show the fits
14.8
Estimated common trend from state-space model
14.9
Compare the common trend to mean of data
14.10
Missing data
14.11
Correlated noise
14.12
Discussion
15
Modeling changing seasonality
15.1
Overview
15.2
Time-varying seasonality and amplitude
15.3
Using DLMs to estimate changing season
15.4
Time-varying amplitude
15.4.1
Fitting the model
15.5
Multivariate responses
15.5.1
Same seasonality and same level
15.5.2
Same seasonality and same level but scaled
15.5.3
Scaled seasonality and same level
15.5.4
Different seasonality but correlated
15.5.5
Same seasonality and different level
15.6
Summary
16
Modeling cyclic sockeye
Data and packages
16.1
Overview
16.2
Analysis goal
16.3
Modeling the cycle
16.3.1
Set up the data
16.3.2
Specify the
\(\mathbf{Z}\)
matrix
16.3.3
Specify the model list
16.3.4
Fit the model
16.3.5
Plot the output
16.4
Univariate results
16.5
Multivariate DLM 1: Synchrony in levels
16.5.1
State model
16.5.2
Observation model
16.5.3
Fit model
16.5.4
Look at the results
References
Published with bookdown
Applied Time Series Analysis for Fisheries and Environmental Sciences
14.8
Estimated common trend from state-space model