1 |
Xquali |
|
alpha_ki |
|
Xijh_i |
|
pki |
|
Y |
|
methode |
|
e |
|
nbr_iteration |
|
k |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (Xquali, alpha_ki = NULL, Xijh_i = NULL, pki = NULL,
Y = NULL, methode = "init", e = 0.1, nbr_iteration = NULL,
k)
{
if (methode == "kmodes") {
Y <- kmodes(Xquali, k)$cluster
}
else {
Y <- init_class(iris, k)
}
if (is.null(alpha_ki)) {
alpha_ki <- alphai(Y, Xquali)
}
if (is.null(Xijh_i)) {
Xijh_i <- xijh(Xquali)
}
if (is.null(pki)) {
pki <- as.numeric(table(Y)/length(Y))
}
Pki <- pki
Alphaki <- alpha_ki
p = length(colnames(Xquali))
n <- nrow(Xquali)
fkx <- fk_quali(Y, Xijh_i, alpha_ki, p = p, n = n)
f <- fx(Pki, fkx, Y)
tkx <- tk(fkx, Pki)
li <- l(f)
Qi <- Qt(tkx, fkx, Pki)
BIC <- Bic(f, Y, Xquali = Xquali)
ICL <- BIC - sum(tkx * log(tkx))
i <- 1
teta <- list()
K <- k
repeat {
Y <- apply(tkx, MARGIN = 1, which.max)
Nk <- nk(tkx)
Pk <- pk(Nk, Xquali)
Alphak <- alphak(tkx, Xijh_i, Y, Xquali)
fkx <- fk_quali(Y, Xijh_i, Alphak, p = p, n = n)
f <- fx(Pk, fkx, Y)
lf <- l(f)
tkx <- tk(fkx, Pk)
Qf <- Qt(tkx, fkx, Pk)
BIC <- Bic(f, Y, Xquali = Xquali)
ICL <- BIC - sum(tkx * log(tkx))
teta[[i]] <- list(iteration = i, Proba = Pk, Alphak = Alphak,
log_like = lf, Q = Qf, Bic = BIC, ICL = ICL, proba_individu = fkx,
part_MAP = tkx)
if (!is.null(nbr_iteration)) {
if (i >= nbr_iteration)
break
}
if (abs(li - lf) < e) {
break
}
else {
Pki <- Pk
Alphaki <- Alphak
li <- lf
i <- i + 1
}
}
return(teta)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.