[R] optim() and starting values.

From: Dong-hyun Oh <r.arecibo_at_gmail.com>
Date: Mon, 16 Jun 2008 18:26:57 +0200


Dear UseRs,

I wrote the following function to estimate parameters using MLE.



mlog <- function(theta, nx = 1, nz = 1, dt){   beta <- matrix(theta[1:(nx+1)], ncol = 1)   delta <- matrix(theta[(nx+2):(nx+nz+1)], ncol = 1)   sigma2 <- theta[nx+nz+2]
  gamma <- theta[nx+nz+3]
  y <- as.matrix(dt[, 1], ncol = 1)
  x <- as.matrix(data.frame(1, as.matrix(dt[, 2:(nx+1)], ncol = 2)))
  z <- as.matrix(dt[, (nx+2):(nx+nz+1)], ncol = nz)

  d <- z %*% delta / (gamma * sigma2)^.5   mustar <- (1-gamma) * z %*% delta - gamma * ( y - x %*% beta)   sigmastar <- (gamma * (1-gamma) * sigma2)^.5   dstar <- mustar / sigmastar

  loglik <- (-0.5 * nrow(x) *(log(2*pi) + log(sigma2))
             -0.5 * sum(( y - x %*% beta + z %*% delta)^2/sigma2)
             -sum(log(pnorm(d))) + sum(log(pnorm(dstar))))
  return(-loglik)
}

To test my function, I created an artificial data set as follows:


x1 <- abs(rnorm(100))*100
x2 <- abs(rnorm(100))*10
z1 <- abs(rnorm(100))*5
z2 <- abs(rnorm(100))*7

y <- abs(0.3 + 0.3* log(x1) + 0.7* log(x2)) dat <- data.frame(log(y), log(x1), log(x2), z1, z2)

The following optimization results provides different estimates.



theta.start1 <- c(1.06, 0.08, 0.04, 0.097, 0.008, 0.08, 0.008) theta.start2 <- c(1.06, 0.08, 0.04, 0.097, 0.00008, 0.0008, 0.0008) out.optim <- optim(theta.start1, mlog, nx = 2, nz = 2, dt = dat, hessian = T)
par.theta1 <- out.optim$par
out.optim <- optim(theta.start2, mlog, nx = 2, nz = 2, dt = dat, hessian = T)
par.theta2 <- out.optim$par

How can I set up concrete starting values?

Any advices will be appreciated.

Looking forward to hearing from you.

Sincerely,
Dong-hyun Oh



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. Received on Mon 16 Jun 2008 - 18:09:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 16 Jun 2008 - 18:30:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive