s-news
[Top] [All Lists]

help with a function

To: s-news@lists.biostat.wustl.edu
Subject: help with a function
From: Pravin Jadhav <pravinj@gmail.com>
Date: Thu, 17 Feb 2005 17:19:37 -0500
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding; b=a90yRm5lxL9/jxtoUu1e31sUdjJCKcxs3kk58kHGrHsZCjc7NrewUFk5PWK09MkAoLaKWvfU4utZU+72GZDSUUfkML55u/rcfNlCi62mnvo1EZBLhSlSLScaBcN1ITQBjR6QKMfueENbcCfCpXECfoNOCTQpU2Ht37TTabq4fDI=
Reply-to: Pravin Jadhav <pravinj@gmail.com>
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

<Prev in Thread] Current Thread [Next in Thread>