install.packages("mosaic")
hand <- c(0,1) #0 is right-hand; 1 is left-hand
counts <- c(105600,14400) #Add number of observations for each outcome
set.seed(12) # Seed so all students get same result
urn <- rep(hand,times=counts) #Creates a vector of left/right for number of counts
results <- replicate(5000,sum(sample(urn,size=120,replace=FALSE))) # Simulate 5000 repetitions; sum adds up number of lefties; sample 20 individuals
hist(results,breaks=c(-0.5,seq(0.5,max(results)+1.5,1)),probability=T,xlab="Number of Lefties", ylab="Relative Frequency", main = "Number of Left-Handed Mensa Members")
mensa <- data.frame(results) # Convert numeric to data frame
head(mensa,n=4)
## results
## 1 13
## 2 11
## 3 11
## 4 13
library(mosaic) #Load the Mosaic package
prop(~(results>=24),data=mensa) # Compute the proportion of results that are 24 or higher
## prop_TRUE
## 0.0088