ACF does not show the correct results?

I applied following steps but failed to get the results!
Using

> rain <- scan("http://robjhyndman.com/tsdldata/hurst/precip1.dat",skip=1)
Read 100 items
> rainseries <- ts(rain,start=c(1813))
> rainseriesforecasts <- HoltWinters(rainseries, beta=FALSE, gamma=FALSE)
>rainseriesforecasts2 <- forecast:::forecast.HoltWinters(rainseriesforecasts, h=8)
>rainseriesforecasts2$residuals
Time Series:
Start = 1813 
End = 1912 
Frequency = 1 
  [1]         NA  2.5100000 -1.7605450
  [4]  7.6619220 -0.1128951  0.1198281
  [7]  2.6469377 -1.1569105  7.8909960
 [10] -0.1293468  0.1237733  8.4407877
 [13] -0.9328169 -1.6003159 -1.1317139
 [16]  3.7755848  1.1245120  0.8573870
 [19]  3.5167056 -4.5081227  0.5606200
 [22] -4.1129030  0.2063065  3.2813300
 [25] -4.7778206 -2.4725723  3.4470698
 [28] -4.6960787  7.1171978 -1.0944797
 [31]  1.6919208 -1.5488909 -1.4115293
 [34]  2.2325189 -6.4813328  5.7850067
 [37] -1.2345364 -4.9147575 -3.3862062
 [40] 11.4054742  1.6803570 -5.6001757
 [43] -1.0550911 -1.8796407 -1.8643009
 [46] -5.2293312  4.3368082  8.2621979
 [49] -1.9070988  3.4389033 -2.6240483
 [52] -7.2207523  5.5034232  7.4906723
 [55]  1.9599860 -0.9372918  1.1053171
 [58] -3.0213449  0.7515345  9.5734064
 [61] -1.8475186 -5.6529537  4.1034041
 [64]  1.7244238  3.6928281  9.5137515
 [67]  9.0242655  5.2665866  2.7795486
 [70]  1.9325016 -0.8541132 -4.8835107
 [73]  1.5242869  1.8575188 -5.9872873
 [76]  2.6871351 -1.2676827 -3.8571042
 [79]  3.1559349 -2.4601910 -5.2108475
 [82]  3.0548460 -3.4888415 -1.3546853
 [85] -1.9820083 -7.1041993 -2.0828352
 [88] -1.2925941 -2.3714148 -3.6442127
 [91] 13.7036912 -4.0768625 -1.6585224
 [94] -0.3285164 -1.5705920 -0.8727070
 [97]  2.2283440  0.7845930  0.1956674
[100]  3.2809476
> acf(rainseriesforecasts2$residuals, lag.max = 20)
Error in na.fail.default(as.ts(x)) : missing values in object

I don't know why acf cannot work at this point!

Could you give me any solutions?

Thank you very much!

Insang

The error message seems relatively helpful here. You can see that the problem has to do with missing values in the object and when I scan through your residuals I see you have a missing value as the first value. One option would be to remove that missing value prior to using acf().

There is another option, though, which takes a bit more sleuthing to figure out if you don't know that functions sometimes have this option yet. If you take a look at the help page for the acf() function, you'll see there is an argument called na.action. The default, shown in the "Usage" section, is na.fail.

acf(x, lag.max = NULL,
    type = c("correlation", "covariance", "partial"),
    plot = TRUE, na.action = na.fail, demean = TRUE, ...)

You got the error message because this is set to na.fail.

In the "Arguments" section of the documentation, this argument is described as

na.action function to be called to handle missing values. na.pass can be used.

This doesn't describe exactly what na.pass does, but you would find a bit more information by going to ?na.pass.

All of this is to say that another option for using acf() with missing values is to use na.pass for your na.action instead of the default. :slightly_smiling_face:

acf(rainseriesforecasts2$residuals, lag.max = 20, na.action = na.pass)

4 Likes

Thank you very much for your great information and solution!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.