Fits a mixture of `k` components, where each component can be either a Binomial or a Beta-Binomial random variable. This function take as input two paramters that determine the possible numer of compoennets, for both distributions, and creates all possible input combinations to fit the model.

The best mode is scored using the Integrated Classification Likelihood, an extension of the Bayesian Information Criterion. Through one parameters it is possible to switch to the Bayesian Information Criterion.

Multiple fits can be computed, and a parameter controls when the Expectation Maximization algorithm should stop.

bmixfit(
  data,
  K.Binomials = 1:2,
  K.BetaBinomials = 0,
  epsilon = 1e-08,
  samples = 2,
  score = "ICL",
  silent = FALSE,
  description = "My BMix model"
)

Arguments

data

A matrix or dataframe with two columns, the first one must represent the number of successes in the Binomial trials, the second the total number of trials.

K.Binomials

A vector of values that represents how many Binomial components should be fit to the data.By default this parameter is set to `c(0:2)`.

K.BetaBinomials

A vector of values that represents how many Beta-Binomial components should be fit to the data. By default this parameter is set to `0`.

epsilon

The parameter that controls when the Expectation Maximization algorithm should stop. This is compared to the variation in the negative loglikelihood.

samples

Number of Expectation Maximization fits that should be computed per configuration of mixture.

score

The score for model selection, any of `NLL`, `BIC` or `ICL`.

silent

If `FALSE`, does not print outputs.

Value

An object of class bmix that represents a fit mixture of this package.

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.693953013534422.
#> • Binomial Bin 2 with mean = 0.390674628032939.
#> Score (model selection): ICL = 738.16.
print(x)
#> ── [ 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.693953013534422.
#> • Binomial Bin 2 with mean = 0.390674628032939.
#> Score (model selection): ICL = 738.16.