小鼠的直方图在R中多重估算变量

发布于 2025-01-24 11:33:43 字数 544 浏览 0 评论 0原文

使用小鼠软件包将丢失的数据算后,我正在寻找一种使用一个估算变量之一的直方图绘制分布的方法。我可以使用以下代码来绘制“臭氧”的分布,但是每个估算的数据集(总共5个)的直方图。

我正在寻找一种创建1个直方图的方法,这是5个直方图的“汇总”结果,如果可能的话。类似于您如何汇总回归系数的如何归纳数据集,以获取系数的最终摘要。

# Example dataset
data <- airquality

# Add missing data
data[4:10,3] <- rep(NA,7)
data[1:5,4] <- NA
data <- data[-c(5,6)]

# Impute missing data creating 5 datasets 
imp <- mice::mice(data,m=5,maxit=50,meth='pmm',seed=500)

# Plot distribution of "Ozone" - Results in 5 plots, Aim is one "pooled" histogram
with(imp, hist(Ozone))

After using the MICE package to impute missing data I am looking for a way to plot the distribution, using a histogram, of one of the imputed variables. I can use the following code to plot the distribution of "Ozone", however one histogram per imputed dataset (5 in total) is produced.

I am looking for a way to create 1 histogram which is the "pooled" result of the 5 histograms, if this is possible. Similar to how you would pool regression coefficients from MICE imputed datasets to get a final summary for the coefficients.

# Example dataset
data <- airquality

# Add missing data
data[4:10,3] <- rep(NA,7)
data[1:5,4] <- NA
data <- data[-c(5,6)]

# Impute missing data creating 5 datasets 
imp <- mice::mice(data,m=5,maxit=50,meth='pmm',seed=500)

# Plot distribution of "Ozone" - Results in 5 plots, Aim is one "pooled" histogram
with(imp, hist(Ozone))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

给我一枪 2025-01-31 11:33:43

您可以使用函数merge_imputations合并归档。您可以使用以下代码:

# Example dataset
data <- airquality

# Add missing data
data[4:10,3] <- rep(NA,7)
data[1:5,4] <- NA
data <- data[-c(5,6)]

# Impute missing data creating 5 datasets 
imp <- mice::mice(data,m=5,maxit=50,meth='pmm',seed=500)

# merge imp
merged_imp <- merge_imputations(data, imp)

# Plot distribution of "Ozone" - Results in 5 plots, Aim is one "pooled" histogram
with(merged_imp, hist(Ozone))

输出:

”在此处输入图像描述”

You can use the function merge_imputations to merge the imputations. You can use the following code:

# Example dataset
data <- airquality

# Add missing data
data[4:10,3] <- rep(NA,7)
data[1:5,4] <- NA
data <- data[-c(5,6)]

# Impute missing data creating 5 datasets 
imp <- mice::mice(data,m=5,maxit=50,meth='pmm',seed=500)

# merge imp
merged_imp <- merge_imputations(data, imp)

# Plot distribution of "Ozone" - Results in 5 plots, Aim is one "pooled" histogram
with(merged_imp, hist(Ozone))

Output:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文