[R] Problems if optimization

Berend Hasselman bhh at xs4all.nl
Fri Mar 26 16:54:30 CET 2010



Francisco Silva wrote:
> 
> ....
> I am a begginer in R and i am trying to find the parameters of one
> likelihood function, but when i otimize it, always appers a error or
> advertisement and the solve does not occur.
> The problem seems like that:
> 
>  "lMix<-function(pars,y){
> 
> 
Shouldn't that be llMix?

I tried this:

llMix <- function(pars,y) {   
    beta1 <- pars[1]
    beta2 <- pars[2]
    beta3 <- pars[3]
    beta4 <- pars[4]
    beta5 <- pars[5]
    alfa1 <- pars[6]
    Fsp <-
log(1/(1+exp(beta1*y[,10]+beta2*y[,3]+beta3*y[,3]+beta4*y[,5]+beta5*y[,6]+alfa1*y[,11])))
    Frp <-
log(1/(1+exp(beta1*y[,10]+beta2*y[,3]+beta3*y[,3]+beta4*y[,5]+beta5*y[,6])))
    logl <- sum((y[,15]*Fsp)+(y[,19]*Frp))
    return(-logl)
}

Mix <- matrix(data=4*runif(25*19)+10,ncol=19) 
pstart <- c(1,1,1,1,1,1)
llMix(pstart,Mix)
optim(pstart, llMix, y=Mix, method="CG", control=list(trace=2))

And this works, in the sense of no error messages.
Something wrong with your data?

Berend
-- 
View this message in context: http://n4.nabble.com/Problems-if-optimization-tp1692193p1692411.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list