R Analysis for Probability Distributions
June 28, 2025 | by Bloom Code Studio
As mentioned earlier, a quick statistical summary can be generated using the summary() command in R, where the usage is summary(data_vector).
R has extensive built-in libraries for calculating confidence intervals, hypothesis testing, and working with various probability distributions such as binomial, Poisson, normal, chi-square, and other probability distributions.
As discussed in Measures of Center, data scientists are often interested in various probability distributions such as the normal distribution, binomial distribution, and Poisson distribution. Excel provides built-in functions to analyze many probability distributions.
R uses the pnorm command to find the area under the normal curve to the left of a specified value:
Usage: pnorm(x_value, mean, standard_deviation)
where pnorm returns the probability that a random variable having a given mean and standard deviation is less than x_value.
EXAMPLE B.2
Problem
Birth weights for newborns in the United States are normally distributed with mean of 3,400 grams and standard deviation of 500 grams.
- Use R to find the probability that a random newborn infant weighs less than 4,000 grams.
- Use R to find the probability that a random newborn infant weighs more than 3,000 grams.
Solution
For part (a), use the pnorm command as follows:
pnorm(4000, 3400, 500)
which returns the probability result of:
[1] 0.8849303
For part (b), an option on the pnorm command “lower.tail=FALSE” can calculate the area to the right of a given x-value:
pnorm(3000, 3400, 500, lower.tail=FALSE)
which returns the probability result of:
[1] 0.7881446
R also provides a built-in function for the binomial distribution as follows:
Binomial distribution:
Usage: pbinom(k, n, p)
where n is the number of trials, p is the probability of success, and k is the number of successes for which the probability is desired.
EXAMPLE B.3
Problem
A data scientist conducts a survey for a sample of 20 people and asks the survey question: “Did you find the website for ABC corporation easy to navigate?” From past data, the probability that a random person found the website easy to navigate was 65%. Use R to find the probability that 13 out of the 20 respond that they find the website easy to navigate.
Solution
Use the pbinom command as follows:
pbinom(13, 20, 0.65)
which returns the probability result of:
[1] 0.5833746
R also provides a built-in function for the binomial distribution as follows:
Binomial distribution:
Usage: dbinom(k, n, p)
where n is the number of trials, p is the probability of success, and k is the number of successes for which the probability is desired.
EXAMPLE B.4
Problem
A data scientist conducts a survey for a sample of 20 people and asks the survey question: “Did you find the website for ABC corporation easy to navigate?” From past data, the probability that a random person found the website easy to navigate was 65%. Use R to find the probability that 13 out of the 20 responds that they find the website easy to navigate.
Solution
Use the dbinom command as follows:
dbinom(13, 20, 0.65)
which returns the probability result of:
[1] 0.1844012
R also provides a built-in function for the Poisson distribution as follows:
Poisson distribution:
Usage: dpois(k, mu)
where mu is the mean of the Poisson distribution and k is the number of successes for which the probability is desired.
EXAMPLE B.5
Problem
A traffic engineer investigates a certain intersection that has an average of 3 accidents per month. Use R to find the probability of 5 accidents in a given month.
Solution
Use the ppois command as follows:
dpois(5, 3)
which returns the probability result of:
[1] 0.1008188
RELATED POSTS
View all