Deb
Deb

Reputation: 231

Error in na.fail.default(as.ts(x)) : missing values in object in time series forecasting

I have a time series:

x <- structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, 
0.74, 0.59, 0.54, 0.18, 0.05, -0.23, -1.92, 2.59, 0.26, -4.73, 
4.89, 2, -3.32, 0.28, 2.31, 7.9, 4.4, 0.32, 1.58, 1.44, -3.2, 
2.11, -2.67, 1.71, -0.52, 0.34, -1.65, 2.77, -2.2, -0.9, -3.44, 
5.48, -2.99, 0.01, 1.55), tsp = c(2012, 2015.91666666667, 12), class = "ts")

#       Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
#2012    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA
#2013  1.00  0.74  0.59  0.54  0.18  0.05 -0.23 -1.92  2.59  0.26 -4.73  4.89
#2014  2.00 -3.32  0.28  2.31  7.90  4.40  0.32  1.58  1.44 -3.20  2.11 -2.67
#2015  1.71 -0.52  0.34 -1.65  2.77 -2.20 -0.90 -3.44  5.48 -2.99  0.01  1.55

and I get an error:

acf(x)
# Error in na.fail.default(as.ts(x)) : missing values in object

Upvotes: 6

Views: 29928

Answers (1)

Deb
Deb

Reputation: 231

Use

acf(x, na.action = na.pass)

Editor Note:

The original poster has not visited Stack Overflow for many years. So I will take the initiative to add more information.

Yes, na.action = na.pass is a workaround. Model fitting functions like stats::arima and forecast::auto.arima also conformable with NA. However, the existence of NA implies that a time series has a different start and end time. This may cause problem when trying to do prediction or forecast. So, consider removing NA or filling in NA as another option.

Upvotes: 15

Related Questions