Learn R Programming

Momocs (version 1.4.1)

KMEDOIDS: KMEDOIDS

Description

A basic implementation of kmedoids on top of cluster::pam Beware that morphospaces are calculated so far for the 1st and 2nd component.

Usage

KMEDOIDS(x, k, metric = "euclidean", ...)

# S3 method for default KMEDOIDS(x, k, metric = "euclidean", ...)

# S3 method for Coe KMEDOIDS(x, k, metric = "euclidean", ...)

# S3 method for PCA KMEDOIDS(x, k, metric = "euclidean", retain, ...)

Value

see cluster::pam. Other components are returned (fac, etc.)

Arguments

x

a Coe or PCA object

k

numeric number of centers

metric

one of euclidean (default) or manhattan, to feed cluster::pam

...

additional arguments to feed cluster::pam

retain

when passing a PCA how many PCs to retain, or a proportion of total variance, see LDA

See Also

Other multivariate: CLUST(), KMEANS(), LDA(), MANOVA_PW(), MANOVA(), MDS(), MSHAPES(), NMDS(), PCA(), classification_metrics()

Examples

Run this code
data(bot)
bp <- PCA(efourier(bot, 10))
KMEANS(bp, 2)

set.seed(123) # for reproducibility on a dummy matrix
matrix(rnorm(100, 10, 10)) %>%
KMEDOIDS(5)

# On a Coe
bot_f <- bot %>% efourier()

bot_k <- bot_f %>% KMEDOIDS(2)
# confusion matrix
table(bot_k$fac$type, bot_k$clustering)

# on a PCA
bot_k2 <- bot_f %>% PCA() %>% KMEDOIDS(12, retain=0.9)

# confusion matrix
with(bot_k, table(fac$type, clustering))
# silhouette plot
bot_k %>% plot_silhouette()

# average width as a function of k
k_range <- 2:12
widths <- sapply(k_range, function(k) KMEDOIDS(bot_f, k=k)$silinfo$avg.width)
plot(k_range, widths, type="b")

Run the code above in your browser using DataLab