ebb_fit_mixture: Fit a mixture of beta-binomial distributions

Description Usage Arguments Examples

Description

Fit a mixture of beta-binomial distributions

Usage

1
2
3
4
5
ebb_fit_mixture(tbl, x, n, clusters = 2, iter_max = 10, nstart = 1L,
  vary_size = FALSE, method = "mle", ...)

ebb_fit_mixture_(tbl, x, n, clusters = 2, iter_max = 10, nstart = 1L,
  vary_size = FALSE, method = "mle", ...)

Arguments

tbl

A table.

x

An expression for the number of successes, evaluated within the table.

n

An expression for the total number of trials, evaluated within the table.

clusters

Number of clusters, default 2

iter_max

Maximum number of iterations to perform

nstart

Number of random restarts

vary_size

Allow each cluster to have a prior probability. Use caution as this may lead to clusters being lost entirely. If setting this to true, it may help to use a high number of random restarts.

method

Method passed on to ebb_fit_prior.

...

Extra arguments passed on to ebb_fit_prior.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
library(dplyr)
library(tidyr)
library(purrr)

# simulate some data
set.seed(2017)
sim_data <- data_frame(cluster = 1:2,
                       alpha = c(30, 35),
                       beta = c(70, 15),
                       size = c(300, 700)) %>%
  by_row(~ rbeta(.$size, .$alpha, .$beta)) %>%
  unnest(p = .out) %>%
  mutate(total = round(rlnorm(n(), 5, 2) + 1),
         x = rbinom(n(), total, p))

mm <- ebb_fit_mixture(sim_data, x, total)
mm

# assignments of points to clusters
mm$assignments

# how accurate was it?
mm$assignments %>%
  count(cluster, .cluster)

library(ggplot2)
ggplot(mm$assignments, aes(x / total, fill = .cluster)) +
  geom_histogram()

dgrtwo/ebbinom documentation built on May 15, 2019, 7:23 a.m.