[R] optim & .C / Crashing on run

Paul Browne paulfj.browne at gmail.com
Sat Nov 3 19:15:21 CET 2012


Hello,

I am attempting to use optim under the default Nelder-Mead algorithm for
model fitting, minimizing a Chi^2 statistic whose value is determined by a
.C call to an external shared library compiled from C & C++ code.

My problem has been that the R session will immediately crash upon starting
the simplex run, without it taking a single step.

This is strange, as the .C call itself works, is error-free (as far as I
can tell!) & does not return NAN or Inf under any initial starting
parameters that I have tested it with in R. It only ever crashes the R
session when the Chi^2 function to be minimized is called from optim, not
under any other circumstances.

In the interests of reproducibility, I attach R code that reads attached
data files & attempts a N-M optim run. The required shared library
containing the external code (compiled in Ubuntu 12.04 x64 with g++ 4.6.3)
is also attached. Calculating an initial Chi^2 value for a starting set of
model parameters works, then the R session crashes when the optim call is
made.

Is there something I'm perhaps doing wrong in the specification of the
optim run? Is it inadvisable to use external code with optim? There doesn't
seem to be a problem with the external code itself, so I'm very stumped as
to the source of the crashes.


More information about the R-help mailing list