[R-sig-ME] nonlinear models with warnOnly

Steven McKinney smckinney at bccrc.ca
Thu Feb 4 22:13:26 CET 2010


Hi Cahn

Have you tried the "verbose" argument to gnls?
That will make gnls() print out information on each iteration before it
throws the error.

Steve McKinney
________________________________________
From: Chaehyung Ahn [cahn88 at gmail.com]
Sent: February 4, 2010 12:47 PM
To: Steven McKinney
Cc: r-sig-mixed-models at r-project.org
Subject: Re: [R-sig-ME] nonlinear models with warnOnly

Hi Steven,

Thank you for your reply.

But I need to this to prevent the error from stopping the iteration. I need to count how many time the model fits without error.

cahn



On Thu, Feb 4, 2010 at 3:29 PM, Steven McKinney <smckinney at bccrc.ca<mailto:smckinney at bccrc.ca>> wrote:

> -----Original Message-----
> From: r-sig-mixed-models-bounces at r-project.org<mailto:r-sig-mixed-models-bounces at r-project.org> [mailto:r-sig-mixed-<mailto:r-sig-mixed->
> models-bounces at r-project.org<mailto:models-bounces at r-project.org>] On Behalf Of Chaehyung Ahn
> Sent: Thursday, February 04, 2010 9:36 AM
> To: r-sig-mixed-models at r-project.org<mailto:r-sig-mixed-models at r-project.org>
> Subject: [R-sig-ME] nonlinear models with warnOnly
>
> Dear list,
>
> I need to make nls() or gnls() function to return something like "NA"
> when
> it fails to fit. I found I can use "warnOnly", but I cannot make it
> work.
>
> In the following program. I intentionally make it fail by making very
> wrong
> initial values, but the "out" is empty. What is wrong with my approach?
>
> Many thanks in advance!
>
> library(nlme)
> out<- gnls(conc~SSbiexp(time,A,lalpha,B,lbeta),
>           start=list(A=-1,lalpha=2,B=20,lbeta=4),
>           weights=varPower(fixed=1),control=list(warnOnly=TRUE),
>           data=Indometh,subset=Subject==1)

Have you explored using the "try()" or "tryCatch()"
strategies?


 out <- try(gnls(conc~SSbiexp(time,A,lalpha,B,lbeta),
          start=list(A=-1,lalpha=2,B=20,lbeta=4),
          weights=varPower(fixed=1),
          data=Indometh,subset=Subject==1))

Then if the fit fails, variable "out" will have class "try-error"
so you can check the class of out and decide what to do etc.


(I tried your example in R 2.10.1 on a Mac and R 2.9.2 on a PC and
get an error that I haven't been able to track down yet.
> require("nlme")
Loading required package: nlme
> out<- gnls(conc~SSbiexp(time,A,lalpha,B,lbeta),
+            start=list(A=-1,lalpha=2,B=20,lbeta=4),
+            weights=varPower(fixed=1),control=list(warnOnly=TRUE),
+            data=Indometh,subset=Subject==1)
Error: object 'convIter' not found
>
>
>  out<- try(gnls(conc~SSbiexp(time,A,lalpha,B,lbeta),
+            start=list(A=-1,lalpha=2,B=20,lbeta=4),
+            weights=varPower(fixed=1),
+            data=Indometh,subset=Subject==1))
Error : object 'convIter' not found
>
)

Best

Steve McKinney


>
>
>
>
> --
> Chaehyung Ahn, Ph.D.
> 4033 Remington Oaks Circle
> Cary, NC 27519
> Daum Cafe: http://cafe.daum.net/biometrika
> Blog: http://cahn88.blogspot.com/
>
>       [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org<mailto:R-sig-mixed-models at r-project.org> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models




Steven McKinney, Ph.D.

Statistician
Molecular Oncology and Breast Cancer Program
British Columbia Cancer Research Centre

email: smckinney -at-  bccrc +dot+ ca
tel: 604-675-8000 x7561

BCCRC
Molecular Oncology
675 West 10th Ave, Floor 4
Vancouver B.C.
V5Z 1L3

Canada




--
Chaehyung Ahn, Ph.D.
4033 Remington Oaks Circle
Cary, NC 27519
Daum Cafe: http://cafe.daum.net/biometrika
Blog: http://cahn88.blogspot.com/




More information about the R-sig-mixed-models mailing list