(p<-ncol(X))== ncol(Y)在glmer中不是TRUE错误 [英] (p <- ncol(X)) == ncol(Y) is not TRUE error in glmer
问题描述
我正在尝试使用 glmer
拟合模型,但不断出现错误:
I'm trying to fit a model with a glmer
and I keep getting the error:
错误:(p<-ncol(X))== ncol(Y)不正确
Error : (p <- ncol(X)) == ncol(Y) is not TRUE
这是一个大型模型,具有8个功能和几千个点.在研究此错误时,我发现它可能是由太多 NA
引起的.我查看了我的功能,只有其中一个具有任何 NA
.然后,我从模型中排除了该功能,但是仍然出现错误.数据太大,无法发布.
It's a large model, with 8 features and several thousand points. When researching this bug, I found that it could be caused by too many NA
s. I looked at my features, and only one of them had any NA
s. I then excluded that feature from my model, but I still I got the error. The data is too large and cannot be posted.
covariates=c("Sex", "PC1", "PC2", "PC3", "PC4", "label", "Alive")
fix.eff=paste("outcome","~",xi)
if (!is.null(covariates)) {for (covi in covariates) fix.eff=paste(fix.eff,"+",covi) }
fix.eff=formula(paste(fix.eff, "+(1|",ind.family,")"))
fit <- try(glmer(fix.eff,family=binomial(link='logit'), data=x))
推荐答案
问题出在以下几行:
fix.eff=formula(paste(fix.eff, "+(1|",ind.family,")"))
应该是
fix.eff=formula(paste(fix.eff, "+(1| ind.family)"))
ind.family
是数据集 x中的一列.
最初的写入方式是读取它的当前值,而不是该列.因此,该公式包含术语(1 | 1)
而不是(1 | ind.family)
.现在,它已修复,可以正常工作!
ind.family
is a column in the data set x.
The original way it was written, it was read in as its current value, instead of the column. So the formula included the term (1|1)
instead of (1|ind.family)
. Now that it's fixed, it works!
如果其他人遇到此错误,我建议您仔细查看您的公式和数据,以确保它是您所认为的样子.
If anyone else gets this error, I would recommend looking very closely at your formula and your data to make sure it is what you think it is.
这篇关于(p<-ncol(X))== ncol(Y)在glmer中不是TRUE错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!