首页 > 解决方案 > 圆形功能不再适用于鼠标输出

问题描述

由于将 R 更新到 4.0.0 并重新安装mice,该round()功能似乎不再适用于鼠标输出,但会产生错误消息。

例如(使用 iris 数据集):

library(missForest) # for the prodNA function
library(mice)       # for the imputations

#Creating dataset with missing values (NAs)
iris.mis <- prodNA(iris, noNA = 0.1)
head(iris.mis)

#Imputation
imputed_data <- mice(data = iris.mis, m = 5, method = "pmm", 
    maxit = 50, seed = 500)
model <- with(data = imputed_data, lm(Sepal.Length ~ Sepal.Width))
round(summary(pool(model), conf.int = TRUE, exponentiate = TRUE), 2)

这会产生错误消息:

Math.data.frame 中的错误(列表(术语 = 1:2,估计 = c(760.13466726231,:数据框中的非数字变量:术语)

使用summary(pool(model), conf.int = T, exponentiate = T)效果很好。

在更新 R 和鼠标之前,我从来没有遇到过 R 中的 round 函数的问题。

标签: rroundingr-mice

解决方案


我不知道为什么会发生这种变化,但是老鼠的新闻文件 在 3.8 版中说

现在有一个更灵活的pool()功能,可以更好地与broombroom.mixed包集成。

将行名改为列是有道理的,因为这与 tidyverse 机制(如and )term更兼容。broombroom.mixed

您可以要求 R 舍入除第一列之外的所有列:

ss <- summary(pool(model), conf.int = TRUE, exponentiate = TRUE)
ss[-1] <- round(ss[-1],2)
ss
##          term estimate std.error statistic     df p.value  2.5 %  97.5 %
## 1 (Intercept)   670.98      0.48     13.69 143.68    0.00 262.19 1717.15
## 2 Sepal.Width     0.80      0.15     -1.44 143.36    0.15   0.59    1.09

如果你喜欢 tidyverse,你可以

mutate_if(ss,is.numeric, round, 2)

推荐阅读