######################################################################
# Car mpg and normal distribution #
# #
######################################################################
#####################################################################
# Example #1
curve(expr = dnorm(x = x, mean = 24.3, sd = 0.6),
from = 20, to = 30, col = "darkgreen", lwd = 2, ylab = "f(y)",
xlab = "y", n = 1000)
abline(h = 0)
segments(x0 = 23, y0 = 0, x1 = 23, y1 = dnorm(x = 23, mean = 24.3, sd = 0.6),
col = "red", lwd = 5)
pnorm(q = 23, mean = 24.3, sd = 0.6)
#####################################################################
# Example #2
curve(expr = dnorm(x = x, mean = 24.3, sd = 1.3),
from = 20, to = 30, col = "darkgreen", lwd = 2, ylab = "f(y)",
xlab = "y", n = 1000)
abline(h = 0)
segments(x0 = 23, y0 = 0, x1 = 23, y1 = dnorm(x = 23, mean = 24.3, sd = 1.3),
col = "red", lwd = 5)
pnorm(q = 23, mean = 24.3, sd = 1.3)
#####################################################################
# Example #3
curve(expr = dnorm(x = x, mean = 23.1, sd = 0.6),
from = 20, to = 30, col = "darkgreen", lwd = 2, ylab = "f(y)",
xlab = "y", n = 1000)
abline(h = 0)
segments(x0 = 23, y0 = 0, x1 = 23, y1 = dnorm(x = 23, mean = 23.1, sd = 0.6),
col = "red", lwd = 5)
pnorm(q = 23, mean = 23.1, sd = 0.6)
#####################################################################
# Compare all 3
curve(expr = dnorm(x = x, mean = 24.3, sd = 0.6),
from = 20, to = 30, col = "darkgreen", lwd = 2, ylab = "f(y)", xlab = "y")
curve(expr = dnorm(x = x, mean = 24.3, sd = 1.3),
from = 20, to = 30, col = "blue", add = TRUE, lwd = 2)
curve(expr = dnorm(x = x, mean = 23.1, sd = 0.6),
from = 20, to = 30, col = "red", add = TRUE, lwd = 2)
abline(h = 0)
abline(v = 23, col = "black", lwd = 5, lty = "dotted")
legend(x = 25, y = 0.6, legend = c("mu = 24.3, sigma = 0.6", "mu = 24.3, sigma = 1.3", "mu = 23.1, sigma = 0.6"),
lty = c(1,1,1), col = c("darkgreen", "blue","red"), bty = "n", lwd = c(2,2,2))
#####################################################################
# Example #4
curve(expr = dnorm(x = x, mean = 24.3, sd = 0.6),
from = 20, to = 30, col = "darkgreen", lwd = 2, ylab = "f(y)",
xlab = "y", n = 1000)
abline(h = 0)
segments(x0 = 23, y0 = 0, x1 = 23, y1 = dnorm(x = 23, mean = 24.3, sd = 0.6),
col = "red", lwd = 5)
segments(x0 = 25, y0 = 0, x1 = 25, y1 = dnorm(x = 25, mean = 24.3, sd = 0.6),
col = "red", lwd = 5)
pnorm(q = 25, mean = 24.3, sd = 0.6) - pnorm(q = 23, mean = 24.3, sd = 0.6)
#####################################################################
# Example #5
1 - pnorm(q = 23, mean = 24.3, sd = 0.6)
#####################################################################
# Example #6
1 - (pnorm(q = 25, mean = 24.3, sd = 0.6) - pnorm(q = 23, mean = 24.3, sd = 0.6))
pnorm(q = 23, mean = 24.3, sd = 0.6) + (1 - pnorm(q = 25, mean = 24.3, sd = 0.6))
#####################################################################
# Example #7
quant<-qnorm(p = 0.95, mean = 24.3, sd = 0.6)
curve(expr = dnorm(x = x, mean = 24.3, sd = 0.6),
from = 20, to = 30, col = "darkgreen", lwd = 2, ylab = "f(y)",
xlab = "y", n = 1000)
abline(h = 0)
segments(x0 = quant, y0 = 0, x1 = quant, y1 = dnorm(x = quant, mean = 24.3, sd = 0.6),
col = "red", lwd = 5)
#####################################################################
# Last example
curve(expr = dnorm(x = x, mean = 24.3, sd = 0.6),
from = 20, to = 30, col = "darkgreen", lwd = 2, ylab = "f(y)",
xlab = "y", n = 1000)
abline(h = 0)
#Alternative distribution
segments(x0 = 19, y0 = 0, x1 = 22.3, y = 0 , col = "pink", lwd = 2)
segments(x0 = 22.3, y0 = 0, x1 = 22.3, y = 0.25, col = "pink", lwd = 2)
segments(x0 = 22.3, y0 = 0.25, x1 = 26.3, y = 0.25, col = "pink", lwd = 2)
segments(x0 = 26.3, y0 = 0, x1 = 26.3, y = 0.25, col = "pink", lwd = 2)
segments(x0 = 26.3, y0 = 0, x1 = 31, y = 0 , col = "pink", lwd = 2)
abline(v = 23, col = "black", lwd = 5, lty = "dotted")
legend(x = 25, y = 0.6, legend = c("Normal", "Alternative"),
lty = c(1,1), col = c("darkgreen", "pink"), bty = "n", lwd = c(2,2))
#
#