[R] problems with optimize (again)

tom wright tom at maladmin.com
Wed May 10 14:18:20 CEST 2006


Can someone please explain what the $minimum result of the optimize
function actually is?

I'm trying to optimize the function:
fitIT<-function(ampFac,ts_wave1,ts_template){
    template<-stretchWaveTime(ts_template,ampFac)
    fit<-calcFit(ts_wave1,template)
    return(fit)
}

with
>optimize(f=fitIT,interval=c(0.5,4),ts_wave1=test.data[,1],ts_template=test.data[,1])
$minimum
[1] 3.764685

$objective
[1] 1.037864

however when I run
> calcFit(test.data[,1],stretchWaveTime(test.data[,1],1.037864)) 
[1] 0.3059954

I thought $minimum and the result of the calcFit function should be the
same.

As a further question I'm going to need to nest optimize functions so I
can optimize over two variables. How can I get the minimum and objective
back from the nested function f, as well as the value to be minimised?

I hope this makes sense and I apologise for the lack of reproducible
code. If it will help I can include that in a further e-mail.
Thanks
Tom




More information about the R-help mailing list