Skip to content
Prev 199594 / 398506 Next

model based clustering with flexmix

In your model driver truncatedmodel() the fit function looks like:

z at fit <- function(x, y, w) {
para <- list(mean = mean(x), sd = sd(x), lower = lower, upper= upper)
para$df <- 4
with(para, eval(z at defineComponent))
}

w are the a-posteriori probabilities and denote the weights with which 
observations are currently assigned to each component. These weights 
are not used in your fit function and hence, the parameters of each 
component are estimated identically using the whole sample. Please 
modify the fit function to take the weights into account for example by

z at fit <- function(x, y, w) {
    para <- cov.wt(y, wt = w)[c("center", "cov")]
    para$df <- (3 * ncol(y) + ncol(y)^2)/2
    if (diagonal) {
         para$cov <- diag(diag(para$cov))
         para$df <- 2 * ncol(y)
    }
    with(para, eval(z at defineComponent))
}

Please also note that your fit function is not appropriate because you
also have to take the truncation into account in the M-step. See for
example for grouped and truncated data:

G. McLachlan and P. Jones (1988) Fitting Mixture Models to Grouped and
Truncated Data via the EM Algorithm. Biometrics, 44(2): 571-578.

Best,
Bettina
Giovanni Luca Ciampaglia wrote: