本文介绍了对来自小鼠(R)的估算数据子集运行glm.mids的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在mids插补对象的子集上运行glm.mids时出现错误:

I get an error when I try to run glm.mids on a subset of a mids imputation object:

library(mice)
imp2 = mice(nhanes)
glm.mids( (hyp==2)~bmi+chl, data=imp2, subset=(age==1) )

给出了错误的错误消息

"Error in eval(expr, envir, enclos) :
..1 used in an incorrect context, no ... to look in"

即使该语法与原始数据集上的常规glm兼容:

even though the syntax works with regular glm on the original dataset:

glm( (hyp==2)~bmi+chl, data=nhanes, subset=(age==1) )

文档?glm.mids并没有专门介绍subset,但是说您可以将其他参数传递给glm.如果我不能将subsetglm.mids一起使用,是否有直接将mids列表对象子集的好方法?

The documentation ?glm.mids doesn't specifically address subset but says that you can pass additional parameters onto glm. If I can't use subset with glm.mids, is there a good way to subset the mids list object directly?

推荐答案

我已经自由地重写了glm.mids.这有点糊涂.问题似乎源于将属性传递给glm的隐式本质.

I have taken the liberty of rewriting glm.mids. It is a bit kludgy. The issue seems to stem from the implicit nature by which attributes are passed into glm.

另请参阅以下帖子:

https://stat.ethz.ch/pipermail/r-help/2003-November/041537.html

http://r.789695.n4.nabble.com/Question-on-passing-the-subset-argument-to-an-lm-wrapper-td3009725.html

library(mice)

glm.mids=function (formula, family = gaussian, data, ...) 
{
  call <- match.call()
  if (!is.mids(data)) 
    stop("The data must have class mids")
  analyses <- as.list(1:data$m)
  for (i in 1:data$m) {
    data.i <- complete(data, i)
    analyses[[i]] <- do.call("glm",list(formula=quote(formula),family=quote(family),data=quote(data.i),...))
  }
  object <- list(call = call, call1 = data$call, nmis = data$nmis, 
                 analyses = analyses)
  oldClass(object) <- c("mira", "glm", "lm")
 return(object)
}

imp2 = mice(nhanes)
glm.mids( (hyp==2)~bmi+chl, data=imp2 ,subset=quote(age==1))

我重写的唯一部分是glm.mids analyses[[i]] <- do.call("glm",list(formula=quote(formula),family=quote(family),data=quote(data.i),...))

The only part that I rewrote was the glm function call within glm.mids analyses[[i]] <- do.call("glm",list(formula=quote(formula),family=quote(family),data=quote(data.i),...))

在旧版本中,它显示为analyses[[i]] <- glm(formula, family = family, data = data.i,...)

In the old version it read analyses[[i]] <- glm(formula, family = family, data = data.i,...)

这篇关于对来自小鼠(R)的估算数据子集运行glm.mids的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 03:07