business-science / timetk

Time series analysis in the `tidyverse`
https://business-science.github.io/timetk/
613 stars 101 forks source link

Spline Interpolation #161

Open shadrackmunene opened 9 months ago

shadrackmunene commented 9 months ago

Dear team, There is a function in timetk ts_impute_vec which is useful for imputing missing or outlier values in time series. The function uses linear interpolation which is a bit subjective at times as it will give extreme values if the data has outliers. My recommendation is you also consider other forms of interpolation like the spline interpolation which comes in handy in cases where the continuity of the time series curvature is important.

Current anyone interested in spline interpolation implement via library(zoo) as below

library(zoo) 
ts_data %>%
    # Via spline interpolation
    mutate(value_spline=ifelse(is.na(value),na.spline(value),value))%>%
    # Or the below using ys_impute vec
    mutate(value_linear=ifelse(is.na(value),ts_impute_vec(value,period=1),value))