if (requireNamespace('data.table', quietly = TRUE)) {
# don't multi-thread during CRAN checks
data.table::setDTthreads(1)
}
set.seed(23590)
class_size = 35
nclasses = 100
true_frate = 0.4
fdata = data.frame(n_female = rbinom(nclasses, class_size, true_frate), stringsAsFactors = FALSE)
title = paste("Distribution of count of female students, class size =", class_size)
# compare to empirical p
PlotDistCountBinomial(fdata, "n_female", class_size, title)
if(FALSE) {
# compare to theoretical p of 0.5
PlotDistCountBinomial(fdata, "n_female", class_size, title,
p = 0.5)
# Example where the distribution is not of a true single binomial
fdata2 = rbind(data.frame(n_female = rbinom(50, class_size, 0.25)),
data.frame(n_female = rbinom(10, class_size, 0.60)),
stringsAsFactors = FALSE )
PlotDistCountBinomial(fdata2, "n_female", class_size, title)
}
Run the code above in your browser using DataLab