[R] optim with constraints

Ravi Varadhan RVaradhan at jhmi.edu
Mon Dec 7 15:35:32 CET 2009


Steven,

You haven't given us much information to help you.  Are you `maximizing' the
log-likelihood or are you `minimizing' the negative log-likelihood?  If it
is the former, you have to specify the control argument, control$fnscale =
-1.  This is a common mistake when using optim for likelihood estimation.

Ravi.

----------------------------------------------------------------------------
-------

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvaradhan at jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml

 

----------------------------------------------------------------------------
--------


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Prof. John C Nash
Sent: Monday, December 07, 2009 9:01 AM
To: r-help at r-project.org
Subject: Re: [R] optim with constraints


Without the data / script, I'm guessing that it is likely an attempt to
evaluate the loss 
function at an inadmissible point e.g., at the constraint where there is a
log(0). 
Different optimization tools handle things differently, and there are a
couple of us 
working (very slowly due to other things) on trying to provide a nice
wrapper to catch 
these exceptions so that they can be handled better.

JN


> Message: 56
> Date: Sun, 6 Dec 2009 17:32:54 -0800 (PST)
> From: Steven <ytsteven at gmail.com>
> Subject: Re: [R] optim with constraints
> To: r-help at r-project.org
> Message-ID:
> 	<88d5c01d-c30c-4e91-900c-2b825d5e3be8 at z4g2000prh.googlegroups.com>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> Hi, Prof Nash
> 
> Thanks for your comment!
> 
> I modified my code to be (added an extra parametr):
> 
> optim(c(1.14,0.25,0.06), weibull.like, mydata=mydata, method="L-BFGS-
> B", hessian = TRUE, lower = c(0, 0, 0), upper = c(Inf, Inf, 1))
> 
> But I had the following error:
> 
> Error in optim(c(1.14, 0.25, 0.06), weibull.like, mydata = mydata,
> method = "L-BFGS-B",  :
>   non-finite finite-difference value [2]
> 
> What does that mean? Much appreciate your help!
> 
> Steven
>

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list