[R] how to show iterations

Pieter Schoonees schoonees at ese.eur.nl
Sun Oct 14 20:25:25 CEST 2012

Have you tried other values for trace? Higher values will likely provide more information (depending on the method - BFGS here) - e.g. use trace = 2 or 3 etc instead of TRUE (which is similar to using 1). 

Optim calls an internal function (implemented in C I presume) so putting a print statement in the R code will not work.

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of sffarooqi
> Sent: Sunday, October 14, 2012 20:44
> To: r-help at r-project.org
> Subject: Re: [R] how to show iterations
> Hi Pieter, thank you for your response.
> I am indeed using the "optim" function. I had already tried the trace option
> under the control argument - however it only provides me with iteration no.
> 10, 20, 30 etc. I would like to be able to generate the results for every
> iteration.
> Here is an example (where fr is the function and grr the gradient - which
> were previously defined already)
> <- optim(c(-1,1), fr, grr, method = "BFGS", control=list(trace = TRUE)))
> Also I shd mention I had tried the print command previously too but this
> hadn't worked. You mentioned that I could use fix() to add a print statement
> - would you be able to suggest how to implement it pls? Once again, thank
> you for your help -I am really appreciative!
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-show-
> iterations-tp4646133p4646158.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> 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