# NOT RUN {
set.seed(12234)
data(tonedata)
attach(tonedata)
rmt1 <- regmix(stretchratio,tuned,nclust=1:2)
# nclust=1:2 makes the example fast;
# a more serious application would rather use the default.
rmt1$g
round(rmt1$bic,digits=2)
# start with initial parameter values
cln <- 3
n <- 150
initcoef <- cbind(c(2,0),c(0,1),c(0,2.5))
initvar <- c(0.001,0.0001,0.5)
initeps <- c(0.4,0.3,0.3)
# computation of m from initial parameters
m <- matrix(nrow=n, ncol=cln)
stm <- numeric(0)
for (i in 1:cln)
for (j in 1:n){
m[j,i] <- initeps[i]*dnorm(tuned[j],mean=initcoef[1,i]+
initcoef[2,i]*stretchratio[j], sd=sqrt(initvar[i]))
}
for (j in 1:n){
stm[j] <- sum(m[j,])
for (i in 1:cln)
m[j,i] <- m[j,i]/stm[j]
}
rmt2 <- regem(stretchratio, tuned, m, cln)
# }
Run the code above in your browser using DataLab