I'm trying to fill in NA values with numbers that show exponential growth. Below is a data sample of what I'm trying to do.
library(tidyverse)
expand.grid(X2009H1N1 = "0-17 years",
type = "Cases",
month = seq(as.Date("2009-04-12") , to = as.Date("2010-03-12"), by = "month")) %>%
bind_cols( data.frame(
MidLevelRange = c(0,NA,NA,NA,NA,NA,8000000,16000000,18000000,19000000,19000000,19000000),
lowEst = c(0,NA,NA,NA,NA,NA,5000000,12000000,12000000,13000000,14000000,14000000)
))
I have used %>% arrange(month, X2009H1N1) %>%
group_by(X2009H1N1, type ) %>%
mutate(aprox_MidLevelRange = zoo::na.approx(MidLevelRange, na.rm = FALSE)) but the result does not look exponential to me. Thanks
Have a look at the imputeTS package. It offers plenty of imputation functions for time series. Take a look at this paper to get a good overview of all offered options
In your case using Stineman interpolation (
imputeTS::na_interpolation(x, option ="stine") could maybe be a suitable option.Here for the example you provided:
This gives you:
So just comparing interpolation functions I guess this could be the best option.
Just plot yourself the different interpolation options, to see the differences. In general this are the interpolation options:
linear / spline options from imputeTS are the same as zoo::approx()/ zoo::spline(). stine does not exist in zoo.