[R] Using MASSv3's example from 8.7 in R?

Sven C. Koehler schween at snafu.de
Tue Aug 3 19:46:30 CEST 2004

Dear list!

I am interested in learning about MLE and I wonder whether it is possible
to use the examples for maximum likelihood estimation given in 8.7 in
MASSv3 with R?  AFAIU R does not have a direct replacement for S-PLUS's
ms() which the examples use for the fitting, but optim() may be of help
for me.  However, I am not sure how I can convert the use of ms() using
optim()--is there an explanation how to do this somewhere?  Thanks.

Best wishes,

Sven C. Koehler

Example from MASSv3 8.7

truehist(waiting, xlim=c(35,110), ymax=0.04, h=5)
wait.dns <- density(waiting, 200, width=10.24)
lines(wait.dns, lty=2)

lmix2 <- deriv3(
    ~ -log(p*dnorm((x-u1)/s1)/s1 + (1-p)*dnorm((x-u2)/s2)/s2),
    c("p", "u1", "s1", "u2", "s2"),
    function(x, p, u1, s1, u2, s2) NULL)

p0 <- c(p=mean(waiting < 70), u1=50, s1=5, u2=80, s2=5)

tr.ms <- function(info, theta, grad, scale, flags, fit.pars) {
    cat(round(info[3], 3), ":", siginf(theta), "\n")

wait.mix2 <- ms(~ lmix2(waiting, p, u1, s1, u2, s2),
        start=p0, data=geyser, trace=tr.ms)

More information about the R-help mailing list