Reputation: 118
I'm trying to fit a model with a glmer
and I keep getting the error:
Error : (p <- ncol(X)) == ncol(Y) is not TRUE
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.
The model is as follows:
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))
Upvotes: 0
Views: 7570
Reputation: 118
The problem was in the following line:
fix.eff=formula(paste(fix.eff, "+(1|",ind.family,")"))
it should have been
fix.eff=formula(paste(fix.eff, "+(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.
Upvotes: 1