This function extracts the clustering assignments and the latent variables from the fit. This function must receive in input exactly the same data used for the fit.

Clusters(x, data)

Arguments

x

An object of class bmix that represents a fit.

data

The data used to compute the fit x.

Value

The input data transformed into a tibble, augmented with a column for the cluster labels and the latent variables.

Examples

# The same dataset used in the package vignette data = data.frame(successes = c(rbinom(30, 100, .4), rbinom(70, 100, .7)), trials = 100) # BMix fit with default parameters x = bmixfit(data)
#>
#> ── BMix fit ────────────────────────────────────────────────────────────────────
#>
#> Binomials k_B = 1 and 2, Beta-Binomials k_BB = 0; 4 fits to run.
#>
#> Bmix best fit completed in 0 mins
#>
#> ── [ BMix ] My BMix model n = 100 with k = 2 component(s) (2 + 0) ──────────────
#> • Clusters: π = 70% [Bin 2] and 30% [Bin 1], with π > 0.
#> • Binomial Bin 1 with mean = 0.398001536600375.
#> • Binomial Bin 2 with mean = 0.705854422544301.
#> Score (model selection): ICL = 730.76.
Clusters(x, data)
#> # A tibble: 100 x 5 #> successes trials cluster `Bin 1` `Bin 2` #> <int> <dbl> <chr> <dbl> <dbl> #> 1 35 100 Bin 1 1.00 5.74e-12 #> 2 37 100 Bin 1 1.00 7.34e-11 #> 3 36 100 Bin 1 1.00 2.05e-11 #> 4 38 100 Bin 1 1.00 2.62e-10 #> 5 46 100 Bin 1 1.00 7.03e- 6 #> 6 47 100 Bin 1 1.00 2.51e- 5 #> 7 40 100 Bin 1 1.00 3.36e- 9 #> 8 40 100 Bin 1 1.00 3.36e- 9 #> 9 44 100 Bin 1 1.00 5.49e- 7 #> 10 37 100 Bin 1 1.00 7.34e-11 #> # … with 90 more rows