我使用MICE
套餐来计算金融时间序列数据(外汇汇率)中的缺失值。
mice()
估算对我的所有数据集都有效,除了一个。我尝试使用mice()
时出现以下错误:
Error in cor(xobs[, keep, drop = FALSE], use = "all.obs") : 'x' is empty
我试过通过以下方法解决问题:
但上述方法让我没有结果。
以下是一个可重复的示例:
#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 in cor(xobs[, keep, drop = FALSE], use = "all.obs") : 'x' is empty