[R] Dealing with missing values in a linear mixed model

Debs Majumdar debs_stata at yahoo.com
Wed Jul 6 21:22:12 CEST 2011


Hello,

   I am trying to run a linear mixed model using 


model.a <- lme(Psstotals ~ Visit, data=caf, random= ~ Visit|Id)


My dataset looks lie the following:


    Id   Visit  Agecorrected Psstotals
1 106     0           19            8         
2 106     1           19            9         
3 106     2           19           NA       
4 106     3           19           NA       
5 106     4           19           NA       
6 106     5           19           11       
........................
.............

I have 14 visits for each ID and I do have some missing values for each Id. I get the following error when I run the above model:

Error in na.fail.default(list(Visit = c(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,  : 
  missing values in object


I do not want to do a listwise deletion as I would like to run model with all available data. So, I tried the following


model.a <- lme(Psstotals ~ Visit, data=caf, random= ~Visit |Id, na.action=na.exclude)


Is this the right syntax?

Thanks,

Debs



More information about the R-help mailing list