Hi, my name is Marcel R. Lopes. My problem is, I made a code to calculate the estimates of a Cox model with random effects. Used to optimize the R command for this. The estimates were calculated correctly, but the Hessian matrix does not have good values. The same thing was done in SAS and gave good results for the Hessian Matrix. Where is the problem in R? As the Hessian is calculated?. How could I solve this problem?. I would be grateful if you could help me .... [[alternative HTML version deleted]]
Are you using optim() function in R? Although I am not sure what your problem really is (as you haven't provided sufficient information), it may be that the hessian computation in optim() is not accurate enough for you. Try the function hessian() in the "numDeriv" package. It is very accurate. Here is an example: require(numDeriv) # to compute hessian fr <- function(x) { ## Rosenbrock Banana function x1 <- x[1] x2 <- x[2] 100 * (x2 - x1 * x1)^2 + (1 - x1)^2 } ans <- optim(par=c(-1,1), fn=fr, method="BFGS") hess <- hessian(x=ans$par, func=fr) hess Hope this helps, 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: jhsph.edu/agingandhealth/People/Faculty/Varadhan.html ---------------------------------------------------------------------------- -------- -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Marcel Rodrigues Lopes Sent: Wednesday, April 29, 2009 10:42 AM To: r-help at r-project.org Subject: [R] Optim and hessian Hi, my name is Marcel R. Lopes. My problem is, I made a code to calculate the estimates of a Cox model with random effects. Used to optimize the R command for this. The estimates were calculated correctly, but the Hessian matrix does not have good values. The same thing was done in SAS and gave good results for the Hessian Matrix. Where is the problem in R? As the Hessian is calculated?. How could I solve this problem?. I would be grateful if you could help me .... [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
The technical issue of this query has been answered by Ravi Varadhan (essentially use numDeriv on the final parameter set to get the hessian). This msg is about getting feedback to those of us trying to improve optimization capabilities. Ravi and I, among others, are working on a substitute package for optim() and related issues. This will still allow access to existing codes -- some of which I wrote in the mid 1970s for strange antique computers with 4K words of storage for program AND data. Some of these codes need updating, but even more, our knowledge base for advising people what to use needs better evidence of how well things perform in modern R settings, including new platforms as they come along. Tools to build such a base of information are part of an ancillary project. For those interested, please get in touch off-list. We have a wiki where we are sharing ideas. It's currently "users only", as it is a work in progress that we would not want quoted, but I'll be happy to provide access on request. John Nash Original Msg. Hi, my name is Marcel R. Lopes. My problem is, I made a code to calculate the estimates of a Cox model with random effects. Used to optimize the R command for this. The estimates were calculated correctly, but the Hessian matrix does not have good values. The same thing was done in SAS and gave good results for the Hessian Matrix. Where is the problem in R? As the Hessian is calculated?. How could I solve this problem?. I would be grateful if you could help me ....