0

I'm conducting lme analysis using on my dataset with the following code

M1 <- lme(VT ~ visit + sx + agevis + c_bmi + gpa + qa + BP + MH + ethn, data = Cleaned_data4t300919, random = ~ 1 + visit |id, corAR1(),method = "ML", na.action = na.omit(Cleaned_data4t300919))

and I get the following error message:

Error in model.frame.default(formula = ~visit + sx + agevis + c_bmi + : attempt to apply non-function

I am not sure what I am doing wrong or how to get the model to run. I really appreciate an answer. Thank you.

I am trying to run a linear mixed effect model with VT as my dependent variable, visit as my time variable, with a 1st order autoregressive correlation, ML estimator on data with some missing observations.

I have tried changing the code in the following ways but got the same error message

library(nlme)
?lme
fm2 <- lme(VT ~ visit + sx + agevis + c_bmi + gpa + qa + BP + MH + ethn, data = Cleaned_data4t300919, random = ~ 1|id, corAR1(),method = "ML", na.action = na.pass(Cleaned_data4t300919))

fm2 <- lme(VT ~ visit + sx + agevis + c_bmi + gpa + qa + BP + sfnMH + ethn, data = Cleaned_data4t300919, random = ~ 1 + visit |cenid, corAR1(),method = "ML", na.action = na.omit(Cleaned_data4t300919))

fm2 <- lme(VT ~ visit + sx + agevis , data = Cleaned_data4t300919, random = ~ 1 + visit |id, corAR1(),method = "ML", na.action = na.omit(Cleaned_data4t300919))

fm2 <- lme(VT~visit + sx + agevis + c_bmi + gpa + qa + BP + MH + ethn, data = Cleaned_data4t300919, na.action = na.exclude(Cleaned_data4t300919))

fm2 <- lme(formula= sfnVT ~ visit + sx + agevis , data = Cleaned_data4t300919, random = ~ 1 + visit |cenid, corAR1(),method = "ML", na.action = na.omit(Cleaned_data4t300919))

I will like to obtain the estimates for the code and plot estimates using ggplot.

IceCreamToucan
  • 28,083
  • 2
  • 22
  • 38
sylvie
  • 3
  • 2
  • 3
    `na.action = na.omit(Cleaned_data4t300919)` is the problem I think. From `?lme` - *na.action: a function that indicates what should happen when the data contain 'NA's* - you are providing data, not a function. A way to identify these kinds of issues for sure is to use `debug` - `debug(lme)` then step through the function line-by-line to see exactly what the error is in response to. – thelatemail Oct 13 '19 at 22:38
  • @thelatemail, post as answer? – Ben Bolker Oct 13 '19 at 23:48
  • @BenBolker - upgraded to answer. – thelatemail Oct 14 '19 at 00:09

1 Answers1

1
na.action = na.omit(Cleaned_data4t300919)

and similar attempts are the problem I think.

From ?lme:

na.action: a function that indicates what should happen when the data contain 'NA's

You are providing data, not a function, since na.omit(dataset) returns a data.frame with NA containing rows removed, rather than something that can be applied to the data= specified. Just:

na.action=na.omit

or similar na.* functions will be sufficient.

A way to identify these kinds of issues for sure is to use ?debug - debug(lme) then step through the function line-by-line to see exactly what the error is in response to.

thelatemail
  • 91,185
  • 12
  • 128
  • 188
  • Thanks for your answer. i'm new to R and I don't quite understand your answer. could you give an example. – sylvie Oct 14 '19 at 10:00
  • @sylvie - e.g.: just `na.action=na.omit` should be enough, you don't need to specify the dataset again as well. – thelatemail Oct 14 '19 at 10:03