9.1 #10

Question: Find the probability that among 10,000 random digits the digit 3 appears not more than 931 times.

Answer: Using simulation, we get about 1.097% probability (or something close to that) that 3 appears not more than 931 times.

n<-100000
trials<-rep(NA, n)

for(i in 1:n){
  temp<-sample(c(0:9),10000, replace=TRUE)
  count<-length(temp[temp==3])
  trials[i]<-count
}

#histogram
hist(trials)

#probability
length(trials[trials<=931])/length(trials)
## [1] 0.01063
#standard deviation
sd(trials)
## [1] 30.11029

If we try a more precise approach, we would expect that since 3 has a probability of occurring 1/10 of the time (0-9 = 10 digits), then 1/10*10000 = 1000 is the expected count (i.e., sample mean) in any sample. If we do this many many times, the central limit theorem applies and we would expect the average of these sample means to in fact be 1000. This will take on a normal distribution, so we just need to determine the standard deviation.

This is calculated as sqrt(10000*1/10*9/10) = 30, which is pretty close to the simulation sd of 30.02608 (or something close to that), so can use this to calculate a probability using the normal distribution. When we do so, we get 1.072% so pretty close to what the simulation showed.

pnorm(931, mean=1000, sd=sqrt(10000*1/10*9/10), lower.tail = TRUE)
## [1] 0.01072411