1 |
Y |
|
Xquali |
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 | ##---- 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 (Y, Xquali)
{
Xquali_k <- as.list(unique(Y))
if (is.null(dim(Xquali))) {
j <- 1
for (i in unique(Y)) {
Xquali_k[[j]] <- data.frame(MAT = Xquali[Y == i])
j <- j + 1
}
alpha_k <- as.list(unique(Y))
for (k in 1:length(alpha_k)) {
variables <- vector("list", 1)
X <- as.numeric(table(Xquali_k[[k]])/nrow(Xquali_k[[k]]))
variables[[1]] <- data.frame(proba = X, modalite = unlist(attributes(table(Xquali_k[[k]])/nrow(Xquali_k[[k]]))$dimnames))
for (h in unique(Xquali)) {
if (!(h %in% variables[[1]]$modalite)) {
mod_miss <- data.frame(proba = 0, modalite = h)
variables[[1]] <- rbind(variables[[1]], mod_miss)
}
}
variables[[1]]$modalite <- as.character(variables[[1]]$modalite)
variables[[1]] <- variables[[1]][order(variables[[1]]$modalite,
decreasing = F), ]
alpha_k[[k]] <- variables
}
}
else {
j <- 1
for (i in unique(Y)) {
Xquali_k[[j]] <- data.frame(MAT = Xquali[Y == i,
])
j <- j + 1
}
alpha_k <- as.list(unique(Y))
for (k in 1:length(alpha_k)) {
variables <- as.list(colnames(Xquali))
for (j in 1:length(variables)) {
X <- as.numeric(table(Xquali_k[[k]][, j])/nrow(Xquali_k[[k]]))
variables[[j]] <- data.frame(proba = X, Var = variables[[j]],
modalite = unlist(attributes(table(Xquali_k[[k]][,
j])/nrow(Xquali_k[[k]]))$dimnames))
for (h in unique(Xquali[, j])) {
if (!(h %in% variables[[j]]$modalite)) {
mod_miss <- data.frame(proba = 0, Var = unique(variables[[j]]$Var),
modalite = h)
variables[[j]] <- rbind(variables[[j]], mod_miss)
}
}
variables[[j]]$modalite <- as.character(variables[[j]]$modalite)
variables[[j]] <- variables[[j]][order(variables[[j]]$modalite,
decreasing = F), ]
}
alpha_k[[k]] <- variables
}
}
return(alpha_k)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.