##Load DATA606 packages
#if(!require('DATA606')) {
# install.packages('DATA606')
# library(DATA606)
#}
normalPlot <- function(mean=0, sd=1, bounds=c(-1,1), tails=FALSE) {
x <- seq(-4,4,length=100)*sd + mean
hx <- dnorm(x,mean,sd)
plot(x, hx, type="n", xlab="x-Axis", ylab="",
main="Normal Distribution", axes=FALSE)
lines(x, hx)
if(tails) {
i.low <- x <= bounds[1]
i.high <- x >= bounds[2]
polygon(c(x[i.low],bounds[1]), c(hx[i.low], 0), col="red")
polygon(c(bounds[2],x[i.high]), c(0,hx[i.high]), col="red")
} else {
i <- x >= bounds[1] & x <= bounds[2]
polygon(c(bounds[1],x[i],bounds[2]), c(0,hx[i],0), col="red")
area <- pnorm(bounds[2], mean, sd) - pnorm(bounds[1], mean, sd)
if(diff(bounds) > 0) {
result <- paste("P(",bounds[1],"< x <",bounds[2],") =",
signif(area, digits=3))
mtext(result,3)
}
}
axis(1)
}
qqnormsim <- function(dat){
par(mfrow = c(3,3))
qqnorm(dat, main = "Normal QQ Plot (Data)")
qqline(dat)
for(i in 1:8){
simnorm <- rnorm(n = length(dat), mean = mean(dat), sd = sd(dat))
qqnorm(simnorm,main = "Normal QQ Plot (Sim)")
qqline(simnorm)
}
par(mfrow = c(1,1))
}
3.2 Area under the curve, Part II. What percent of a standard normal distribution N(μ = 0,! = 1) is found in each region? Be sure to draw a graph.
normalPlot(mean = 0, sd = 1, bounds = c(-1.13, 4))
normalPlot(mean = 0, sd = 1, bounds = c(-4, 0.18))
normalPlot(mean = 0, sd = 1, bounds = c(8,12))
normalPlot(mean = 0, sd = 1, bounds = c(-0.5,0.5))
3.4 Triathlon times, Part I. In triathlons, it is common for racers to be placed into age and gender groups. Friends Leo and Mary both completed the Hermosa Beach Triathlon, where Leo competed in the Men, Ages 30 - 34 group while Mary competed in the Women, Ages 25 - 29 group. Leo completed the race in 1:22:28 (4948 seconds), while Mary completed the race in 1:31:53 (5513 seconds). Obviously Leo finished faster, but they are curious about how they did within their respective groups. Can you help them? Here is some information on the performance of their groups: • The finishing times of the Men, Ages 30 - 34 group has a mean of 4313 seconds with a standard deviation of 583 seconds. • The finishing times of the Women, Ages 25 - 29 group has a mean of 5261 seconds with a standard deviation of 807 seconds. • The distributions of finishing times for both groups are approximately Normal. Remember: a better performance corresponds to a faster finish.
#Leo
leo_obs <- 4948
leo_mu <- 4313
leo_sd <- 583
leo_Z = (leo_obs - leo_mu )/leo_sd
leo_Z
## [1] 1.089194
#Mary
mary_obs <- 5261
mary_mu <- 4313
mary_sd <- 807
mary_Z <- (mary_obs - mary_mu)/mary_sd
mary_Z
## [1] 1.174721
leo_rank <- 1-pnorm(leo_Z)
leo_rank
## [1] 0.1380342
mary_rank <- 1-pnorm(mary_Z)
mary_rank
## [1] 0.1200531
pnorm(leo_obs, leo_mu, leo_sd)
## [1] 0.8619658
pnorm(mary_obs, mary_mu, mary_sd)
## [1] 0.8799469
3.18 Heights of female college students. Below are heights of 25 female college students.
1 54, 2 55, 3 56, 4 56, 5 57, 6 58, 7 58, 8 59, 9 60, 10 60, 11 60, 12 61, 13 61, 14 62, 15 62, 16 63, 17 63, 18 63, 19 64, 20 65, 21 65, 22 67, 23 67, 24 69, 25 73
(a) The mean height is 61.52 inches with a standard deviation of 4.58 inches. Use this information to determine if the heights approximately follow the 68-95-99.7% Rule.
hgt <- c(54,55,56,56,57,58,58,59,60,60,60,61,61,62,62,63,63,63,64,65,65,67,67,69,73)
mean_hgt = mean(hgt)
sd_hgt = sd(hgt)
z_hgt <- (hgt - mean_hgt) / sd_hgt
hist(z_hgt, col="#c2c2c2", freq=F, xlim=c(-5, 5))
# 99.7% Rule
curve(dnorm, -3, 3, add=T, col="red")
# 95% Rule
curve(dnorm,-2,2,add=T, col="blue")
# 68% Rule
curve(dnorm,-1,1,add=T, col="green")
qqnormsim(hgt)
3.22 Defective rate. A machine that produces a special type of transistor (a component of computers) has a 2% defective rate. The production is considered a random process where each transistor is independent of the others.
n <- 10
p <- 0.02
q <- 0.98
round(((q ^ (n-1)) * p)*100, 2)
## [1] 1.67
n <- 100
p <- 0.02
q <- 0.98
round((q ^ n)*100, 2)
## [1] 13.26
p <- 0.02
q <- 0.98
(1/p)
## [1] 50
sqrt(q/(p^2))
## [1] 49.49747
p <- 0.05
q <- 0.95
(1/p)
## [1] 20
sqrt(q/(p^2))
## [1] 19.49359
3.38 Male children. While it is often assumed that the probabilities of having a boy or a girl are the same, the actual probability of having a boy is slightly higher at 0.51. Suppose a couple plans to have 3 kids.
p = 2
k = 3
q = 0.51
dbinom(p,k,q)
## [1] 0.382347
boy = 0.51
girl = 0.49
(boy * boy * girl) + (boy * girl * boy) + (girl * boy * boy)
## [1] 0.382347
3.42 Serving in volleyball. A not-so-skilled volleyball player has a 15% chance of making the serve, which involves hitting the ball so it passes over the net on a trajectory such that it will land in the opposing team’s court. Suppose that her serves are independent of each other.
#Negative Binomial distribution
p <- 0.15
n <- 10
k <- 3
choose(n - 1, k - 1) * (1 - p)^(n - k) * p^k
## [1] 0.03895012