This functions plots the density of the fit, coloured according to the mixture components. This function must receive in input exactly the same data used for the fit.

plot_density(x, data, trials = round(median(data[, 2])))

Arguments

x

An object of class bmix that represents a fit.

data

The data used to compute the fit x.

trials

To compute the density a number of trials must be fixed. This parameter represents exactly that. By default the median number of trials in the input data are taken.

Value

A ggplot object.

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 1] and 30% [Bin 2], with π > 0.
#> • Binomial Bin 1 with mean = 0.712430526840376.
#> • Binomial Bin 2 with mean = 0.396695150493778.
#> Score (model selection): ICL = 755.87.
plot_density(x, data)