Hi,

I am trying to maximize a utility function using optim. I have a problem
with optim, since some of the values in the caw, mom, me and btm matrixes in
the code bellow are missing. Is there a handy way just to skip the missing
values in the loop?

g <- 5
retp <- NULL
object <- function (x)
{
    b1 <- x[1]
    b2 <- x[2]
    b3 <- x[3]
    for(i in 1:nrow(ret)){
        for(j in 1:ncol(ret)){
        retp[i] <- (caw[i,j]+1/24*(b1*mom[i,j] + b2*me[i,j] +
b3*btm[i,j]))*ret[i,j]
        }
    }
    util <- (1+retp)^(1-g)/(1-g)
    return(-sum(util))
}
result <- optim(c(2.0,-1.0,3.5
),object,control=list(maxit=500),hessian=TRUE,method="BFGS")

Thank you in advance.
Hannu Kahra

	[[alternative HTML version deleted]]


