[R] convert ms() to optim()

From: Xiaodong Jin <close2ceo_at_yahoo.com>
Date: Fri 07 Jul 2006 - 23:18:17 EST


  How to convert the following ms() in Splus to Optim in R? The "Calc" function is also attached.    

  ms(~ Calc(a.init, B, v, off, d, P.a, lambda.a, P.y, lambda.y,   10^(-8), FALSE, 20, TRUE)$Bic,
  start = list(lambda.a = 0.5, lambda.y = 240),   control = list(maxiter = 10, tol = 0.1))    

  Calc <- function(A.INIT., X., V., OFF., D.,   P1., LAMBDA1., P2., LAMBDA2.,
  TOL., MONITOR., MAX.ITER., TRACE.){
  lambda1 <- abs(LAMBDA1.)
  lambda2 <- abs(LAMBDA2.)
  P <- lambda1 * P1. + lambda2 * P2.
  a <- Estimate(A.INIT., X., V., OFF., D., P,   TOL., MONITOR., MAX.ITER.)
  Ita <- OFF. + X. %*% a
  Mu <- c(exp(Ita))
  Wt <- Mu * V.
  Bt.W.B <- t(X.) %*% (Wt * X.)
  BtWBplusP <- Bt.W.B + P
  Rhs <- Bt.W.B %*% a + t(X.) %*% (V. * (D. - Mu))   a <- solve(BtWBplusP, Rhs)
  Tr <- sum(diag(solve(BtWBplusP, Bt.W.B)))   y.init <- D.
  y.init[D.==0] <- 10^(-4)
  Dev <- 2*sum( V. * D.*log(y.init/Mu) )   Bic <- Dev + log(sum(V.)) * Tr
  Hazard <- Ita - OFF.
  if (TRACE. == TRUE) cat(lambda1, lambda2, Bic, "\n")   return(a, Hazard, Tr, Dev, Bic, BtWBplusP)    

  Thanks,
  Shelton                  


        [[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 Fri Jul 07 23:23:05 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 14 Jul 2006 - 04:14:19 EST.

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