Description Usage Arguments Examples
Fit a mixture of beta-binomial distributions
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", ...)
|
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 |
... |
Extra arguments passed on to |
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()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.