Skip to contents

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.

Usage

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.
#> Warning: replacing previous import ‘cli::num_ansi_colors’ by ‘crayon::num_ansi_colors’ when loading ‘easypar’
#> 
#> ℹ Bmix best fit completed in 0 mins
#> 
#> ── [ BMix ] My BMix model n = 100 with k = 2 component(s) (2 + 0) ──────────────
#> • Clusters: π = 70% [Bin 1] and 30% [Bin 2], with π > 0.
#> • Binomial Bin 1 with mean = 0.705852433674751.
#> • Binomial Bin 2 with mean = 0.397997930492763.
#> ℹ Score (model selection): ICL = 730.34.

Clusters(x, data)
#> # A tibble: 100 × 5
#>    successes trials cluster  `Bin 1` `Bin 2`
#>        <int>  <dbl> <chr>      <dbl>   <dbl>
#>  1        35    100 Bin 2   8.89e-12   1.000
#>  2        37    100 Bin 2   1.13e-10   1.000
#>  3        36    100 Bin 2   3.17e-11   1.000
#>  4        38    100 Bin 2   4.03e-10   1.000
#>  5        46    100 Bin 2   1.05e- 5   1.000
#>  6        47    100 Bin 2   3.75e- 5   1.000
#>  7        40    100 Bin 2   5.12e- 9   1.000
#>  8        40    100 Bin 2   5.12e- 9   1.000
#>  9        44    100 Bin 2   8.28e- 7   1.000
#> 10        37    100 Bin 2   1.13e-10   1.000
#> # ℹ 90 more rows