[R] Using optim with parameters that are factors (instead of continuous parameters)

Lucas Merrill Brown lucas.merrill.brown at gmail.com
Thu Oct 27 17:50:00 CEST 2011


Ben,

Thank you for the incredibly helpful suggestions and links. I've been
exploring each over the past few days, and for anyone else's future
reference, here's what I've found.

(1) I was able to use SANN to specify how to choose new candidate
solutions, but I wasn't able to easily use SANN for a model that
includes both discrete and continuous parameters. That would require
designating two separate rules for choosing new candidate solutions --
one rule for the continuous parameters and one rule for the discrete
parameters.

(2) Your second suggestion ended up solving the problem best for the
needs of this data. I wrote a continuous function that looks a lot
like a discrete pulse, and optim was able to find its way towards the
specification with the maximum likelihood. A function of the general
form f(x) = 1/(k + (c - x)^n) does the trick, where c represents the
location of the discrete jump. I then optimized over potential values
of c.

(3) Generating log-likelihoods for each separate value of the
parameter works well, especially for a parameter with few potential
values. Since I'm also running a specification with
individual-specific thresholds, however, re-running the regression
five times for each individual is a little unwieldy. So it made the
most sense to use solution #2.

Thanks again for your prompt and productive response!
Lucas



More information about the R-help mailing list