You are on page 1of 12

Probability problem solution

strategy in R
Hands on R Session
Binomial distribution in R
• The function dbinom returns the value of the probability
density function (pdf) of the binomial distribution given a
certain random variable x, number of trials (size) and
probability of success on each trial (prob).
• The syntax for using dbinom is as follows:
• dbinom(x, size, prob)
• The function pbinom returns the value of the cumulative
density function (cdf) of the binomial distribution given a
certain random variable q, number of trials (size) and
probability of success on each trial (prob).
• The syntax for using pbinom is as follows:
• pbinom(q, size, prob)
Examples
• Bob makes 60% of his free-throw attempts. If he shoots 12 free
throws, what is the probability that he makes exactly 10?
• dbinom(x=10, size=12, prob=.6)
• [1] 0.06385228
• Suppose Tyler scores a strike on 30% of his attempts when he bowls.
If he bowls 10 times, what is the probability that he scores 4 or fewer
strikes?
• pbinom(4, size=10, prob=.3)
• [1] 0.8497317
Poisson distribution in R
• The dpois function finds the probability that
a certain number of successes occur based
on an average rate of success.
• The following syntax is used :
• dpois(x, lambda)
• The ppois function finds the probability that
a certain number of successes or less occur
based on an average rate of success,
• The following syntax is used :
• ppois(q, lambda)
Examples
• It is known that a certain website makes 10 sales per hour. In a given
hour, what is the probability that the site makes exactly 8 sales?
• dpois(x=8, lambda=10)
• [1] 0.112599
• It is known that a certain website makes 10 sales per hour. In a given
hour, what is the probability that the site makes more than 8 sales?
• 1 - ppois(q=8, lambda=10)
• [1]0.6671803
Uniform Distributions
• A uniform distribution is a probability distribution in which
every value between an interval from a to b is equally likely to
be chosen.
• The mean of the distribution is μ = (a + b) / 2
• The variance of the distribution is σ2 = (b – a)2 / 12
• The standard deviation of the distribution is σ
Uniform Distributions in R
• dunif(x, min, max) – calculates the probability
density function (pdf) for the uniform distribution
where x is the value of a random variable,
and min and max are the minimum and maximum
numbers for the distribution, respectively.
• punif(x, min, max) – calculates the cumulative
distribution function (cdf) for the uniform distribution
where x is the value of a random variable,
and min and max are the minimum and maximum
numbers for the distribution, respectively.
Examples
• The amount of time, in minutes, that a person must wait for a bus is
uniformly distributed between zero to 20 minutes. If you arrive at the bus
stop, what is the probability that the bus will show up in 8 minutes or less?
• punif(8, min=0, max=20)
• [1] 0.4
• The weight of a certain species of frog is uniformly distributed between 15
and 25 grams. If you randomly select a frog, what is the probability that the
frog weighs between 17 and 19 grams?
• punif(19, 15, 25) - punif(17, 15, 25)
• [1] 0.2
Normal Distribution
• What are the mean and variance of a normal random variable
• 𝐸 𝑋 =𝜇
• 𝑉𝑎𝑟 𝑋 = 𝜎 2
• 𝑆𝑑 𝑋 = 𝜎

• If we have data that looks like it has a bell curve we can approximate
it with a normal by setting
1 𝑛 1
• 𝜇Ƹ = σ 𝑋 and 𝜎ො = σ𝑛𝑖=1 𝑋𝑖 − 𝜇Ƹ 2
𝑛 𝑖=1 𝑖 𝑛−1
Normal distribution
• The function dnorm returns the value of the probability density function
(pdf) of the normal distribution given a certain random variable x, a
population mean μ and population standard deviation σ.
• The syntax for using dnorm is as follows:
• dnorm(x, mean, sd)
• The function pnorm returns the value of the cumulative density function
(cdf) of the normal distribution given a certain random variable q, a
population mean μ and population standard deviation σ.
• The syntax for using pnorm is as follows:
• pnorm(q, mean, sd)
• Put simply, pnorm returns the area to the left of a given value x in the
normal distribution. If you’re interested in the area to the right of a given
value q, you can simply add the argument lower.tail = FALSE
Examples
• find the value of the normal distribution pdf at x=10 with mean=20
and sd=5
• dnorm(x=10, mean=20, sd=5)
• [1] 0.01079819
• find percentage of males that are taller than 74 inches in a population
with mean = 70 and sd = 2
• pnorm(74, mean=70, sd=2, lower.tail=FALSE)
• [1] 0.02275013
Probability Density
Function (pdf)
P(X=x)
(dbinom)
Binomial(N,p)
Cumulative Density
Function (cdf)
P(X≥x or X≤x)
(pbinom)
Discrete
Probability Density
Function (pdf)
P(X=x)
(dpois)
Poisson (l)
Cumulative Density
Function (cdf)
P(X≥x or X≤x)
(ppois))
Probability
Probability Density
Function (pdf)
P(X=x)
(dunif)
Uniform (m,s)
Cumulative Density
Function (cdf)
P(X≥x or X≤x)
(punif))
Continues
Probability Density
Function (pdf)
P(X=x)
(dnorm)
Normal (m,s)
Cumulative Density
Function (cdf)
P(X≥x or X≤x)
(pnorm)

You might also like