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

