Normal Distribution

Density Function

# Generate random samples for standard normal distribution
help(rnorm)
snd <- rnorm(n = 50)
hist(snd, freq = FALSE, main = "Histogram of Standard Normal Distribution")

plot(density(snd))

summary(snd)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -2.0604 -0.8391 -0.1201 -0.1064  0.7271  1.8870
# Generate random samples for normal distribution
nd <- rnorm(n = 50, mean = 20, sd = 5)
hist(nd, freq = FALSE, main = "Histogram of Normal Distribution")

plot(density(nd))

summary(nd)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    7.17   15.20   17.44   18.03   20.52   30.59

Cumulative Distribution Function

curve(dnorm(x), xlim = c(-3, 3),
      main = "The Standard Normal Distribution", ylab = "Density")

curve(pnorm(x), xlim = c(-3, 3),
      main = "The Standard Normal CDF", ylab = "Probability")

Question: Suppose widgit weights produced at Acme Widgit Works have weights that are normally distributed with mean 17.46 grams and variance 375.67 grams. What is the probability that a randomly chosen widgit weighs more then 19 grams?
Question Rephrased: What is P(X > 19) when X has the N(17.46, 375.67) distribution?
prob <- 1 - pnorm(19, mean = 17.46, sd = sqrt(375.67))
prob
## [1] 0.4683356
Question: Suppose IQ scores are normally distributed with mean 100 and standard deviation 15. What is the 95th percentile of the distribution of IQ scores?
pct <- qnorm(.95, mean = 100, sd = 15)
pct
## [1] 124.6728

Exponential Distribution

help(rexp)
expd <- rexp(n = 200, rate = .5)
hist(expd, main = "Histogram of Exponential Distribution")

Cumulative Distribution Function

curve(dexp(x, rate = .5), xlim = c(0, 50),
      main = "PDF of Exponential Distribution", ylab = "Density")

curve(pexp(x, rate = .5), xlim = c(0, 50),
      main = "CDF of Exponential Distribution", ylab = "Probability")