【问题标题】:Round function no longer works with mice output圆形功能不再适用于鼠标输出
【发布时间】:2020-05-16 16:44:17
【问题描述】:

自从将 R 更新到 4.0.0 并重新安装 mice 后,round() 函数似乎不再适用于鼠标输出,但会产生错误消息。

例如(使用鸢尾花数据集):

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,: 数据框中的非数字变量:term

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

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

【问题讨论】:

    标签: r rounding r-mice


    【解决方案1】:

    我不知道为什么会发生这种变化,但 NEWS file for mice 在 3.8 版中说

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

    将行名改为term 列是有道理的,因为这与 tidyverse 机制更兼容(如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)
    

    【讨论】:

    • 看来 Stef "bugfixed" mice 3.8.0 通过扩展 pool 函数更同情 broom/tidyverse。所以我得出结论,我们不再有行名,而是这个“伟大的”term 变量。
    猜你喜欢
    • 2012-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-27
    • 2019-10-18
    • 2016-07-01
    • 1970-01-01
    • 2015-11-27
    相关资源
    最近更新 更多