Re: [R] convert ms() to optim()

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Fri 14 Jul 2006 - 03:24:40 EST

          Have you worked through the examples in the help pages for 'optim' and 'nlminb'? Also, 'nls', 'nlm', and 'mle{stats4}' provide related capabilities.

          If you'd like further help from this groups, please submit another post. To increase your chances of a quick, informative response, I suggest you include a simple, self-contained example of something you tried that didn't produce what you expected, as suggested in the posting guide! "www.R-project.org/posting-guide.html".

	  Best Wishes,
	  Spencer Graves	  	

Xiaodong Jin wrote:
> 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



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 14 03:30:37 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 - 06:14:40 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.