#rhyper(k,N1,N2,n)generates k random values from this hypergeometric distribtion
rhyper(10,12,6,4)

#dhyper(x,N1,N2,n)returns the probability of drawing x black chiops from a bag that contains N1 black and
#N2 white chips when n chips are drawn without replacement. As usual, x amy be a vector.
dhyper(0:4,12,6,4)

#phyper(x,N1,N2,n)returnsthe CDF.
phyper(0:4,12,6,4)

#qhyper(p,N1,N2,n)returns the smallest value x such that phyper(x,N1,N2,n)>=p. 
phyper(2,12,6,4)
qhyper(0.4068627,12,6,4)

#Example. A statistics class includes 19 women and 11 men. A team of 5 people is selected at random.
#1.What is the probability that a team includes at most 3 women? At least 3 women?
phyper(3,19,11,5)
#At least 3 women means the complementary of at most 2
1-phyper(2,19,11,5)

#2.Construct a probabilityhistogram for this experiment.
x <-0:5
probs<-dhyper(x,19,11,5)
probs

#3. Simulate the composition of 50 such teams.
rhyper(50,19,11,5)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: