当前位置:网站首页>R 笔记 MICE
R 笔记 MICE
2022-07-28 02:12:00 【UQI-LIUWJ】
1 MICE 算法理论部分
MICE(Multiple Imputation by Chained Equations)是一种处理数据集中缺失数据的稳健、信息丰富的方法。 该过程通过一系列迭代的预测模型“填充”(估算)数据集中的缺失数据。
在每次迭代中,数据集中的每个指定变量都使用数据集中的其他变量进行估算。 不断迭代在,直至收敛。
1.1 MICE举例

上述这个过程一直持续到所有指定的变量都被插补。 如果没有收敛,则可以运行额外的迭代,尽管通常不超过 5 次迭代是必要的。
插补的准确性取决于数据集中的信息密度。 没有相关性的完全独立变量的数据集不会产生准确的插补。
1.2 PMM,Predictive Mean Matching
MICE 可以使用称为预测均值匹配 (PMM) 的程序来选择要估算的值。 PMM 从原始非缺失数据中选择一个数据点,该数据点的预测值接近缺失样本的预测值。
选择最接近的 N个数据点作为候选值,从中随机选择一个值来进行补全。

2 R语言MICE
2.0 导入包
library(magrittr)
library(dplyr)
library(mice)
library(missForest)2.1 导入数据
data(iris)
summary(iris)
# Sepal.Length Sepal.Width Petal.Length
# Min. :4.300 Min. :2.000 Min. :1.000
# 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600
# Median :5.800 Median :3.000 Median :4.350
# Mean :5.843 Mean :3.057 Mean :3.758
# 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100
# Max. :7.900 Max. :4.400 Max. :6.900
# Petal.Width Species
# Min. :0.100 setosa :50
# 1st Qu.:0.300 versicolor:50
# Median :1.300 virginica :50
# Mean :1.199
# 3rd Qu.:1.800
# Max. :2.500
2.2 随机丢失一定量数据
随机在数据里产生 10% 的 缺失值。同时把 Species 这个分类变量也去掉。
iris_mis <- missForest::prodNA(iris, noNA = 0.1) %>% select(-Species)
summary(iris_mis)
# Sepal.Length Sepal.Width Petal.Length
# Min. :4.300 Min. :2.000 Min. :1.000
# 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.500
# Median :5.800 Median :3.000 Median :4.300
# Mean :5.856 Mean :3.049 Mean :3.707
# 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100
# Max. :7.900 Max. :4.200 Max. :6.900
# NA's :16 NA's :15 NA's :7
# Petal.Width
# Min. :0.100
# 1st Qu.:0.300
# Median :1.300
# Mean :1.201
# 3rd Qu.:1.800
# Max. :2.500
# NA's :13 2.3 可视化缺失数据
md.pattern(iris_mis)
表达的意思是Petal.Length一共7个missing 数据,其中两个和第二列的Petal.Weight在同样的坐标处丢失数据;剩下5个只有在自己的坐标处丢失数据。
2.4 进行补全
imputed_Data <- mice(iris_mis, m=5, maxit = 50, method = 'pmm', seed = 123)- m = 5 ,表示生成 5 组填补好的数据
- maxit = 50,每次产生填补数据的迭代次数,这里取 50 次
- method = ‘pmm’,使用1.2介绍的 Predictive Mean Matching 的方法(连续型数据采用之)
2.5 查看数据
由于我们这边生成了5组数据,所以可以一组一组查看
completeData <- mice::complete(imputed_Data,2)后面这个2就表示查看哪一组的数据
边栏推荐
猜你喜欢

Docker高级篇-Docker容器内Redis集群配置

微服务架构统一安全认证设计与实践
[email protected] Annotation usage"/>[email protected] Annotation usage

MySQL index learning

JVM 内存布局详解,图文并茂,写得太好了!

Es6.--promise, task queue and event cycle

Skills in writing English IEEE papers

Some shortest path problems solved by hierarchical graph

How do gateways and chirpstacks in lorawan communicate? UDP? GRPC? MQTT?

别再用 offset 和 limit 分页了,性能太差!
随机推荐
JS event object 2 e.charcode character code e.keycode key code box moves up, down, left and right
CSDN TOP1“一个处女座的程序猿“如何通过写作成为百万粉丝博主?
PS simple to use
Skills in writing English IEEE papers
Es6.--promise, task queue and event cycle
One month's experience of joining Huawei OD
MySQL essay
How do gateways and chirpstacks in lorawan communicate? UDP? GRPC? MQTT?
JS event object offsetx/y clientx y pagex y
嵌入式分享合集22
Digital twin agriculture - Smart agriculture rice processing plant has changed from "watching the sky to eat" to "knowing the sky to work"
tfx airflow 使用体验
Day 8 of DL
使用PyTorch的TensorBoard-可视化深度学习指标 | PyTorch系列(二十五)
Data Lake: flume, a massive log collection engine
Center Based 3D object detection and tracking (centerpoint) paper notes
[wechat applet development (V)] the interface is intelligently configured according to the official version of the experience version of the development version
[stream] parallel stream and sequential stream
Deep residual learning for image recognition shallow reading and Implementation
“29岁,普通功能测试,我是如何在一周内拿到5份Offer的?”