1. Simulate an MA(1) model with n= 36 and = −0:5.
  1. Fit the correctly specified MA(1) model and look at a time series plot of the residuals. Does the plot support the MA(1) specification?
library(sarima)
## Warning: package 'sarima' was built under R version 4.2.2
## Loading required package: stats4
## 
## Attaching package: 'sarima'
## The following object is masked from 'package:stats':
## 
##     spectrum
library(astsa)
## 
## Attaching package: 'astsa'
## The following object is masked from 'package:sarima':
## 
##     sarima
library(TSA)
## 
## Attaching package: 'TSA'
## The following object is masked from 'package:sarima':
## 
##     periodogram
## The following objects are masked from 'package:stats':
## 
##     acf, arima
## The following object is masked from 'package:utils':
## 
##     tar
library(randtests)

set.seed(50000)
series=arima.sim(n=36,list(ma=0.5))
model=arima(series,order=c(0,0,1))
plot(rstandard(model),ylab ='Residuals', type='o')

The residual plot looks random.

  1. Display a normal quantile-quantile plot of the standardized residuals. Does the plot support the MA(1) specification?
qqnorm(residuals(model))
qqline(residuals(model))

The plot looks fine but toward the upper tail the plot doen’t look like it’s following the straight line.

  1. Display the sample ACF of the residuals. Does the plot support the MA(1) specification?
acf(residuals(model))

There doesn’t seem to be an issue with the autocorrelation.

  1. Calculate the Ljung-Box statistic summing to K= 6. Does this statistic support the MA(1) specification? (Hint: see LB.testfunction in R)
LB.test(model,lag=6)
## 
##  Box-Ljung test
## 
## data:  residuals from  model
## X-squared = 7.6999, df = 5, p-value = 0.1736

There doesn’t seem to be a porblem with the lag.

  1. Fit an AR(3) model by maximum likelihood to the square root of the hare abun dance series (filename hare).
  1. Plot the sample ACF of the residuals. Comment on the size of the correlations.
data(hare)
model=arima(sqrt(hare),order=c(3,0,0))
acf(rstandard(model))

Residual autocorrelations look good.

  1. Calculate the Ljung-Box statistic summing to K= 9. Does this statistic support the AR(3) specification? (Hint: see LB.testfunction in R)
LB.test(model,lag=9)
## 
##  Box-Ljung test
## 
## data:  residuals from  model
## X-squared = 6.2475, df = 6, p-value = 0.396

The Ljung-Box test does not reject independence of the error terms.

  1. Perform a runs test on the residuals and comment on the results.
runs(rstandard(model))
## $pvalue
## [1] 0.602
## 
## $observed.runs
## [1] 18
## 
## $expected.runs
## [1] 16.09677
## 
## $n1
## [1] 13
## 
## $n2
## [1] 18
## 
## $k
## [1] 0

The p value is 0.6, therefore we can’t reject independence of error term.

  1. Display the quantile-quantile normal plot of the residuals. Comment on the plot.
qqnorm(residuals(model))
qqline(residuals(model))

The graph has some outliers at both extremes.

  1. Perform the Shapiro-Wilk test of normality on the residuals.
shapiro.test(residuals(model))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(model)
## W = 0.93509, p-value = 0.06043
  1. The data file named robot contains a time series obtained from an industrial robot. The robot was put through a sequence of maneuvers, and the distance from a desired ending point was recorded in inches. This was repeated 324 times to form the time series.
  1. Compare the fits of an AR(1) model and an IMA(1,1) model for these data in terms of the diagnostic tests discussed in this chapter.
library(TSA)
data(robot)
mod1=arima(robot,order=c(1,0,0))
res1=rstandard(mod1)
mod1
## 
## Call:
## arima(x = robot, order = c(1, 0, 0))
## 
## Coefficients:
##          ar1  intercept
##       0.3074     0.0015
## s.e.  0.0528     0.0002
## 
## sigma^2 estimated as 6.482e-06:  log likelihood = 1475.54,  aic = -2947.08
mod2=arima(robot,order=c(1,0,1))
res2=rstandard(mod2)
mod2
## 
## Call:
## arima(x = robot, order = c(1, 0, 1))
## 
## Coefficients:
##          ar1      ma1  intercept
##       0.9472  -0.8062     0.0015
## s.e.  0.0309   0.0609     0.0005
## 
## sigma^2 estimated as 5.948e-06:  log likelihood = 1489.3,  aic = -2972.61

The IMA(1,1)model is better. The estimation parameters are better.

  1. What other model(s) might work better?