[R] Simple optim - question
Dieter Menne
dieter.menne at menne-biomed.de
Thu Feb 9 09:17:38 CET 2006
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
More information about the R-help
mailing list