SteffenMoritz / imputeTS

CRAN R Package: Time Series Missing Value Imputation
http://steffenmoritz.github.io/imputeTS/
GNU General Public License v3.0
158 stars 25 forks source link

Detailed Model Summary in na_kalman() #45

Open csglui opened 4 years ago

csglui commented 4 years ago

The interpolation result by na_kalman() is pretty good when the option model='auto.arima' is used. Is it possible to show the searched parameter results of auto.arima()?

Did the package use the default search parameter settings of auto.arima() in the forecast package?

Thanks in advance.

SteffenMoritz commented 4 years ago

Yes, you are totally correct. It uses the default search parameters of auto.arima() from forecast.

So just run the following on your series: (tsAirgap is just an example time series with NAs)

library("forecast")
auto.arima(tsAirgap)

Series: tsAirgap ARIMA(0,1,1)(0,1,0)[12]

Coefficients: ma1 -0.3745 s.e. 0.0918

sigma^2 estimated as 145.2: log likelihood=-466.04 AIC=936.09 AICc=936.18 BIC=941.84

This are then the ARIMA parameters for model='auto.arima'.

If you think there is a model that fits the time series better, you can also supply a ARIMA model you created:

# Example 5:  Perform imputation with KalmanSmooth and user created model
usermodel <- arima(tsAirgap, order = c(1, 0, 1))$model
na_kalman(tsAirgap, model = usermodel)

Thanks for your question 👍 Maybe it a good idea to think about providing more information with the output itself. (to avoid this kind of workarounds) I'll keep this in mind for future versions.

SteffenMoritz commented 4 years ago

Just as an addition:

Parameters from auto.arima will also be forwarded, if you supply them to na_kalman.

So you could also call: na_kalman(tsAirgap, model ="auto.arima", seasonal = F)

You would get a different model then before. seasonal is a parameter from forecast::auto.arima - which restricts to non-seasonal models when set false.

auto.arima(tsAirgap, seasonal = F)

ARIMA(0,1,4)

Coefficients: ma1 ma2 ma3 ma4 0.3683 -0.1873 -0.2327 -0.5088 s.e. 0.0901 0.0992 0.0726 0.1025

sigma^2 estimated as 785.4: log likelihood=-625.33 AIC=1260.65 AICc=1261.09 BIC=1275.47

As you can see at the results, this now finds a different (in this case way worse model).