Hello,
I am writing a a small function to fit an LME model.
fit.data<-function(data) {
lme.fit<-by(data, data$rep, function (x) lme(resp~time, data=x,
random=list(id=pdDiag(~1+time))))
return(lme.fit)
}
It WORKS for fitting response (resp) versus time for a given dataset
by replications (rep).
PROBLEM: Now, I wanted to fit other variables in the same dataset. One
option (inefficient) was to rewrite the function for resp1,
resp2,.......respN and do the fitting.
However, I would like to pass on the vector information to the
function used in "by". I know the following would not work..because it
is not supposed to...but I tried.
fit.dataN<-function(data,vec) {
lme.fit<-by(data, data$rep, function (x) lme(vec~time, data=x,
random=list(id=pdDiag(~1+time))))
}
So that I can do the following
fit1<-fit.dataN(data,vec1)
fit2<-fit.dataN(data,vec2)
.............
fitN<-fit.dataN(data,vecN)
Any suggestions? How to pass on the dataset as well as vector information.
Thanks.
Pravin
--
Pravin Jadhav
Graduate Student
Department of Pharmaceutics
MCV/Virginia Commonwealth University
DPE1/CDER/OCPB/Food and Drug Administration
Phone: (301) 594-5652
Fax: (301) 480-3212
|