# NOT RUN {
library(dplyr)
library(mclust)
set.seed(27)
centers <- tibble::tibble(
cluster = factor(1:3),
num_points = c(100, 150, 50), # number points in each cluster
x1 = c(5, 0, -3), # x1 coordinate of cluster center
x2 = c(-1, 1, -2) # x2 coordinate of cluster center
)
points <- centers %>%
mutate(
x1 = purrr::map2(num_points, x1, rnorm),
x2 = purrr::map2(num_points, x2, rnorm)
) %>%
dplyr::select(-num_points, -cluster) %>%
tidyr::unnest(c(x1, x2))
m <- mclust::Mclust(points)
tidy(m)
augment(m, points)
glance(m)
# }
Run the code above in your browser using DataLab