[R] Loop within nlme

Spencer Graves spencer.graves at pdf.com
Sat Dec 3 06:57:57 CET 2005


	  I have not seen a reply to this, so I will offer a couple of feeble 
comments, hoping that you might find them useful even though they don't 
answer your question.  It is difficult for me to understand your 
question, because my SAS experience is so limited.

	  1.  R is open source, so you can get the source code for nlme, read 
it, modify it to do something similar but different, etc.  You can see 
the source for any function by typing its name at a command prompt.  I 
did this just now with "lme" and "nlme" and found calls to "UseMethod". 
  When I consult help("UseMethod"), it says, "See Also ... methods", and 
'methods("lme")' and 'methods("nlme")' identify, among other things 
"lme.forumla" and "nlme.formula".  When I request those two, a listing 
of R code fills my screen.  If you step through either of those line by 
line, you will likely find a place where you can modify the code to do 
what you want.  If you do this, calling "debug(lme.forumla)' before 
"lme" will allow you to walk through the code without being encumbered 
by features of R that work differently when called from within a 
function than they do when you run them line by line from a command 
prompt.

	  2.  What's the more general problem you are trying to solve?  Can you 
simplify you problem to a few lines of R code that will replicate a 
specific difficulty you have encountered with R (as suggested in the 
posting guide! "www.R-project.org/posting-guide.html")?  A question with 
that kind of simple, reproducible example will, I believe, more likely 
receive a useful response quickly than questions that are more difficult 
for readers of this listserve to parse.

	  hope this helps.
	  spencer graves

Scott Story wrote:

> 	I am trying to mimic the SAS code below in R. The trick is that each 
> row in the dataset has variable "t" which controls how many times the 
> do-loop below will be iterated (that is, the model is fit to the 
> response, ifate, 0 to t-1 times for each row of data). Is it possible to 
> incorporate a loop like this into nlme by writing a function? Can 
> anybody provide some hints to get me on my way? The code below is for a 
> very simple model, an intercept only model, but more complex models will 
> be evaluated (some potentially including random effects). The code is 
> used to model daily nest survival.
> 
> 
> Proc Nlmixed data=Mall tech=quanew method=gauss maxiter=1000;
> parms B0=0;
> 	p=1;
> 	   do i=0 TO t-1;
> 	   	   logit=B0;
> 	      p=p*(exp(logit)/(1+exp(logit)));
> 	   end;
> model ifate~binomial(1,p);
> 
> 

-- 
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915




More information about the R-help mailing list