Reputation: 1222
I'm trying to execute a lme function as follows
mydata <- read.table(
"H:/edu/Multivariat/HCMpart2.TXT", header=TRUE, sep="\t",
na.strings="*", dec=",", strip.white=TRUE
)
mydata = data.frame(mydata)
summary(lme(mydata$x~1+mydata$grp+mydata$var, random~1|mydata$id))
where x contains my values, grp and var represent which groups and variables that caused the x value, and id is the id of the patient.
And where HCMpart2.txt contains a header with "id grp var x" with tabs in-between and the corresponding values for all these. I've tried to use the "as.numeric" function to convert the factors into numerical factors, but it did not complete my problem.
When I'm trying to execute the lme function I get the following
Error in as.data.frame.default(data) :
cannot coerce class '"formula"' into a data.frame
Can anyone help? I was under the impression I did everything correctly... Regards Cenderze
Upvotes: 1
Views: 21757
Reputation: 121177
Three things:
Like shadow said, you're missing an equals sign in the random argument.
lme
has a data
argument that stops you having to write ugly code with lots $
signs.
The intercept is implicitly included.
summary(model <- lme(x ~ grp + var, mydata, random = ~ 1 | id))
Upvotes: 4