impute_datamatrix(data_matrix, measurements_per_day, imputation_iterations)
imputation_iterations
, since Amelia's values are already averaged over five runs.This function uses Amelia::amelia
to try and impute missing (NA
) values in the input data set. Amelia averages over five iterations, which is multiplied by the given imputation_iterations
parameter.
# create a matrix with some missing values data_matrix <- matrix(nrow = 40, ncol = 3) data_matrix[, ] <- runif(ncol(data_matrix) * nrow(data_matrix), 1, nrow(data_matrix)) while (sum(is.na(data_matrix)) == 0) data_matrix[as.logical(round(runif(ncol(data_matrix) * nrow(data_matrix), -0.3, 0.7)))] <- NA colnames(data_matrix) <- c('rumination', 'happiness', 'activity') data_matrixrumination happiness activity [1,] 28.379772 2.247946 2.875802 [2,] 26.384591 2.655619 18.488865 [3,] 14.074625 37.948101 15.893832 [4,] 10.290650 NA NA [5,] 30.463038 35.654354 28.694388 [6,] 17.283237 30.217696 35.481986 [7,] 12.700646 NA 10.279747 [8,] 1.582495 21.629129 3.823699 [9,] 34.407750 17.982508 20.512482 [10,] NA 7.367465 25.016639 [11,] 39.518390 13.884480 9.447187 [12,] 5.718213 26.132050 1.230684 [13,] 30.978108 NA 32.731758 [14,] 7.564082 12.442560 11.580015 [15,] 21.211028 25.327510 31.195891 [16,] 23.910214 35.420652 11.226382 [17,] 30.435484 NA 28.089203 [18,] 35.343077 9.626838 19.046390 [19,] 15.829411 4.272897 NA [20,] 1.968350 4.900136 12.862822 [21,] 12.458404 25.685741 21.902219 [22,] 24.853330 23.470764 38.269463 [23,] 19.860251 28.993162 37.072521 [24,] 4.122257 22.132763 NA [25,] 37.835233 9.979503 24.537984 [26,] 13.671059 8.322604 29.463075 [27,] 31.759748 28.844447 6.367849 [28,] 19.993085 29.550783 6.416834 [29,] 39.867275 32.767868 32.737602 [30,] 21.264485 33.523859 NA [31,] 37.518187 16.655839 37.937473 [32,] 35.341468 30.598152 16.309589 [33,] NA 19.426316 22.335161 [34,] 30.617530 NA 13.790364 [35,] 37.150630 33.155959 8.209671 [36,] 8.149042 16.182142 18.651366 [37,] 17.074136 37.349179 31.786228 [38,] 1.417276 8.684127 NA [39,] NA 10.654564 34.781826 [40,] 18.779114 6.436800 23.946464autovarCore:::impute_datamatrix(data_matrix, 1, 30)rumination happiness activity [1,] 28.379772 2.247946 2.875802 [2,] 26.384591 2.655619 18.488865 [3,] 14.074625 37.948101 15.893832 [4,] 10.290650 29.576743 33.737036 [5,] 30.463038 35.654354 28.694388 [6,] 17.283237 30.217696 35.481986 [7,] 12.700646 41.780628 10.279747 [8,] 1.582495 21.629129 3.823699 [9,] 34.407750 17.982508 20.512482 [10,] 19.878392 7.367465 25.016639 [11,] 39.518390 13.884480 9.447187 [12,] 5.718213 26.132050 1.230684 [13,] 30.978108 20.019288 32.731758 [14,] 7.564082 12.442560 11.580015 [15,] 21.211028 25.327510 31.195891 [16,] 23.910214 35.420652 11.226382 [17,] 30.435484 22.130368 28.089203 [18,] 35.343077 9.626838 19.046390 [19,] 15.829411 4.272897 14.171567 [20,] 1.968350 4.900136 12.862822 [21,] 12.458404 25.685741 21.902219 [22,] 24.853330 23.470764 38.269463 [23,] 19.860251 28.993162 37.072521 [24,] 4.122257 22.132763 34.998007 [25,] 37.835233 9.979503 24.537984 [26,] 13.671059 8.322604 29.463075 [27,] 31.759748 28.844447 6.367849 [28,] 19.993085 29.550783 6.416834 [29,] 39.867275 32.767868 32.737602 [30,] 21.264485 33.523859 22.295313 [31,] 37.518187 16.655839 37.937473 [32,] 35.341468 30.598152 16.309589 [33,] 23.825883 19.426316 22.335161 [34,] 30.617530 22.362537 13.790364 [35,] 37.150630 33.155959 8.209671 [36,] 8.149042 16.182142 18.651366 [37,] 17.074136 37.349179 31.786228 [38,] 1.417276 8.684127 54.714003 [39,] 26.359255 10.654564 34.781826 [40,] 18.779114 6.436800 23.946464