[R-sig-ME] nonlinear models with warnOnly
Steven McKinney
smckinney at bccrc.ca
Thu Feb 4 22:27:20 CET 2010
Hi Cahn,
I'm not seeing a "warnOnly" argument to gnlsControl.
I do see a returnObject argument
returnObject a logical value indicating whether the fitted object should be returned when the maximum number of iterations is reached without convergence of the algorithm. Default is FALSE.
With returnObject=TRUE you will get output even if the fitting fails (the error appears to be downgraded to a warning).
> fm <- gnls(weight ~ SSlogis(Time, Asym, xmid, scal), Soybean,
+ weights = varPower(), start = list(Asym = 2000, xmid = 1, scal = 100),
+ verbose = TRUE, control=list(returnObject = TRUE))
**Iteration 1
GLS step: Objective: NULLvarStruct parameters:
power
0.9431074
Warning message:
In gnls(weight ~ SSlogis(Time, Asym, xmid, scal), Soybean, weights = varPower(), :
Step halving factor reduced below minimum in NLS step
> fm
Generalized nonlinear least squares fit
Model: weight ~ SSlogis(Time, Asym, xmid, scal)
Data: Soybean
Log-likelihood: -1381.013
Coefficients:
Asym xmid scal
2000 1 100
Variance function:
Structure: Power of variance covariate
Formula: ~fitted(.)
Parameter estimates:
power
0.9431074
Degrees of freedom: 412 total; 409 residual
Residual standard error: 0.008625526
> fm$numIter
[1] 1
>
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