3

I am working on a simple model in R:

fit<-lme(x~y, data, random=~1|subject)

But I keep getting this error:

Error in na.fail.default(list(h1 = c(103L, 20L, 34L, 85L, 47L, 136L, 76L, : missing values in object

(h1 is one of my column titles of a factor)

Any idea on how to fix this? An identical model works with a different set of data.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Katie Tetzloff
  • 55
  • 1
  • 1
  • 6
  • 1
    The error suggests you have missing values in the data, You either need to omit data with missing values or Impute missing values – Imran Ali Apr 11 '16 at 21:33
  • 2
    Take a look at the help page for `lme`, specifically at the `na.action` argument. The default is set to `na.fail`. You might want to choose a different option. – aosmith Apr 11 '16 at 21:55
  • This question will basically be unanswerable unless you can please include data and/or code that will provide us with a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) ? (Especially since you say that the same model works with a different set of data ...) Otherwise I'm going to vote to close as "unclear what you're asking" ... – Ben Bolker Jul 07 '16 at 16:23

1 Answers1

15

Set na.action equal to na.omit in your function call:

fit<-lme(x~y, data, random=~1|subject, na.action=na.omit)

nlme defaults to na.fail when NAs are found. This is not the case with lme4::lmer() where na.action is equal to na.omit by default.

Edit: oops, after replying I noticed this is an old and most likely dead question.

blazej
  • 1,678
  • 3
  • 19
  • 41