0

I am using the MICE package to impute missing values in financial time series data (Foreign Exchange Rates).

The mice() imputation worked fine for all my data sets except one. I get the following error when I try to use mice():

Error in cor(xobs[, keep, drop = FALSE], use = "all.obs") : 'x' is empty

I have tried fixing the problem by:

  • Changing the format of the data to array and a matrix
  • Taking subsets of the data.

But the above approaches have got me no results.

Here is a reproducible example:

#library used
library(mice)

#Generate dataset
Repdata <- matrix(data = c(1    , 40546,  0.0016,   -0.0053,    -0.0003, -0.0012,  0.0012,   0.0051, -0.0005,   -0.0008,  0.0057, -0.0068,
                       2    , 40547,  0.012 ,  0.0047,   0.0139,  NA      ,  0.0026,    -0.0073, -0.0001,    0.0087,  0.0058, -0.0049,
                       3    , 40548,  0.0067,    0.0009,     0.0157, -0.0009,  0.0118,   0.0047,  0.0003,    0.0079,  0.0102,   0.0006,
                       4    , 40549,  0.0045,   -0.0022,     0.0046,  0.0037,  0.0106,   0.0029,  0.0004,   -0.0022,  0.0041, -0.0017,
                       5    , NA,     0.0007,   -0.0027,     NA   ,   0.0002,  0.0073,  -0.0023, -0.0003,    0.0023,  0.0003,   0.0019,
                       6    , 40551,  0.0005,    0.0006,     0.0005,  NA      ,  NA    ,    0.001,  NA    , -0.0013,  0.0013,   0.0001,
                       7    , 40553,  0.0014,    0.0008,     0.0008,  0.0009, -0.0004,  -0.0031,  0.0006,    0.0029, -0.0059,   0.0016,
                       8    , 40554,  0.0069,   -0.0034,     0.0052, -0.002 , -0.0024,  -0.0029, -0.0001,   -0.007 , 0.0045 , -0.005,
                       9    , 40555,  NA    ,   -0.0046,    -0.0018, -0.0028, -0.0085,  -0.0059, -0.0003,   -0.0017, -0.0003,   NA,
                       10   , 40556, -0.0057,    0.0026,    -0.0038,  0.0001, -0.0185,  -0.0086,  NA      ,  0.0013, -0.0045,   0.0003), nrow = 10, byrow = TRUE)

 #Impute missing values:
 mice(Repdata)

Error:

Error in cor(xobs[, keep, drop = FALSE], use = "all.obs") : 'x' is empty
Spacedman
  • 92,590
  • 12
  • 140
  • 224
Schalk Burger
  • 58
  • 1
  • 11
  • [This](https://stackoverflow.com/questions/38153385/unclear-error-with-mice-package) can help – nghauran Nov 21 '17 at 08:09
  • Thanks @ANG. I looked at that specific, but there is no clear answer from that question. – Schalk Burger Nov 21 '17 at 08:33
  • Of course, but you sould provide a minimal [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? Try to use a subset of your data. – nghauran Nov 21 '17 at 08:42
  • My best bet is that the correlation between V1 and V2 is simply too high (almost perfectly correlated, r = .9975) which causes the algorithm to break down somehow as V2 is perfectly predicted by V1. Omitting V2 from the dataset clears the error. – Niek Nov 21 '17 at 10:02
  • Do you need to impute V2? It's clear that the missing value in the example is 40550. If your real data contains a variable like this I suggest removing it and then imputing. – Niek Nov 21 '17 at 10:15
  • @Niek this is just an example (mtcars), but in my real data I need to impute all the variables. I am testing imputation methods and have done almost all of the imputations I have come accross. – Schalk Burger Nov 21 '17 at 10:28
  • Have you looked into the correlations between the variables in your dataset? Maybe the error is caused by a similar problem – Niek Nov 21 '17 at 10:32
  • @Niek, yes I have. The biggest correlation is 0,66. I cannot think that this is big enough to be deleted. – Schalk Burger Nov 21 '17 at 10:35

0 Answers0