PredictionVariance: Prediction variance

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

The prediction variance of the forecast for lead times l=1,...,maxLead is computed given theoretical autocovariances.

Usage

1
PredictionVariance(r, maxLead = 1, DLQ = TRUE)

Arguments

r

the autocovariances at lags 0, 1, 2, ...

maxLead

maximum lead time of forecast

DLQ

Using Durbin-Levinson if TRUE. Otherwise Trench algorithm used.

Details

Two algorithms are available which are described in detail in McLeod, Yu and Krougly (2007). The default method, DLQ=TRUE, uses the autocovariances provided in r to determine the optimal linear mean-square error predictor of order length(r)-1. The mean-square error of this predictor is the lead-one error variance. The moving-average expansion of this model is used to compute any remaining variances (McLeod, Yu and Krougly, 2007). With the other Trench algorithm, when DLQ=FALSE, a direct matrix representation of the forecast variances is used (McLeod, Yu and Krougly, 2007). The Trench method is exact. Provided the length of r is large enough, the two methods will agree.

Value

vector of length maxLead containing the variances

Author(s)

A.I. McLeod

References

McLeod, A.I., Yu, Hao, Krougly, Zinovi L. (2007). Algorithms for Linear Time Series Analysis, Journal of Statistical Software.

See Also

predict.Arima, TrenchForecast, exactLoglikelihood

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#Example 1. Compare using DL method or Trench method
va<-PredictionVariance(0.9^(0:10), maxLead=10)
vb<-PredictionVariance(0.9^(0:10), maxLead=10, DLQ=FALSE)
cbind(va,vb)
# 
#Example 2. Compare with predict.Arima
#general script, just change z, p, q, ML
z<-sqrt(sunspot.year)
n<-length(z)
p<-9
q<-0
ML<-10
#for different data/model just reset above
out<-arima(z, order=c(p,0,q))
sda<-as.vector(predict(out, n.ahead=ML)$se)
#
phi<-theta<-numeric(0)
if (p>0) phi<-coef(out)[1:p]
if (q>0) theta<-coef(out)[(p+1):(p+q)]
zm<-coef(out)[p+q+1]
sigma2<-out$sigma2
r<-sigma2*tacvfARMA(phi, theta, maxLag=n+ML-1)
sdb<-sqrt(PredictionVariance(r, maxLead=ML))
cbind(sda,sdb)
#
# 
#Example 3. DL and Trench method can give different results
#  when the acvf is slowly decaying. Trench is always
#  exact based on a finite-sample.
L<-5
r<-1/sqrt(1:(L+1))
va<-PredictionVariance(r, maxLead=L)
vb<-PredictionVariance(r, maxLead=L, DLQ=FALSE)
cbind(va,vb) #results are slightly different
r<-1/sqrt(1:(1000)) #larger number of autocovariances
va<-PredictionVariance(r, maxLead=L)
vb<-PredictionVariance(r, maxLead=L, DLQ=FALSE)
cbind(va,vb) #results now agree

Example output

Warning messages:
1: In phikk * rev(phi) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

2: In phikk * rev(phi) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

3: In phikk * rev(phi) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

4: In phikk * rev(phi) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

5: In phikk * rev(phi) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

6: In phikk * rev(phi) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

7: In phikk * rev(phi) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

8: In phikk * rev(phi) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

             va        vb
 [1,] 0.1900000 0.1900000
 [2,] 0.3439000 0.3439000
 [3,] 0.4685590 0.4685590
 [4,] 0.5695328 0.5695328
 [5,] 0.6513216 0.6513216
 [6,] 0.7175705 0.7175705
 [7,] 0.7712321 0.7712321
 [8,] 0.8146980 0.8146980
 [9,] 0.8499054 0.8499054
[10,] 0.8784233 0.8784233
There were 50 or more warnings (use warnings() to see the first 50)
           sda      sdb
 [1,] 1.041030 1.041030
 [2,] 1.641731 1.641731
 [3,] 1.948342 1.948342
 [4,] 2.017305 2.017305
 [5,] 2.030936 2.030936
 [6,] 2.031083 2.031083
 [7,] 2.043472 2.043472
 [8,] 2.054550 2.054550
 [9,] 2.063813 2.063813
[10,] 2.064858 2.064858
Warning messages:
1: In phikk * rev(phi) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

2: In phikk * rev(phi) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

3: In phikk * rev(phi) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

            va        vb
[1,] 0.4802753 0.5000000
[2,] 0.6382356 0.6666667
[3,] 0.7222952 0.7500000
[4,] 0.7779709 0.8000000
[5,] 0.8205485 0.8333333
There were 50 or more warnings (use warnings() to see the first 50)
            va        vb
[1,] 0.4747281 0.4747282
[2,] 0.6239203 0.6239206
[3,] 0.6985165 0.6985167
[4,] 0.7440359 0.7440361
[5,] 0.7750786 0.7750787

ltsa documentation built on May 2, 2019, 4:01 a.m.