2
votes

I am trying to simulate a self-made probability problem "Suppose there are 6 households living in a unit of an apartment complex. On average, a single household does laundry twice a week for 2 hours each time. Find the probability that any two households doing laundry at the same time."

However, I was able to simulate for the case when a single household does laundry ONCE a week (R code below) and would appreciate any help on extending the code to the scenario for doing laundry TWICE a week.

I also attempted to find a theoretical solution but it did not match with my simulation results below. Any help is appreciated. Thanks!

dist.min <- function(x) {
    ifelse(min(dist(x)) <= 2 * 3600 - 1, T, F)
}

set.seed(12345)
N <- 100000
mat <- matrix(sample(1:(24 * 60 * 60 * 7), N * 6, replace = T), ncol = 6)
is.same <- apply(mat, 1, dist.min)
mean(is.same) # 0.30602
1
twice a week means one per half-week, you can change the sample to 1:(24 * 60 * 60 * 7/2)Reza

1 Answers

0
votes

Hi if I understood the problem correctly I would take such an approach.

This is binomial distribution where n=6 number of families and p of success that a family is doing laundry is 4/168 as 4 hours divided by number of week hours.

Then theoretical probability of at least 2 families doing laundry at the same time is

sum(dbinom(2:6,6,4/168))

which gives about 0.7%

And as per simulation let's create a matrix with 6 columns per each family and 10K rows as number of simulation. Then let's fill matrix with 1(doing laundry) and 0(not) where probs correspond probabilities of doing a laundry at any point in time.

Running this code I am getting about 0.7% probability of 2 or more families doing laundry at the same time

mat<-replicate(6,sample(0:1,size = 10000,replace=T,prob = c(164/168,4/168)))
table(rowSums(mat))