# How to best impute missing values of county-level time series data using R?

I have a dataset consisting of mobility data at the county-level for the US for about one year. So the number of observations is >1m. Apart from the county code, the date, and the mobility index, the dataset also has a number of socio-economic variables at the county level, which do not vary temporally (i.e. there is one single value for all day-county combinations) and also do not have any missing values. The mobility data contain a lot of missing values clustered both temporally and spatially, meaning that some counties have more missing values than others and some days have more missing values than others.

I'm looking for an imputation method that takes into account temporal, spatial correlation as well as the association with some sociodemographic county-level variables such as income, education, and so forth. I'm thinking that multiple imputation would be the way to go (like Hmisc or mice) but how would I incorporate the spatial and temporal correlation? Is there an R package that does what I'm looking for?

• This is a rich and extraordinarily complex situation. Details--concerning the types and amounts of data, reasons for missingness, patterns of missingness, and spatio-temporal dependence structures--are needed even to begin narrowing the possible approaches.
– whuber
Jun 9, 2021 at 16:11

The Amelia R package fits a quite simple Bayesian model (with a latent multivariate normal distribution in the background that gets used to construct categorical and ordinal variables, too) that often does a nice job of creating multiple imputations. One could probably give it categorical predictors (e.g. counties), variables that construct time patterns (e.g. sine(day/period), cosine(day/period) for different choice of period) and spatial patterns, and then try to use its time series option. However, I have to admit that I've usually struggled to get it to work well with time series (I've got really sensible imputations for non-time series tabular data from it though, so definitely worth knowing, if you have not looked at it before).