sylvie
sylvie

Reputation: 3

'lme' error R "attempt to apply non-function

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.

Upvotes: 0

Views: 554

Answers (1)

thelatemail
thelatemail

Reputation: 93803

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.

Upvotes: 1

Related Questions