简体   繁体   English

R 中的鼠标问题:无法将“mids”类强制转换为 data.frame

[英]problems with mice in R: cannot coerce class '“mids”' into a data.frame

I have a dataset with about 11,500 rows and 15 factors.我有一个包含大约 11,500 行和 15 个因子的数据集。 I only need to impute values for 3 of the factors, with only 2 of the factors having any significant number of missing values.我只需要估算 3 个因子的值,其中只有 2 个因子具有大量缺失值。 I have been trying to use mice to create imputed datasets, and I am using the following code:我一直在尝试使用鼠标来创建插补数据集,我正在使用以下代码:

dataset<-read.csv("filename.csv",header=TRUE)

model<-success~1+course+medium+ethnicity+gender+age+enrollment+HSGPA+GPA+Pell+ethnicity*medium

library(mice)

vempty<-c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
v12<-c(0,0,0,0,0,0,0,1,1,1,1,0,1,1,1)
v13<-c(0,0,0,0,0,0,0,1,1,1,1,1,0,1,1)
v14<-c(0,0,0,0,0,0,0,1,1,1,1,1,1,0,1)
list<-list(vempty,vempty,vempty,vempty,vempty,vempty,vempty,vempty,vempty,vempty,vempty,v12,v13,v14,vempty)
predmatrix<-do.call(rbind,list)


MIdataset<-mice(dataset,m=2,predictorMatrix=predmatrix)
MIoutput<- pool(glm(model, data=MIdataset, family=binomial))

After this code, I get the error message:在此代码之后,我收到错误消息:

Error in as.data.frame.default(data) : cannot coerce class '"mids"' into a data.frame as.data.frame.default(data) 中的错误:无法将类 '"mids"' 强制转换为 data.frame

I'm totally at a loss as to what this means.我完全不知道这意味着什么。 I had no trouble doing this same analysis just deleting the missing data and using regular glm.我做同样的分析没有问题,只是删除丢失的数据并使用常规 glm。 I'd also like to do a multilvel logistic model on imputed datasets using lmer (that's the next step after I get this to work with glm), so if there is anything I am doing wrong that will also impact that next step, that would be good to know, too.我还想使用 lmer 在估算数据集上做一个多级逻辑模型(这是我让它与 glm 一起工作后的下一步),所以如果我做错了什么也会影响下一步,那会也很高兴知道。 I've tried to search this error on the internet, and I'm not getting anywhere.我试图在互联网上搜索此错误,但一无所获。 I'm just really learning R, so I'm also not that familiar with the environment yet.我只是在真正学习 R,所以我对环境还不太熟悉。

Thanks for your time!感谢您的时间!

You need to apply the with.mids function.您需要应用with.mids函数。 I think the last line in your code should look like this:我认为你的代码中的最后一行应该是这样的:

pool(with(MIdataset, glm(formula(model), family = binomial)))池(与(MIdataset,glm(公式(模型),家庭=二项式)))

You could also try this:你也可以试试这个:

expr <- 'glm(success ~ course, family = binomial)'
pool(with(MIdataset, parse(text = expr)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将类别““ amelia””强制转换为R中的data.frame - Cannot coerce class “”amelia“” to a data.frame in R R-“无法将类别&#39;” msm.est”强制转换为data.frame” - R - “cannot coerce class ‘”msm.est“’ to a data.frame” 无法将类“ String”强制转换为data.frame - Cannot coerce class “”String“” to a data.frame 无法将类““ powerCurve””强制转换为data.frame - Cannot coerce class “”powerCurve“” to a data.frame 折叠 R 中的行:无法将“公式”类强制转换为 data.frame (R) - Collapsing Rows in R: cannot coerce class ‘"formula"’ to a data.frame (R) 视图中的错误:无法将 class '"infl"' 强制转换为 data.frame - 问题在于 `infl` class - R - Error in View : cannot coerce class ‘"infl"’ to a data.frame - Issue is with `infl` class - R R 无法将类“函数”强制转换为 data.frame - 将 matchit 的 logit 结果与 PseudoR2 一起使用 - R Cannot coerce class "function" to a data.frame - Using logit results from matchit with PseudoR2 导出数据时无法强制输入R - cannot coerce type in R when exporting the data.frame 无法强制类typeOf为data.frame的两倍 - Cannot coerce class typeOf is double to a data.frame 无法将“try-error”类强制转换为 SNP 中的 data.frame - cannot coerce class “”try-error“” to a data.frame in SNPs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM