## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 4.5)

## ----one-d--------------------------------------------------------------------
library(clusta)
set.seed(1)
x <- c(rnorm(60, 0), rnorm(60, 6), rnorm(60, 13))
fit <- clusta(x, k = 3)
fit

## ----estvar-------------------------------------------------------------------
skewed <- c(rexp(150, 1), rexp(150, 0.3) + 6)
est <- clusta(skewed, k = 3, method = "estvar", objective = "neyman")
summary(est)

## ----parametric, eval = requireNamespace("fitdistrplus", quietly = TRUE)------
par_fit <- clusta(skewed, k = 3, method = "parametric")
par_fit$distr

## ----exact2d, fig.height = 5--------------------------------------------------
X <- rbind(matrix(rnorm(120, 0), 60, 2),
           matrix(rnorm(120, 5), 60, 2))
fit_2d <- clusta(X, k = 2, method = "exact2d")
plot(fit_2d)

## ----projection---------------------------------------------------------------
iris_fit <- clusta(iris[, 1:4], k = 3, method = "projection")
table(cluster = iris_fit$cluster, species = iris$Species)

## ----gap----------------------------------------------------------------------
sweep_fit <- clusta(X, k = 2, method = "sweep")
c(within_ss = sweep_fit$tot.withinss,
  lower_bound = sweep_fit$lower_bound,
  gap_percent = sweep_fit$gap_pct)

## ----elbow, fig.width = 8, fig.height = 3.4-----------------------------------
clusta_elbow(x, k_range = 1:7, method = "wcss")

