Skip to content
Back to formatted view

Raw Message

Message-ID: <6rad3rvmr5.fsf@bates4.stat.wisc.edu>
Date: 2004-02-09T23:47:26Z
From: Douglas Bates
Subject: how to use try()
In-Reply-To: <4027DFBF.7090604@mcgill.ca>

Check the function nlsList in package nlme.  It does something very
like what you want to do.

"r.ghezzo" <heberto.ghezzo at mcgill.ca> writes:

> Hello, I have a program with this section:
> ..
> for(i in 1:20){
>    lo <- nls(y~y0+a/(1+(x/x0)^b),start=list(y0=0.1,a=a0,x0=x00,b=-8.1))
>    beta[i] <- lo$m$getPars()[4]
> }
> ..
> If the fit works this is OK but if the fit fails, the whole program
> fails so:
> 
> ..
> for(i in 1:20){
>    try(lo <-
> 
> nls(y~y0+a/(1+(x/x0)^b),start=list(y0=0.1,a=a0,x0=x00,b=-8.1)))
>    beta[i] <- lo$m$getPars()[4]
> }

It is not a good idea to use lo$m$getPars() directly.  It is better to
use the generic function, which in this case is coef(), as in

coef(lo)[4]