假设被邀请参加婚礼的人的决定是独立的,则可以将参加婚礼的客人人数建模为伯努利随机变量的总和,这些变量不一定具有相同的成功概率。这对应于泊松二项分布。
令为一个随机变量,对应于受邀者中将参加婚礼的人数。预期的参与者数量确实是各个“显示”概率的总和,即
给定概率质量函数的形式并不容易确定置信区间。但是,它们很容易通过蒙特卡洛模拟进行近似。N p i E (X )= N ∑ i = 1 p i。XNpi
E(X)=∑i=1Npi.
下图显示了一个示例,该示例基于10000个模拟场景(右)使用230个受邀人员的虚假出现概率显示了参加婚礼的人数(左)。下面显示了用于运行此模拟的R代码;它提供了置信区间的近似值。
## Parameters
N <- 230 # Number of potential guests
nb.sim <- 10000 # Number of simulations
## Create example of groups of guests with same show-up probability
set.seed(345)
tmp <- hist(rbeta(N, 3, 2), breaks = seq(0, 1, length.out = 21))
p <- tmp$breaks[-1] # Group show-up probabilities
n <- tmp$counts # Number of person per group
## Generate number of guests by group
guest.mat <- matrix(NA, nrow = nb.sim, ncol = length(p))
for (j in 1:length(p)) {
guest.mat[, j] <- rbinom(nb.sim, n[j], p[j])
}
## Number of guest per scenario
nb.guests <- apply(guest.mat, 1, sum)
## Result summary
par(mfrow = c(1, 2))
barplot(n, names.arg = p, xlab = "Probability group", ylab = "Group size")
hist(nb.guests, breaks = 21, probability = TRUE, main = "", xlab = "Guests")
par(mfrow = c(1, 1))
## Theoretical mean and variance
c(sum(n * p), sum(n * p * (1-p)))
#[1] 148.8500 43.8475
## Sample mean and variance
c(mean(nb.guests), var(nb.guests))
#[1] 148.86270 43.23657
## Sample quantiles
quantile(nb.guests, probs = c(0.01, 0.05, 0.5, 0.95, 0.99))
#1% 5% 50% 95% 99%
#133.99 138.00 149.00 160.00 164.00