Skip to content
Back to formatted view

Raw Message

Message-ID: <3A758979-5308-423A-81D8-822B4081A7B0@uos.de>
Date: 2009-01-16T17:43:00Z
From: Stefan Evert
Subject: Using "optim" with exponential power distribution
In-Reply-To: <1232122782.4410.15.camel@Regulus.Biologie.Uni-Marburg.DE>

> I know "optim" should do a minimisation, therefor I used as the
> optimisation function
>
> opt.power <- function(val, x, y) {
>   a <- val[1];
>   b <- val[2];
>   sum(y - b/(2*pi*a^2*gamma(2/b))*exp(-(x/a)^b));
> }
>
> I call: (with xm and ym the data from the table)
>
> a1 <- c(0.2, 100)
> opt <- optim(a1, opt.power, method="BFGS", x=xm, y=ym)
>
> but no optimisation of the parameter in a1 takes place.
> Any ideas?

It looks to me like your optimising the _average_ of the differences  
between y and the function, so as long as positive and negative  
differences balance out you get a cost value of 0 (and you can make it  
even smaller if the fitted function is much larger than the actual y  
values, so all differences are negative).

You probably wanted to minimise the squared errors:

	sum((y - b/(2*pi*a^2*gamma(2/b))*exp(-(x/a)^b)))^2)




Best regards,
Stefan Evert

[ stefan.evert at uos.de | http://purl.org/stefan.evert ]