[R] Help in optimization

Alberto Monteiro
Wed, 11 Oct 2006 18:19:17 -0000

Ricardo Bessa wrote:
>
> I have had a problem in finding the minimum of a function, the
> function in cause is:
>
The first, obvious, optimization step is that you
are reading the whole table every time you call the function.

You should read the table just once. Instead of:

> curv <- function(a,b){
> date <-
read.table("bessa.csv",header=T,sep=";",dec=",")
> calP <- (22000)/(1+exp(-(a*date$v+b)))
> err <- (calP-date$P)^2
> return(sum(err))
> }

Try:

date <-
read.table("bessa.csv",header=T,sep=";",dec=",")
curv <- function(a,b){
calP <- (22000)/(1+exp(-(a*date$v+b)))
err <- (calP-date$P)^2
return(sum(err))
}

Alberto Monteiro