On Mon, 5 Jul 2010, Fabian Gehring wrote:
Hi all,
I am trying to rebuild the results of a study using a different data set. I'm
using about 450 observations. The code I've written seems to work well, but I
have some troubles minimizing the negative of the LogLikelyhood function
using 5 free parameters.
As starting values I am using the result of the paper I am rebuiling. The
system.time of the calculation of the function is about 0.65 sec. Since the
free parameters should be within some boundaries I am using the following
command:
optim(fn=calculateLogLikelyhood, c(0.4, 2, 0.4, 80000, 0.8),
lower=c(0,0,0,0,0), upper=c(1, 5, Inf, Inf, 1), control=list(trace=1,
maxit=1000))
Unfortunately the result doesn't seem to be reasonable. 3 of the optimized
parameters are on the boundaries.
You haven't said why this is unreasonable.
A suggestion: Profile the loglikelihood around the starting value and
around the putative maximum. (This might help with the parscale issue.)
Also, you might try something like
apply(rbind(0,eps*as.matrix(expand.grid(rep(list(c(-1,0,1)),5)))),1,
function(x) calculateLogLikelyhood( x + y ) )
where y is the starting value (or the value achieved by optim()) and 'eps'
is small enough to make small changes in the function value might help you
see what gives. (It might be necessary to scale each column in
as.matrix(...) separately, 'though.)
In addition to inspecting the results by eyeball, you can fit the results
to a quadratic form in rbind(...) using lm() and then figure out roughly
where to go to find the maximum of your function.
If this isn't enough to get you started, at least it might enable you to
say more clearly what is not reasonable about your results.
HTH,
Chuck
Unfortunately I don't have much experience using optimizatzion methods.
That's why I am asking you. Do you have any hints for me what should be
taken into account when doing such an optimization.
Is there a good way to implement the boundaries into the code (instead of
doing it while optimizing)? I've read about parscale in the help-section.
Unfortunately I don't really know how to use it. And anyways, could this
help? What other points/controls should be taken into account?
I know that this might be a bit little information about my current code. But
I don't know what you need to give me some advise. Just let me know what you
need to know.
Thankds
______________________________________________
R-help@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.
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
______________________________________________
R-help@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.