【问题标题】:Using imputed datasets from library mice() to fit a multi-level model in R使用来自 library mouse() 的估算数据集来拟合 R 中的多级模型
【发布时间】:2021-02-20 10:00:08
【问题描述】:

我是在 R 中打包 mice 的新手。但我试图从 popmis 中估算 5 个数据集,然后分别拟合 lmer() 模型 with(),最后在它们之间拟合 pool()

我认为mice() 中的pool() 函数不适用于来自lme4 包的lmer() 调用,对吧?

如果是这样的话,有没有办法为我下面的情况编写一个类似于pool() 的定制函数?

library(mice)
library(lme4)

imp <- mice(popmis, m = 5) # `popmis` is a dataset from `mice`

fit <- with(imp, lme4::lmer(popular ~ sex + (1|school))) # works fine.

pool(fit) # BUT this one fails, should I loop here?

【问题讨论】:

    标签: r missing-data lme4 imputation r-mice


    【解决方案1】:

    我有你的解决方案。它就像install.packages("broom.mixed") 一样简单,然后library(broom.mixed).broom.mixed 包提供了正确的glance 方法

    # install.packages("broom.mixed")
    library(mice)
    library(lme4)
    library(broom.mixed)
    imp <- mice(popmis, m = 5) # `popmis` is a dataset from `mice`
    
    fit <- with(data = imp, exp = lme4::lmer(popular ~ sex + (1|school)))
    
    pool(fit) 
    

    结果:

    > pool(fit)
    Class: mipo    m = 5 
             term m  estimate        ubar            b           t dfcom       df        riv     lambda        fmi
    1 (Intercept) 5 4.9122016 0.007589694 0.0003823641 0.008048531  1996 743.8691 0.06045526 0.05700878 0.05953397
    2         sex 5 0.8378947 0.001187606 0.0002937859 0.001540149  1996  72.7305 0.29685175 0.22890184 0.24926611
    

    Ben Bolker is the author of broom.mixed

    【讨论】:

    • 但是与解决方案中的随机效应相关的ubar 应该只显示(intercept) 而不是sex(因为模型只对intercept 有随机效应),什么是在这里进行吗?
    • @BenBolker 是 broom.mixed 的作者。对我来说,虽然我不是混合模型方面的专家,但它看起来还不错。
    猜你喜欢
    • 2015-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-12
    • 2017-12-03
    • 2018-11-16
    • 1970-01-01
    相关资源
    最近更新 更多