0% found this document useful (0 votes)
24 views3 pages

Time Series Practice P4

The document discusses using R to perform time series analysis and modeling. It covers creating matrices in R, fitting ARIMA models to temperature data, and using functions to estimate models and forecast future values. Steps are provided on exploratory data analysis, maximum likelihood estimation of parameters, model diagnostics, and comparing different ARIMA models. The document also includes two assignments, one involving estimating parameters from sample autocovariances and another involving building ARIMA models for two different datasets.

Uploaded by

Aa Hinda no Aria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Time Series Practice P4

The document discusses using R to perform time series analysis and modeling. It covers creating matrices in R, fitting ARIMA models to temperature data, and using functions to estimate models and forecast future values. Steps are provided on exploratory data analysis, maximum likelihood estimation of parameters, model diagnostics, and comparing different ARIMA models. The document also includes two assignments, one involving estimating parameters from sample autocovariances and another involving building ARIMA models for two different datasets.

Uploaded by

Aa Hinda no Aria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment 7

1 R Tutorial
1. In the first part of this tutorial, we will learn how to use R to perform matrix operations.

(a) Creating matrices. Suppose we want to have the following matrix in R:


 
2 1
X= .
3 4
We type x<-matrix(c(2,3,1,4),nrow=2,ncol=2)
(b) Transpose and inverse. Use t(x) and solve(x) to obtain X0 and X−1 respectively.
(c) Matrix multiplication. Suppose we have
 
6
Y= .
2
To obtain XY, type
y<-matrix(c(6,2),nrow=2)
x%*%y
to multiply matrices.

2. Next, we will fit ARIMA models for time series using R. We will start with a data
set that we have used frequently, the Berkeley average yearly temperature data set.
Download and input the data with the following commands

berk<-scan("berkeley.dat", what=list(double(0),double(0),double(0)))
berkeley<-ts(berk[[2]])

(a) Exploratory data analysis. We start by creating some graphical summaries of


the data. Create the time series plot, the ACF, and the PACF of the data.
The dataset is non-stationary, but we can obtain approximately stationary data
by differencing the time series. Use dberk<-diff(berkeley) and look at the
plot of the data, the ACF and the PACF. What are possible candidates for the
ARMA(p,q) process?

1
(b) ML estimation. We can fit models using maximum likelihood estimation. We
will be using a function created by Shumway and Stoffer to perform the esti-
mation. Download sarima.R from the assignment 7 . Type source("sarima.R")
to input the function into R. Using the command fit1<-sarima(dberk, 0,0,1),
we can fit the differenced data to an M A(1) model. This can also be done with
fit1<-sarima(berkeley, 0,1,1). This fits an ARIMA model with one level of
differencing for the original series berkeley.
(c) Checking significance of ARMA estimates. Look at the output by typing fit1.
Notice that we have estimates for the mean and for θ1 along with standard errors.
How do we check for significance of the ARMA estimates? We also have an
estimate for the variance of the white noise, σw2 .
(d) Model diagnostics. Some diagnostic plots are produced. The top plot shows the
standardized residual plot, the middle is the ACF for residuals, and the bottom is
the p-values for Ljung-Box statistic. If the model fits well, we should expect the
following: (1) No clear pattern in the residuals; (2) ACF plot cuts off after lag 0;
(3) p-values fall ABOVE the blue line. We can plot the Q-Q plot of the residuals
to check the normality of the residuals by typing
qqnorm((fit1$fit)$resid)
qqline((fit1$fit)$resid, col="red")
From all the diagnostics, we can see that, MA(1) fits the data well.
(e) How about AR(2)?
fit2<-sarima(dberk,2,0,0)
What do you think about the fit of the AR(2) model?
(f) We can also fit other models, for example ARMA(1,1):
fit3<-sarima(dberk,1,0,1)
What do you think about the fit of the ARMA(1,1) model?
(g) If you have to pick one model that reasonably describes the series, what is your
choice? Why?

3. Next, we will learn how to use R to give us predicted values for future observations. We
will use another function created by Shumway and Stoffer. Download sarima.for.R
from the assignment 7 folder on Collab. Type source("sarima.for.R") to input the
function into R.

(a) Forecasting. To predict the next five future values of the series, you may type
sarima.for(dberk,5,0,0,1)
Alternatively, you may type
sarima.for(berkeley,5,0,1,1)
Why do they look different?

2
2 Assignment
1. Suppose we observe x1 , · · · , x100 , and obtain the sample autocovariances γ̂(0) = 1382.2, γ̂(1) =
1114.4, γ̂(2) = 591.73 and γ̂(3) = 96.216. Find the Yule-walker estimates of φ1 , φ2 , and
σw2 in the model xt = φ1 xt−1 + φ2 xt−2 + wt , where wt is Gaussian white noise with
variance σw2 . Also find 95% confidence intervals for φ1 and φ2 . You may use R to help
with matrix calculations.

2. Build ARIMA models for the dataset 2a and 2b, using the steps outlined in class as
a guide. If there are two (or more) competing models, make sure you discuss each of
these. Make a decision about which model you think is best and support this decision
with plots and other information. Here are short summaries about the datasets to
analyze.

(a) The data in cow.dat are the daily morning temperature readings for a cow.
(b) The data in bicoal.dat are the annual bituminous coal production levels in the
US from 1930-1968 in millions of net tons per year.

You might also like