0% found this document useful (0 votes)
4 views6 pages

Lab 7

This document is a lab guide focused on uniform, normal, and lognormal distributions in statistics. It provides definitions, formulas, and R functions for each distribution, along with examples and exercises for practical application. The lab is intended to be completed in one session and covers key concepts and calculations related to these probability distributions.

Uploaded by

goyal03tarang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Lab 7

This document is a lab guide focused on uniform, normal, and lognormal distributions in statistics. It provides definitions, formulas, and R functions for each distribution, along with examples and exercises for practical application. The lab is intended to be completed in one session and covers key concepts and calculations related to these probability distributions.

Uploaded by

goyal03tarang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LAB # 7 : Uniform, Normal, and Lognormal Distributions

Introduction
This lab is concerned with three important continuous probability distributions, namely uniform,
normal, and lognormal distributions. This lab is designed to be completed in one session.

Uniform Distribution
We say that a random variable X has a uniform distribution on the interval [a, b], if it has density
function f , given by 
 1
, a≤x≤b
f (x) = b−a
 0, elsewhere.

We write X ∼ U [a, b]. The random variable X can model a randomly chosen point from the interval
[a, b], where each choice is equally likely.
There are four basic functions in R for calculating the probability in uniform distribution.

• dunif (x, a, b) returns the probability density function evaluated at x in [a, b]. We can use this
function to plot the density function.

x<−seq(0,10,by=0.1)
y<−dunif(x,0,10)
plot(x,y)

• punif (x, a, b) returns the cumulative probability P (X ≤ x) for uniform distribution.

punif(5,−10,10)

1
[1] 0.75
punif(0:5,−10,10)
[1] 0.50 0.55 0.60 0.65 0.70 0.75

• qunif (p, a, b) is the inverse cdf of the uniform distribution. It returns the value x such that
punif (x, a, b) = p.

qunif(c(0.25,0.5,0.75),0,10)
[1] 2.5 5 7.5
punif(2:8,0,10)
[1] 0.2 0.3 0.4 0.5 0.6 0.7 0.8

• runif (n, a, b) generates n random values from the uniform distribution.

runif(10,−10,10)
[1] −2.1586878 0.7646733 6.0913344 8.8848749 −9.5967198 8.5564495
[7] −3.9578399 3.8082255 −4.7050247 −3.0242637

Example 1: A bus arrives every 10 minutes at a bus stop. It is assumed that the waiting time for a
particular individual is a random variable with a continuous uniform distribution.

1. What is the probability that the individual waits more than 7 minutes?

2. What is the probability that the individual waits between 2 and 7 minutes?

3. Simulate the situation by taking 100 random numbers and produce a histogram of the results.

Sol.

(a) 1−punif(7,0,10)
[1] 0.3
(b) punif(7,0,10)−punif(2,0,10)
[1] 0.5
(c) y <− runif(100,0,10)
hist(y)

Normal Distribution
The normal (or Gaussian) distribution is the most important distribution in the study of statistics. We
say that a random variable has a normal distribution with parameters µ and σ 2 if its density function
f is given by
1 −1 x−µ 2
f (x) = √ e 2 ( σ ) , x ∈ R.
σ 2π
We write X ∼ N (µ, σ 2 ). The parameters µ and σ 2 turn out to be the mean and variance of the
distribution, respectively. If µ = 0 and σ = 1 then
1 −x2
f (x) = √ e 2 ,

and the distribution is known as a standard normal distribution.
There are four basic functions in R similar to uniform distribution.

2
• dnorm(x, µ, σ) returns the value of the probability density function at x. We can use this function
to plot the density function of the normal distribution.

x<−seq(0,100,by=0.1)
png(file="[Link]") % SAVE THE FILE as [Link]
y<− dnorm(x,55,21)
plot(x,y)
[Link]()

• pnorm(x, µ, σ) returns the cumulative probability P (X ≤ x) and x can be a vector.

pnorm(5,14,8)
[1] 0.1302945

3
pnorm(12:14,14, 0.81)
[1] 0.00677199 0.10849568 0.50000000

• qnorm(p, µ, σ) returns the value x such that pnorm(x, µ, σ) = p. This function finds the quantiles
for the normal distribution.

qnorm(0.60,55,19)
[1] 59.81359
qnorm(c(0.25,0.5,0.75),55,19)
[1] 42.18469 55.00000 67.81531

• rnorm(n, µ, σ) generates n random numbers from the normal distribution.

rnorm(10,55,19)
[1] 95.30111 72.55787 16.73742 53.34533 82.81127 57.55974 42.33415
[9] 32.98337 29.07413 33.90214

Example 2: The flipper length of a certain kind of penguin is normally distributed with mean 182.5
mm and standard deviation 5.5 mm.
1. What is the probability that a randomly selected penguin has a flipper less than 190 mm long?
More than 190 mm?
2. What is the 25th and 90th percentile for flipper length in these penguins?
3. Simulate 50 random selections from this population and plot the results.
Sol.

(a) pnorm(190,182.5,5.5)
[1] 0.9331928
1−pnorm(190,182.5,5.5)
[1] 0.0668072
(b) qnorm(c(0.25,0.90),182.5,5.5)
[1] 178.7903 189.5485
(c) y<− rnorm(50,182.5,5.5)
hist(y)

Lognormal distribution
A continuous random variable X has a lognormal distribution if the random variable Y = ln(X) has
a normal distribution with mean µ and standard deviation σ. The resulting density function of X is
( −1 ln(x)−µ 2
√ 1 e 2 [ σ ] , x≥0
f (x) = 2π σ x
0, elsewhere
There are four basic functions in R. In R, the parameters meanlog and sdlog refer to the mean and
standard deviation of ln(X).

dlnorm(x, meanlog, sdlog, log = FALSE)


plnorm(q, meanlog, sdlog, [Link] = TRUE, log.p = FALSE)
qlnorm(p, meanlog, sdlog, [Link] = TRUE, log.p = FALSE)
rlnorm(n, meanlog, sdlog)

4
Example 3: The lifetime, in thousands of miles, of a certain type of electronic control for locomotives
has an approximately lognormal distribution with µ = 5.149 and σ = 0.737. Find the 5th and 10th
percentile of the life of such an electronic control.
Sol.

qlnorm(0.05,5.149,0.737)
[1] 51.2514
qlnorm(0.10,5.149,0.737)
[1] 66.98686

Exercises:

1. In a Wi-Fi network, a device chooses a random backoff time uniformly between 0 and 20 mil-
liseconds before retransmitting a packet.

(a) What is the probability the waiting time is between 5 ms and 12 ms? More than 15 ms?
(b) Simulate 200 random backoff times in R and plot a histogram.

2. The accuracy of a trained Machine Learning (ML) model across different test datasets is normally
distributed with mean 85% and standard deviation 3%.

(a) What is the probability the accuracy exceeds 90%?


(b) What is the probability accuracy lies between 80% and 88%?
(c) Find the first quartile and median accuracy.
(d) Generate 200 random samples and visualize the distribution.

3. Imagine a class’s exam scores follow a normal distribution. If the average score is 60 and the
standard deviation is 10.

(a) What is the probability of the scores between 80 and 90? More than 90?
(b) What are the score values corresponding to first quartile and median?
(c) Simulate the results for 100 random situations and plot the results.

5
4. File sizes (in MB) stored on a cloud server follow a lognormal distribution with µ = 2.5 and
σ = 0.8.

(a) Find the probability a file exceeds 50 MB.


(b) Find the median file size.
(c) Find the 90th percentile.
(d) Simulate 300 file sizes and plot the histogram.

5. Suppose random variable Y follows a lognormal distribution with parameters µ = 1 and σ = 1.


Let Y1 = 1.25Y .

(a) Find the probability that Y1 exceeds 1.


(b) The 40th and 80th percentile of Y1 .

You might also like