0
$\begingroup$

I am trying to impute missing timeseries present in different dimentions, row by row, on the whole date set. I showed the type of return of na.kalman() and it happens to be a tribble, I am not so keen on R, so I thought converting it to a plain vector will do it, something like array(as.data.frame(imputed_slice))

library("imputeTS")
library(readr)

slice <- read_csv("slice.csv")
little_slice <- slice[c(750: 850)]
for (row in 1:nrow(little_slice)) {
  ts <- little_slice[row,]
  if(any(is.na(ts)))
     {
       imputed_ts <- na.kalman(ts, model = "auto.arima")
       little_slice[row,] <- array(imputed_ts)
  }
}

#529, 811, 812 missings

Looking for warning, I see something like:

imputeTS: No imputation performed for column 64 because of this Error in na.kalman(data[, i], model, smooth, nit, ...): Input data needs at least 3 non-NA data point for applying na.kalman

For every row, so I tried to force other columns to be NA

Like this:

slice$`811` <- NA
slice$`812` <- NA
slice$`822` <- NA
slice$`832` <- NA

To sum up, why na.kalman() not recognizing my NAs?

$\endgroup$
0
$\begingroup$

I made it work by coercing the timeserie to numerics

little_slice <- slice[c(750: 850)]
for (row in 1:nrow(little_slice)) {
  ts <- as.numeric(little_slice[row,])
  if(any(is.na(ts)))
     {
       imputed_ts <- na.kalman(ts, model = "auto.arima")
       little_slice[row,] <- imputed_ts
  }
}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.