I am trying to fit a mixed model to my data using the nlme library in R.
Here's what I have:
df <- data.frame(phen = phen.info.box[,2], hap = as.factor(mouse.haps), strain = as.factor(mouse.strains)) fit <- nlme(model = phen ~ hap + (1|strain), data = df, fixed = hap ~ 1, random = strain ~ 1, start = rep(1, 832), correlation = K)
And the error I get is:
Error in getGroups.data.frame(dataMix, eval(parse(text = paste("~1", deparse(groups[]), : invalid formula for groups
I would like to do more complex things down the road, but I'm having trouble just getting this basic model running. I have read through the nlme documentation and can't seem to figure out this "invalid formula" error. I got the same error with the line "random = strain ~ 1" omitted. I read in the documentation that simply putting "fixed = var ~ 1" signals a single fixed effect, which is what I want.
I have to use nlme instead of lme4 because, as far as I understand, lme4 won't let me specify a variance-covariance matrix on the random effects and that's important to me (see "correlation = K" line.)
OK, I'm getting downvotes for this and I'm not sure why. I assume it's people thinking "this question is too easy to even be asked -- the asker must not have tried to solve it at all!". I have been looking through documentation and examples online and I cannot, for the life of me see the difference between how I'm doing it and this example I found online:
nlme.fit <- nlme(lgcopy ~ logexp2(p1,b1,p2,b2,day), fixed = p1+b1+p2+b2 ~1,random = p1+b1+p2+b2 ~1, data =aids.dat,start=c(start))
which apparently works.