我有一个时间序列数据集,其中有一些缺失值。我希望估算缺失值,但我不确定哪种方法最合适,例如imputeTS
包中的线性、样条或斜线。
为了完整起见,我希望测试我的数据是否是 MCAR、MAR、NMAR。我很清楚它是 MCAR,但我有兴趣进行测试。
str(wideRawDF)
'data.frame': 1343 obs. of 13 variables:
$ Period.Start.Time: POSIXct, format: "2017-01-20 16:30:00" "2017-01-20 16:45:00" "2017-01-20 17:00:00" "2017-01-20 17:15:00" ...
$ DO0182U09A3 : num -102 -101 -101 -101 -101 ...
$ DO0182U09B3 : num -103.4 -102.8 -103.3 -95.9 -103 ...
$ DO0182U09C3 : num -103.9 -104.2 -103.9 -99.2 -104.1 ...
$ DO0182U21A1 : num -105 -105 -105 -104 -102 ...
$ DO0182U21A2 : num -105 -104 -105 -105 -105 ...
$ DO0182U21A3 : num -105 -105 -105 -105 -105 ...
$ DO0182U21B1 : num -102 -103 -104 -104 -104 ...
$ DO0182U21B2 : num -99.4 -102 -104 -101.4 -104.1 ...
$ DO0182U21B3 : num -104 -104 -104 -104 -104 ...
$ DO0182U21C1 : num -105 -105 -105 -104 -105 ...
$ DO0182U21C2 : num -104 -105 -105 -103 -105 ...
$ DO0182U21C3 : num -105 -105 -105 -105 -105 ...
md.pattern(wideRawDF)
Period.Start.Time DO0182U21C1 DO0182U21C2 DO0182U21C3 DO0182U21B1 DO0182U21B2 DO0182U21B3 DO0182U09A3 DO0182U09B3 DO0182U09C3 DO0182U21A1 DO0182U21A2
1327 1 1 1 1 1 1 1 1 1 1 1 1
3 1 1 1 1 1 1 1 0 1 1 1 1
1 1 1 1 1 1 1 1 1 0 1 1 1
2 1 1 1 1 1 1 1 1 1 0 1 1
1 1 1 1 1 1 1 1 0 1 1 0 0
1 1 1 1 1 1 1 1 0 0 1 0 0
3 1 1 1 1 1 1 1 1 0 0 0 0
2 1 1 1 1 1 1 1 0 0 0 0 0
3 1 1 1 1 0 0 0 1 0 0 0 0
0 0 0 0 3 3 3 7 10 10 10 10
DO0182U21A3
1327 1 0
3 1 1
1 1 1
2 1 1
1 0 4
1 0 5
3 0 5
2 0 6
3 0 8
10 66
如您所见,我的 DF 中的某些列没有 NA 值。我希望只将具有 NATestMCARNormality
的列传递给 MissMech 包中的函数。
我尝试了以下方法,但我不断收到相同的错误:
> TestMCARNormality(wideRawDF[,3:4])
Warning: 8 Cases with all variables missing have been removed
from the data.
Warning: More than one missing data pattern should be present.
使用 colnames 我得到列的索引,我引用 md.pattern 的上述输出来确定我正在使用具有 NA 值的列。
> colnames(wideRawDF)
[1] "Period.Start.Time" "DO0182U09A3" "DO0182U09B3" "DO0182U09C3" "DO0182U21A1" "DO0182U21A2" "DO0182U21A3" "DO0182U21B1"
[9] "DO0182U21B2" "DO0182U21B3" "DO0182U21C1" "DO0182U21C2" "DO0182U21C3"
测试缺失值并仅将具有 NA 的列传递给TestMCARNormality
函数的聪明方法是什么?