Re: [R] Help in optimization

From: Alberto Monteiro <>
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))
> }


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

Alberto Monteiro mailing list PLEASE do read the posting guide 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 Please read the posting guide before posting to the list.