EDITED: See below for additional information..
TL;DR: How can I add missing data in a dataset like the sample in a way that it doesn't deviate much from the original dataset.
I have a question about the mice package.
I am looking at a dataset like the example code:
set.seed(1337) df <- data.frame(x = c(seq(100, 10, -4), seq(100, 20, -3), seq(100, 60, -3), seq(80, 40, -3), seq(100, 10, -3))) %>% data.table() df[sample(seq_len(nrow(df)), size = nrow(df) * 0.3), x := NA] df$y <- seq(1,nrow(df),1) Tmp <- mice(df, m = 1, maxit = 30, seed = 1337, print = FALSE) Completed <- mice::complete(Tmp, 1) plot(df$y, df$x, col = "blue") points(Completed[is.na(df$x), ]$y, Completed[is.na(df$x), ]$x, col = "red") legend(70, 30, legend = c("actual", "pred"), col = c("blue", "red"), lty = 1, cex = 0.5)
I am trying to fit the missing data points, but as you can see in the image below, the fit (red) isn't like I want it to be, because I would expect it to appear in between the blue line. Would anyone know how to 'fix' this?
For clearance: The data on the x-axis is interpreted as a datetime object while the value on the right is the current battery level (in percentage) of ONE device. The points where the blue dotted line stops and starts at a higher number is when the battery is charged.
However it gave an issue when I tried to implement it with the real data set, because it threw an error:
Error in scale.default(xcomplete, dm[i, ], FALSE) : length of 'center' must equal the number of columns of 'x'
> sessionInfo() R version 3.4.4 (2018-03-15) Platform: x86_64-redhat-linux-gnu (64-bit) Running under: CentOS release 6.9 (Final) attached base packages:  grid stats graphics grDevices utils datasets methods base other attached packages:  lubridate_1.3.3 zoo_1.7-12 tidyr_0.6.0 pROC_1.13.0 randomForest_4.6-14 DMwR_0.4.1 lattice_0.20-35 stringr_1.0.0  openxlsx_3.0.0 tictoc_1.0 data.table_1.10.4-3 wlhive_1.1.9003 ggplot2_1.0.1 dplyr_0.5.0