library(tidyverse)
Beta distributions
This is fairly sketchy, just trying to see how the \(\phi\) from Harrison (2015) affect beta probability distributions.
<- seq(from = 0, to = 1, by = 0.01)
p <- seq(from = 0.1, to = 1, by = 0.1) phi
# ai <- p[1]/phi[1]
# bi <- (1-p[1])/phi[1]
#
# db <- dbeta(p, ai, bi)
<- tibble(p = NA, db = NA, betap = NA, phi = NA, .rows = 0)
probdists
for (j in 1:length(phi)) {
for (i in 1:length(p)) {
<- p[i]/phi[j]
ai <- (1-p[i])/phi[j]
bi
<- dbeta(p, ai, bi)
db
<- tibble(p, db, betap = p[i], phi = phi[j])
dbt <- rbind(probdists, dbt)
probdists
} }
ggplot(probdists |> filter(betap %in% c(0.1, 0.25, 0.5, 0.75, 0.9)),
aes(x = p, y = db, color = factor(betap))) + geom_line() +
facet_wrap("phi")
<- seq(from = 0, to = 1, by = 0.01)
testx <- dbeta(testx, ai, bi)
testbetaprob <- tibble(testx, testbetaprob)
probdist
ggplot(probdist, aes(x = testx, y = testbetaprob)) + geom_line()
Random draws
<- -2
intercept <- 0.5
beta <- seq(0, 10, 0.1)
all_x <- intercept + beta*all_x
all_logit_p
<- 1/(1+exp(-all_logit_p)) all_p
plot(all_x, all_p, type = 'l')
References
Harrison, Xavier A. 2015. “A Comparison of Observation-Level Random Effect and Beta-Binomial Models for Modelling Overdispersion in Binomial Data in Ecology & Evolution.” PeerJ 3 (July): e1114. https://doi.org/10.7717/peerj.1114.