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
you should use:
optmz <- optimize(fitIT, interval = c(0.5, 4),
ts_wave1 = test.data[, 1], ts_template = test.data[, 1])
calcFit(test.data[, 1], stretchWaveTime(test.data[, 1], optmz$minimum)
which should give the same as optmz$objective, i.e., the optmz$minimum
is the value of 'ampFac' argument for which fitIT() attains its
minimum value; the value of fitIT() at optmz$minimum is
optmz$objective.
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "tom wright" <tom at maladmin.com>
To: "R-Stat Help" <R-help at stat.math.ethz.ch>
Sent: Wednesday, May 10, 2006 2:18 PM
Subject: [R] problems with optimize (again)
> 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
>
> ______________________________________________
> 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
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
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.3059954What 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