Probability Distributions
In this page:
Probability Distributions
R has built-in functions for common probability distributions, following a d/p/q/r naming convention -- rnorm() generates random normal values, dnorm() gives the density, pnorm() gives the cumulative probability, and qnorm() gives the quantile. This same pattern applies to other distributions like runif(), rbinom(), and rpois(). This built-in statistical machinery is a major reason R is popular for data analysis.
Note: The prefix tells you what the function does: r=random draw, d=density, p=cumulative probability, q=quantile.
Example: Probability Distributions
set.seed(1)
samples <- rnorm(5, mean = 0, sd = 1)
print(samples)
cat("P(X <= 0) for standard normal:", pnorm(0), "\n")
Login to try C/C++/Java/PHP code in the editor
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: