Solved – Missing values imputation of time series using na.kalman command

arimadata-imputationmissing datartime series

I have a time series for daily records of concentration of Total Phosphorus (TP) in a riiver and the water flow in the year of 2014. While I have complete data for the flow variable, I have missing values for the TP variable. I am trying to impute the missing values of the TP variable based on an AR(1) model for TP with the flow variable as an external regressor. The model is programmed in R as:
ts1=arima(TP, order = c(1,1,0), xreg=F)

I came across imputeTS package on R and tried the command na.kalman. I want my model ts to be used hence I used the argument model in the command as follows:

na.kalman(TP, model = "ts")

This method does not seem to be working as I get the error

Error in na.kalman(tp1, model = "ts1_") : Parameter model has either to be "StructTS"/"auto.arima" or a user supplied model in form of a list with at least components T, Z, h , V, a, P, Pn specified

What did I do wrong here? How can I use the command na.kalman and to make it make use my ARIMA model?

Best Answer

You need to pass it the model and not a string:

ts1=arima(TP, order = c(1,1,0), xreg=F)

na.kalman(TP, model = ts1$model)