Re: [R] Help in optimization

From: Alberto Monteiro <albmont_at_centroin.com.br>
Date: Wed 11 Oct 2006 - 18:19:17 GMT

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



R-help@stat.math.ethz.ch 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. Received on Thu Oct 12 04:24:36 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 11 Oct 2006 - 18:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.