Simple optim - question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Simple optim - question

Carsten Steinhoff
Hello,

I want to find the parameters mu and sigma that minimize the following
function.
It's important, that mu and sigma are strictly positive.

-----------------
optimiere = function(fmean,smean,d,x,mu,sigma)
{
merk = c()
for (i in 1:length(d))
  merk=c(merk,1/(d[i]^2)*(d[i]-1/(fmean*(1-plnorm(x[i],mu,sigma))))^2)
return(sum(merk))
}
-----------------

To do that I'm using the nlm function, but I only get results for ONE of the
two parameters.
I cannot cope with optimizing the two parameter problem simultaneously.
I've started with:

nlm(optimiere,p=5,fmean=10,smean=10000,d=c(40,10),x=c(500000,50000),sigma=3.
5)

Then I tried to combine mu and sigma in one Vector. I get back two
parameters but the results are unreasonable since mu and sigma are
-0.3247726 and 4.7905308 but have to be strictly positive.

I've given up after hours and hope to get your help..
I'm sure the problem should be easily solved by one of the experts.

Thanks a lot.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Simple optim - question

Dieter Menne
Carsten Steinhoff <carsten.steinhoff <at> gmx.de> writes:

> I want to find the parameters mu and sigma that minimize the following
> function.
> It's important, that mu and sigma are strictly positive.
>
> -----------------
> optimiere = function(fmean,smean,d,x,mu,sigma)
> {
> merk = c()
> for (i in 1:length(d))
>   merk=c(merk,1/(d[i]^2)*(d[i]-1/(fmean*(1-plnorm(x[i],mu,sigma))))^2)
> return(sum(merk))
> }
> -----------------
>
....

Try optim or nlminb, both can be used with constraints. Or, as your example
looks like a least-square problem, reformulate optim and use nls.

Dieter

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html