[R] Optimize multiple variable sets
Jonathan P Daily
jdaily at usgs.gov
Mon Dec 6 15:15:29 CET 2010
Correct me if I'm wrong, but isn't the minimal x value in your example the
same regardless of what positive coefficient you apply to x? If that is
the case, you would expect the same min(x) for each iteration.
i.e. in the interval [0,1] the minimum x value of x^2 + x is the same as
x^2 + 100000000*x, at x = 0.
--------------------------------------
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,
the thing itself have purpose? Or do we, what's the word... imbue it."
- Jubal Early, Firefly
r-help-bounces at r-project.org wrote on 12/06/2010 07:00:57 AM:
> [image removed]
>
> [R] Optimize multiple variable sets
>
> sandra lag
>
> to:
>
> r-help
>
> 12/06/2010 08:54 AM
>
> Sent by:
>
> r-help-bounces at r-project.org
>
>
>
> Hi,
> I usually use optimize function for ML Estimation. Now I´ve got a
> data frame with many sets, but I can´t save estimates each time I
> run the code for each data set (I´m using a for loop with my
> loglikelihood function and works ok but when I apply another for loop
to:
> optimize(my.loglikelihood.function[i], int=c(0.0001,10))
> it doesn´t work;
>
> alternatively, using optimize inside the for loop (like in the
> example below), it returns always the same value, which is not expected:
>
> data<-matrix(c(1,1,1, 2,2,2, 3,3,3, 4,4,4), nrow=3, ncol=4)
> c<-dim(data)[2]
> results<-vector(length=c)
> for (i in 1:c){
> f<-function(x){
> x^2+x*sum(data[,i])
> }
> results[i]<-optimize(f,int=c(0.0001,10))[1] #minimum
> }
> #results
>
> Can someone please indicate me if there´s a different function/ way
> to do so? (with no need of initial parameter values)
> Thanks! Sandra
> ______________________________________________
> R-help at r-project.org 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.
More information about the R-help
mailing list