Hypergeometric distribution is connected with taking n items (no replacement) from N items, where k items labeled success and N-k items failure. The success number x of n selected items follows hypergeometric distribution. To calculate the probability of x using R, function dhyper() can be applied. The basic form of the function is:
dhyper(x, m, n, k)
Where
m and n represents the success and failure items in total,
k represents k items to select, and
x represent success items from those selected.
Next example show the calculation of probability of white ball, from a group of white ball and black ball urn.
# Specify x-values for dhyper function
#x between 4 and 10, integers
x_dhyper <- seq(4, 10, by = 1)
x_dhyper
#output
4 5 6 7 8 9 10
# Apply dhyper function, to calculate probability of x white ball
#selecting 16 balls from from 15 white balls, and 10 black balls,
y_dhyper <- dhyper(x_dhyper, m = 15, n = 10, k = 16)
# Plot dhyper values
plot(y_dhyper)
0 Comments