jmlange at ucla.edu
2007-May-09 04:47 UTC
[R] Passing variable names as function arguments for lme model specification
Hello, I have what I hope is a relatively straightforward question. I'm trying to write a function that runs lme using variables specified in the function argument, along with some other tasks. However, I'm having some problems with lme accessing the variables I'm interested in. Here's a simplified version of my test code: testfunction<-function(var1, var2) { lme(var1 ~ var2,random=~1,data=testdata) #other stuff... } If I run testfunction(var_a, var_b), I get the following error: Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type I tested the same procedure with lm rather than lme, and it seems to be an acceptable way of passing arguments with this procedure. This works: testfunction<-function(var1, var2) { lm(var1 ~ var2,data=testdata) #other stuff... } Any help on this matter would be much appreciated, Jane Lange Department of Biostatistics, UCLA