if (requireNamespace('data.table', quietly = TRUE)) {
# don't multi-thread during CRAN checks
data.table::setDTthreads(1)
}
set.seed(52523)
N = 100
pgray = 0.1 # rate of gray horses in the population
herd_size = round(runif(N, min=25, 50))
ngray = rbinom(N, herd_size, pgray)
hdata = data.frame(n_gray=ngray, herd_size=herd_size)
# observed rate of gray horses in each herd
hdata$rate_gray = with(hdata, ngray/herd_size)
title = "Observed prevalence of gray horses in population"
PlotDistDensityBeta(hdata, "rate_gray", title) +
ggplot2::geom_vline(xintercept = pgray, linetype=4, color="maroon") +
ggplot2::annotate("text", x=pgray+0.01, y=0.01, hjust="left",
label = paste("True prevalence =", pgray))
# # no sd lines
# PlotDistDensityBeta(hdata, "rate_gray", title,
# sd_color=NULL)
Run the code above in your browser using DataLab