beth
beth

Reputation: 118

(p <- ncol(X)) == ncol(Y) is not TRUE error in glmer

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 NAs. I looked at my features, and only one of them had any NAs. I then excluded that feature from my model, but I still I got the error. The data is too large and cannot be posted.

http://r.789695.n4.nabble.com/Error-from-lme4-quot-Error-p-lt-ncol-X-ncol-Y-is-not-TRUE-quot-td4712617.html

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

Answers (1)

beth
beth

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

Related Questions