[R] NAs in optim

From: Hannu Kahra <hkahra_at_gmail.com>
Date: Mon 23 Jan 2006 - 04:37:00 EST


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] +

    util <- (1+retp)^(1-g)/(1-g)
result <- optim(c(2.0,-1.0,3.5

Thank you in advance.
Hannu Kahra

        [[alternative HTML version deleted]]

R-help@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 Received on Mon Jan 23 04:50:25 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:09 EST