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)
Run the code above in your browser using DataLab