Computing probabilities
R provides basic commands that compute probabilities for our special families of distributions:
Each family has its own commands, but the pattern is the same.
Evaluating the PMF
To evaluate the PMF \(P(X=x)\), you use a d- command:
For example:
# P(X = 0)
dbinom(0, 5, 0.5) [1] 0.03125
# P(X = 1)
dbinom(1, 5, 0.5)[1] 0.15625
[1] 0.03125 0.15625
[1] 1
# P(0 <= Z <- 6)
dpois(0:6, 5)[1] 0.006737947 0.033689735 0.084224337 0.140373896 0.175467370 0.175467370
[7] 0.146222808
Notice that these d- commands are vectorized.
Evaluating the CDF
To evaluate the CDF \(F(q) = P(X\leq q)\), you use a p- command:
Notice right away that the p- commands and d- commands are consistent with one another:
