5-1. Continuous Random Variables
连续型随机变量
1. The Probability Distribution of a Continuous Random Variable
The probability distribution of a continuous random variable X is an assignment of probabilities to intervals of decimal numbers using a function , called a density function, in the following way: the probability that X assumes a value in the interval [a,b][a,b] is equal to the area of the region that is bounded above by the graph of the equation , bounded below by the x-axis, and bounded on the left and right by the vertical lines through a and b, as illustrated in Figure "Probability Given as Area of a Region under a Curve".

Every probability density function(p.d.f) must satisfy the following two conditions:
For all numbers , so that the graph of never drops below the x-axis.
The area of the region under the graph of and above the x-axis is 1.
For any continuous random variable :
2. Uniform Distribution
균일분포(Uniform distribution)는 유한한 실수 구간 에서 동일한 확률로 관측되는 확률변수 의 분포이다.
(p.d.f) .
Expected Values and Variance of Uniform Distribution
EXAMPLE 1. A random variable has the uniform distribution on the interval : the density function is if x is between 0 and 1 and for all other values of , as shown in Figure "Uniform Distribution on ".

Find , the probability that assumes a value greater than 0.75.
Find , the probability that assumes a value less than or equal to 0.2.
Find , the probability that assumes a value between 0.4 and 0.7.
[ Solution ]

is the area of the rectangle of height 1 and base length , hence is . See Figure 5.3 "Probabilities from the Uniform Distribution on "(a).
is the area of the rectangle of height 1 and base length , hence is . See Figure 5.3 "Probabilities from the Uniform Distribution on "(b).
is the area of the rectangle of height 1 and length , hence is . See Figure 5.3 "Probabilities from the Uniform Distribution on "(c).
library(Rstat)
# 0. Probability Distribution Function
fx <- function(x) dunif(x, 0, 1)
win.graph(7, 6); par(mfrow=c(1,1));
# E(X), Var(X) and Plot
cont.exp(fx, -0.2, 1.2, prt=TRUE, plot=TRUE)
# 1. P(X>0.75)
punif(0.75, min=0, max=1, lower.tail=FALSE)
# 2. P(X<0.2)
punif(0.2, min=0, max=1, lower.tail=TRUE)
# 3. P(0.4<X<0.7) = P(X<0.7) - P(X<0.4)
punif(0.7, min=0, max=1, lower.tail=TRUE) - punif(0.4, min=0, max=1, lower.tail=TRUE)
EXAMPLE 2. A man arrives at a bus stop at a random time (that is, with no regard for the scheduled service) to catch the next bus. Buses run every 30 minutes without fail, hence the next bus will come any time during the next 30 minutes with evenly distributed probability (a uniform distribution). Find the probability that a bus will come within the next 10 minutes.
[ Solution ]
The graph of the density function is a horizontal line above the interval from 0 to 30 and is the x-axis everywhere else. Since the total area under the curve must be 1, the height of the horizontal line is 1/30. See Figure 5.4 "Probability of Waiting At Most 10 Minutes for a Bus". The probability sought is .
By definition, this probability is the area of the rectangular region bounded above by the horizontal line bounded below by the x-axis, bounded on the left by the vertical line at 0 (the y-axis), and bounded on the right by the vertical line at 10. This is the shaded region in Figure 5.4 "Probability of Waiting At Most 10 Minutes for a Bus". Its area is the base of the rectangle times its height, .
Thus .

library(Rstat)
min <- 0
max <- 30
# 0. Probability Distribution Function
fx <- function(x) dunif(x, min, max)
# E(X), Var(X) and Plot
t <- (max-min) * 0.2
cont.exp(fx, min-t, max+t, prt=TRUE, plot=TRUE)
# 1. P(X<10)
punif(10, min=min, max=max, lower.tail=TRUE)
3. Uniform Distribution in R
Function
parameters
density function
d
dunif(x, min, max)
cumulative distribution function
p
punif(q, min, max, lower.tail =TRUE/FALSE
quantile function
q
qunif(p, min, max, lower.tail = TRUE/FALSE
random nunber generation
r
runif(n, min, max)
3-1. Uniform Distribution Plot
dunif()
Uniform Distribution of
library(ggplot2)
# uniform distribution plot (min=0, max=10)
# fun = dunif
ggplot(data.frame(x=c(-2,20)), aes(x=x)) +
stat_function(fun=dunif, args=list(min = 0, max = 10),
colour="black", size=1) +
ggtitle("Uniform Distribution of (min=1, max=10)")
3-2. Cumulative Uniform Distribution Plot
punif()
Uniform Distribution of
# Cumulative Uniform distribution plot) : fun = punif
ggplot(data.frame(x=c(-2,20)), aes(x=x)) +
stat_function(fun=punif, args=list(min = 0, max = 10),
colour="black", size=1) +
ggtitle("Cumulative Uniform Distribution of (min=0, max=10)")
3-3. Probability Calculation
Uniform Distribution of , from 0 to 3"
min = 0, max = 10 =>
# 확률 값 계산 : punif()
# punif(q, min, max, lower.tail = TRUE/FALSE)
punif(3, min=0, max=10, lower.tail=TRUE)
# Uniform Distribution of (min=1, max=10), x from 0 to 3"
ggplot(data.frame(x=c(-2,20)), aes(x=x)) +
stat_function(fun=dunif, args=list(min = 0, max = 10), colour="black", size=1) +
annotate("rect", xmin=0, xmax=3, ymin=0, ymax=0.1, alpha=0.2, fill="yellow") +
ggtitle("Uniform Distribution of (min=1, max=10), x from 0 to 3")
3-4. Quartiles
qunif(p, min, max, lower.tail=TRUE/FALSE)
Uniform Distribution of
qunif(0.3, min=0, max=10, lower.tail = TRUE)
3-5. Random Number Generation
runif(n=100, min=0, max = 10)
# Random Number Generation
ru_100 <- runif(n=100, min=0, max = 10) ; ru_100
# density plot of runif(n=100, min=0, max = 10) & adding line of 0.1 uniform probability
hist(ru_100, freq=FALSE, breaks=10, col="yellow", ylim=c(0, 0.15))
abline(h=0.1, lty=3, lwd=3, col="red")
Drawing PDF and CDF of Continuous Uniform Distribution
library(ggplot2)
library(dplyr)
options(scipen = 999, digits = 2) # sig digits
min <- 0
max <- 1
events <- seq(min, max, by=0.005)
density <- dunif(x = events, min=min, max=max)
prob <- punif(q = events, min=min, max=max, lower.tail = TRUE)
df <- data.frame(events, density, prob)
ggplot(df, aes(x = events, y = density)) +
geom_col(width=0.02) +
# geom_text(
# aes(label = round(density,2), y = density + 0.01),
# position = position_dodge(0.9),
# size = 3,
# vjust = 0
# ) +
labs(title = "PMF and CDF of Uniform Distribution",
# subtitle = "P(3).",
x = "Events (x)",
y = "Density") +
geom_line(data = df, aes(x = events, y = prob), col="blue")
Using Rstat Package
library(Rstat)
min <- 0
max <- 1
events <- seq(min, max, by=0.005)
dcol <- c("red", "blue", "green2")
# Survival Function
win.graph(7, 5)
par(mfrow=c(1,2))
plot(events, punif(q = events, min=min, max=max, lower.tail = TRUE),
type="l", lwd=2, col=dcol[1],
main="CDF of Gamma Distribution",
ylab="CDF", ylim=c(0,1))
grid(col=3)
plot(events, dunif(events, min=min, max=max),
type="l", lwd=2, col=dcol[2],
main="PDF of Gamma Distribution",
ylab="CDF", ylim=c(0,1))
grid(col=3)
4. Normal Distributions
The formula for contains two parameters and that can be assigned any specific numerical values, so long as is positive. We will not need to know the formula for , but for those who are interested it is
where and is the base of the natural logarithms.

library(ggplot2)
# uniform distribution plot (min=0, max=10)
# fun = dnorm
mu <- c(-2, -1, 1)
ggplot(data.frame(x=c(-4,4)), aes(x=x)) +
stat_function(fun=dnorm, args=list(mean = mu[1], sd = 0.25),
colour="black", size=1) +
stat_function(fun=dnorm, args=list(mean = mu[2], sd = 0.25),
colour="blue", size=1) +
stat_function(fun=dnorm, args=list(mean = mu[3], sd = 0.25),
colour="red", size=1) +
ggtitle("Normal Distribution of (mu=c(-2, -1, 1), sigma=0.25)")
The value of determines whether the bell curve is tall and thin or short and squat, subject always to the condition that the total area under the curve be equal to 1.

library(ggplot2)
# uniform distribution plot (min=0, max=10)
# fun = dnorm
mu <- 6
sd <- c(0.5, 1, 2)
ggplot(data.frame(x=c(-2,14)), aes(x=x)) +
stat_function(fun=dnorm, args=list(mean = mu, sd = sd[1]),
colour="black", size=1) +
stat_function(fun=dnorm, args=list(mean = mu, sd = sd[2]),
colour="blue", size=1) +
stat_function(fun=dnorm, args=list(mean = mu, sd = sd[3]),
colour="red", size=1) +
ggtitle("Normal Distribution of (mean=6, sigma=c(0.5, 1, 2))")
The probability distribution corresponding to the density function for the bell curve with parameters and is called the normal distribution with mean and standard deviation .
A continuous random variable whose probabilities are described by the normal distribution with mean and standard deviation is called a normally distributed random variable, or a normal random variable for short, with mean and standard deviation : .
The density curve for the normal distribution is symmetric about the mean.

EXAMPLE 3. Heights of 25-year-old men in a certain region have mean 69.75 inches and standard deviation 2.59 inches. These heights are approximately normally distributed. Thus the height X of a randomly selected 25-year-old man is a normal random variable with mean μ = 69.75 and standard deviation σ = 2.59. Sketch a qualitatively accurate graph of the density function for X. Find the probability that a randomly selected 25-year-old man is more than 69.75 inches tall.
[ Solution ]
Since the total area under the curve is 1, by symmetry the area to the right of 69.75 is half the total, or 0.5. But this area is precisely the probability , the probability that a randomly selected 25-year-old man is more than 69.75 inches tall.

library(Rstat)
# 1. Compute P(X<=69.75
pnorm(69.75, mean=69.75, sd=2.59)
# 2. Plot
norm.trans(69.75, 2.59, a=0, b=69.75)
We will learn how to compute other probabilities in the next two sections.
4-1. Random Number Generation & Plotting using R
Random Number Generation :
dnorm(x, mena = , sd = )
Plotting :
plot(x, dnorm())
mean = 69.75 , standard deviation = 2.59.
# Normal distribution plot, X~N(69.76, 2.59)
mu <- 69.75
sigma <- 2.59
x <- seq((mu - 6 * sigma), (mu + 6 * sigma), length=200) # x-axis values
dnorm(x, mean=mu, sd=sigma) # random number
main_title <- paste("Normal Distribution, X ~ N(", mu,",",sigma,")", sep="")
ylab_title <- paste("dnorm(x, mean = ", mu, ", sd = ", sigma,")", sep="")
plot(x, dnorm(x, mean=mu, sd=sigma),
type='l',
main=main_title,
ylab=ylab_title)
abline(v=mu, col="yellow")
abline(h=0, col="gray")
概率密度函数 Probability Density Function 均匀分布 Uniform probability distribution 正态分布 Normal probability distribution
Last updated
Was this helpful?