[R] problems with optimize (again)

Uwe Ligges ligges at statistik.uni-dortmund.de
Wed May 10 18:37:45 CEST 2006


tom wright wrote:

> 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


What is calcFit?

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

Why should to different algorithms (at least I guess so, since you don't 
say what calcFit() does) find the same *local* minimum?


> 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?


Use optim().

Uwe Ligges


> 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
> 
> ______________________________________________
> R-help at 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




More information about the R-help mailing list