kproto_gower {clustMixType} | R Documentation |
k-Prototypes Clustering using Gower Dissimilarity
Description
Internal function. Computes k-prototypes clustering for mixed-type data using Gower dissimilarity.
Usage
kproto_gower(
x,
k,
lambda = NULL,
iter.max = 100,
na.rm = "yes",
keep.data = TRUE,
verbose = TRUE
)
Arguments
x |
Data frame with both numerics and factors (also ordered factors are possible). |
k |
Either the number of clusters, a vector specifying indices of initial prototypes, or a data frame of prototypes of the same columns as |
lambda |
Parameter > 0 to trade off between Euclidean distance of numeric variables and simple matching coefficient between categorical variables. Also a vector of variable specific factors is possible where the order must correspond to the order of the variables in the data. In this case all variables' distances will be multiplied by their corresponding lambda value. |
iter.max |
Maximum number of iterations if no convergence before. |
na.rm |
Character; passed from |
keep.data |
Logical whether original should be included in the returned object. |
verbose |
Logical whether information about the cluster procedure should be given. Caution: If |
Details
Internal function called by kproto
. Note that there is no nstart
argument.
Higher values than nstart = 1
can be specified within kproto
which will call kproto_gower
several times.
For Gower dissimilarity range-normalized absolute distances from the cluster median
are computed for the numeric variables (and for the ranks of the ordered factors respectively).
For factors simple matching distance is used as in the original k prototypes algorithm.
The prototypes are given by the median for numeric variables, the mode for factors and the level with the closest rank
to the median rank of the corresponding cluster.
In case of na.rm = "no"
: for each observation variables with missings are ignored
(i.e. only the remaining variables are considered for distance computation).
In consequence for observations with missings this might result in a change of variable's weighting compared to the one specified
by lambda
. Further note: For these observations distances to the prototypes will typically be smaller as they are based
on fewer variables.
Value
kmeans
like object of class kproto
:
cluster |
Vector of cluster memberships. |
centers |
Data frame of cluster prototypes. |
lambda |
Distance parameter lambda. For |
size |
Vector of cluster sizes. |
withinss |
Vector of within cluster distances for each cluster, i.e. summed distances of all observations belonging to a cluster to their respective prototype. |
tot.withinss |
Target function: sum of all observations' distances to their corresponding cluster prototype. |
dists |
Matrix with distances of observations to all cluster prototypes. |
iter |
Prespecified maximum number of iterations. |
stdization |
List of standardized ranks for ordinal variables and and an additional element |
trace |
List with two elements (vectors) tracing the iteration process:
|
Author(s)
References
Gower, J. C. (1971): A General Coefficient of Similarity and Some of Its Properties. Biometrics, 27(4), 857–871. doi:10.2307/2528823.
Podani, J. (1999): Extending Gower's general coefficient of similarity to ordinal characters. TAXON, 48, 331-340. doi:10.2307/1224438.
Examples
datasim <- function(n = 100, k.ord = 2, muk = 1.5){
clusid <- rep(1:4, each = n)
# numeric
mus <- c(rep(-muk, n),
rep(-muk, n),
rep(muk, n),
rep(muk, n))
x1 <- rnorm(4*n) + mus
# ordered factor
mus <- c(rep(-muk, n),
rep(muk, n),
rep(-muk, n),
rep(muk, n))
x2 <- rnorm(4*n) + mus
# ordered factor
quants <- quantile(x2, seq(0, 1, length.out = (k.ord+1)))
quants[1] <- -Inf
quants[length(quants)] <- Inf
x2 <- as.ordered(cut(x2, quants))
x <- data.frame(x1, x2)
return(x)
}
n <- 100
x <- datasim(n = n, k.ord = 10, muk = 2)
truth <- rep(1:4, each = n)
# calling the internal kproto_gower() directly
kgres <- kproto_gower(x, 4, verbose = FALSE)
# calling kproto gower via kproto:
kgres2 <- kproto(x, 4, verbose = FALSE, type = "gower", nstart = 10)
table(kgres$cluster, truth)
clprofiles(kgres, x)