【问题标题】:Role of raw data in pooled estimates from mice (R package)?原始数据在小鼠汇总估计中的作用(R 包)?
【发布时间】:2019-01-24 18:05:02
【问题描述】:

我想知道在 R 中使用mice 包来估算数据时,原始数据集的作用是什么。在将长数据集转换回 as.mids 对象之前,我需要估算我的数据,然后计算一些额外的变量。我注意到,在计算我的附加变量(下面代码中的“总计”)时,无论我使用 na.rm=TRUE 是否受到估计和我的理解的影响,它都不应该。这是一个可重现的示例:

# Add required package 
 require(mice)

# Impute data and compute summary with na.rm=T 
 imp1 <- mice(nhanes, seed = 123) 
 com1 <- complete(imp1, "long", include = TRUE) 
 head(com1) 
 com1$total <- rowSums(com1[4:6],na.rm=T)
 imp2 <- as.mids(com1)

# Fit model with data using na.rm=T 
 fit <- with(imp2, lm(bmi ~ age)) 
 round(summary(pool(fit)), 2)

请注意,我的变量“total”是 3 个变量的 rowSums,我使用了 na.rm=TRUE。但是,由于只有原始数据集(由长数据集中的变量“.imp”表示)包含 NA 值,所以这额外的代码应该只与原始数据相关。删除na.rm=TRUE 表明这是不正确的:

# Impute data and compute summary without na.rm=T 
 imp3 <- mice(nhanes, seed = 123) 
 com2 <- complete(imp3, "long", include = TRUE) 
 head(com2) 
 com2$total <- rowSums(com2[4:6]) 
 imp4 <- as.mids(com2)

# Fit model with data without using na.rm=T 
fit2 <- with(imp4, lm(bmi ~ age)) 
round(summary(pool(fit2)), 2)

再次注意,省略 na.rm=TRUE 会导致不同的估计值。此处唯一的区别是,当变量 .imp 等于 0(即原始数据集)时,变量“total”现在具有 NA 值。

我错过了什么?我会认为只有估算数据会影响汇总估计,而我只是表明原始数据集中的值会影响(即来自 .imp = 0 的值)。原始数据集在从小鼠中获取汇总估计值中的作用是什么?

注意:为清晰起见编辑

【问题讨论】:

    标签: r missing-data imputation r-mice


    【解决方案1】:

    我认为原始(原始)数据不起作用。根据as.mids 帮助页面,它只需要指明丢失数据的位置。我运行了您的脚本,发现创建 imp2 时出现错误。你调用对象com,它应该是com1。校正后,两种方法的结果完全相同:

    # Add required package 
    require(mice)
    
    # Impute data and compute summary with na.rm=T 
    imp1 <- mice(nhanes, seed = 123) 
    com1 <- complete(imp1, "long", include = TRUE) 
    head(com1) 
    com1$total <- rowSums(com1[4:6],na.rm=T)
    imp2 <- as.mids(com1)
    
    # Fit model with data using na.rm=T 
    fit <- with(imp2, lm(bmi ~ age)) 
    
    # Impute data and compute summary without na.rm=T 
    imp3 <- mice(nhanes, seed = 123) 
    com2 <- complete(imp3, "long", include = TRUE) 
    head(com2) 
    com2$total <- rowSums(com2[4:6]) 
    imp4 <- as.mids(com2)
    
    # Fit model with data without using na.rm=T 
    fit2 <- with(imp4, lm(bmi ~ age)) 
    

    结果:

    > round(summary(pool(fit)), 2)
                estimate std.error statistic    df p.value
    (Intercept)    29.76      1.86     15.98 18.61    0.00
    age            -1.73      0.95     -1.83 19.50    0.08
    
    > round(summary(pool(fit2)), 2)
                estimate std.error statistic    df p.value
    (Intercept)    29.76      1.86     15.98 18.61    0.00
    age            -1.73      0.95     -1.83 19.50    0.08
    

    简而言之,我认为不同的结果可能是由于您的代码中的错误。我用mice 3.0.9

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      • 2017-10-26
      • 1970-01-01
      相关资源
      最近更新 更多