I could not download ‘DATA606’ package as it is not compatible with the last version of R. I have manually taken function normalPlot() from the package. source: https://github.com/jbryer/DATA606/blob/master/R/normalPlot.R
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)
}
# normalPlot(mean = 0, sd = 1, bounds = c(-1.13, 4))
3.2 Area under the curve, Part II. What percent of a standard normal distribution N(mu = 0, sd = 1) is found in each region? Be sure to draw a graph. (a) Z >-1.13
pnorm(1.13, mean= 0, sd= 1 )
## [1] 0.8707619
normalPlot(bounds = c(-1.13, Inf))
pnorm(0.18, mean= 0, sd= 1)
## [1] 0.5714237
normalPlot(bounds = c(-Inf, 0.18))
pnorm(8, mean= 0, sd= 1)
## [1] 1
normalPlot(bounds = c(8,Inf))
pnorm(0.5, mean=0, sd= 1)
## [1] 0.6914625
normalPlot(bounds = c(-0.5, 0.5))
Z_Leo<-(4948-4313)/583
Z_Leo
## [1] 1.089194
Z_Mary<-(5513 -5261)/807
Z_Mary
## [1] 0.3122677
Answer: Z score tells me how many standard deviation Leo or Mary from the groups’ mean. The more st deviation (+) the worse as it is rasing results (the faster the better)
Answer: Mary has better performance than Leo as his Z score higher and it’s negative for racing results.
1 - pnorm(4948, mean = 4313, sd = 583)
## [1] 0.1380342
Answer: Leo finished faster than 13.8% triathletes in his group.
1-pnorm(5513, mean = 5261, sd = 807)
## [1] 0.3774186
Answer: Mary finished faster than 37.7% triathletes in his group.
Z scores will remain same as it is replacing the measurement unit with “number of standard deviations” away from the mean. Whereas probability will not be the same as it should be calculated on a normaly distributed data with 68%/95%/99.7& rule.
Heights of female college students. Below are heights of 25 female college students.
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
height <- 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)
hmean <- 61.52
hsd <- 4.58
pnorm(hmean+hsd, mean = hmean, sd = hsd)
## [1] 0.8413447
pnorm(hmean+2*hsd, mean = hmean, sd = hsd)
## [1] 0.9772499
pnorm(hmean+3*hsd, mean = hmean, sd = hsd)
## [1] 0.9986501
Hight is approximatly follows the 68-95-97% rule.
84.13% of the data are within 1 standard deviation of the mean.
97.72% of the data are within 2 standard deviation of the mean.
99.86% of the data are within 3 standard deviation of the mean.
heights <- 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)
qqnorm(height)
qqline(height)
Data appears to follow a normal distribution as the points on the normal probability plot seem to follow a straight line. Also graph has typical for a normally distributed data bell curve.
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. (a) What is the probability that the 10th transistor produced is the first with a defect?
pgeom(10-1,0.02)
## [1] 0.1829272
1-pgeom(100,0.02)
## [1] 0.1299672
first_prob <- 1/0.02
first_prob
## [1] 50
sd <- sqrt((1 - 0.02)/0.02^2)
sd
## [1] 49.49747
first__prob2 <- 1/0.05
first__prob2
## [1] 20
sd2 <- sqrt((1 - 0.05)/0.05^2)
sd2
## [1] 19.49359
Mean(expected value) decreases as the probabilities of each event increases (less transistors are produced before the first with a defect).
Standard deviation also decreases as the likelihood of a defecdtive transistor is less spread out.
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.
dbinom(2, 3, 0.51)
## [1] 0.382347
Answer: possible ordering of 3 children - gbb, bgb, bbg
prob <- ((0.49*0.51*0.51)+(0.51*0.49*0.51)+(0.51*0.51*0.49))
prob
## [1] 0.382347
dbinom(3,8,0.51)
## [1] 0.2098355
In this case number of combinations will be significantly higher and process will be very tedious and time consuming.
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.
# 1. probability of 2 successes in 9 trials
P = dbinom(2,9,0.15)
# 2. probability that she will be successful on her 10th try (3 success in total)
P * 0.15
## [1] 0.03895012
Probability is 0.15 (each serve is independant)
Part (a): joint probability of all of the first 10 trials Part (b): probability of the 10th trial only