See https://data606.net/assignments/homework/ for more information. Chapter 3 - Distributions of Random Variables Practice: 3.1 (see normalPlot), 3.3, 3.17 (use qqnormsim from lab 3), 3.21, 3.37, 3.41 Graded: 3.2 (see normalPlot), 3.4, 3.18 (use qqnormsim from lab 3), 3.22, 3.38, 3.42
Refer to “Getting Started with R” in https://data606.net/post/
What percent of a standard normal distribution N(?? =0, ?? = 1) is found in each region? Be sure to draw a graph.
Z=(x?????)/??
mu <- 0
sd <- 1
Z <- -1.13
x <- Z * sd + mu
x## [1] -1.13
P <- 1 - pnorm(Z, mean = mu, sd = sd) # Finding probability for Z > -1.13
P## [1] 0.8707619
par(mfrow=c(1,3))
visualize.norm(stat=x, mu=mu, sd=sd, section="upper")
shadeDist(x, lower.tail = FALSE)
normalPlot(mean = mu, sd = sd, bounds=(c(x,Inf)), tails = FALSE)mu <- 0
sd <- 1
Z <- 0.18
x <- Z * sd + mu
x## [1] 0.18
P <- pnorm(Z, mean = 0, sd = 1) # Finding probability for Z < 0.18
P## [1] 0.5714237
par(mfrow=c(1,3))
visualize.norm(stat=x, mu=mu, sd=sd, section="lower")
shadeDist(x, lower.tail = TRUE)
normalPlot(mean = mu, sd = sd, bounds=(c(-Inf,x)), tails = FALSE)mu <- 0
sd <- 1
Z <- 8
x <- Z * sd + mu
x## [1] 8
P <- 1 - pnorm(Z, mean = mu, sd = sd) # Finding probability for Z > 8
P## [1] 6.661338e-16
par(mfrow=c(1,3))
visualize.norm(stat=x, mu=mu, sd=sd, section="upper")
shadeDist(x, lower.tail = FALSE)
normalPlot(mean = mu, sd = sd, bounds=(c(x,Inf)), tails = FALSE)Z < 0.5
-Z < 0.5 => Z > -0.5
-0.5 < Z < 0.5mu <- 0
sd <- 1
Z <- 0.5
x <- Z * sd + mu
x## [1] 0.5
x1 <- pnorm(-Z, mean = mu, sd = sd)
x2 <- pnorm(Z, mean = mu, sd = sd)
P <- x2 - x1 # Finding probability for |Z| < 0.5 = -Z < 0.5 < Z
P## [1] 0.3829249
par(mfrow=c(1,3))
visualize.norm(stat=c(-Z,Z), mu=mu, sd=sd, section="bounded")
shadeDist(c(-Z,Z), lower.tail = FALSE)
normalPlot(mean = mu, sd = sd, bounds=(c(-Z,Z)), tails = FALSE)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 Men group: Ages=30-34; Mean=4313s; SD=583s; RaceTime=4948s
Mary Women group: Ages=25-29; Mean=5261s; SD=807s; RaceTime=5513sN(??=4313, s=583) -> Men, Ages 30 - 34 N(??=5261, s=807) -> Women, Ages 25 - 29
The Z score of an observation is the number of standard deviations it falls above or below the mean.
LMgX <- 4948
LMgU <- 4313
LMgS <- 583
LMgZ <- (LMgX-LMgU)/LMgS
paste0('Leo Men group Z score is ',LMgZ,', the number of standard deviation is above the mean.')## [1] "Leo Men group Z score is 1.08919382504288, the number of standard deviation is above the mean."
MWgX <- 5513
MWgU <- 5261
MWgZ <- (5513-5261)/807
paste0('Mary Women group Z score is ',MWgZ,', the number of standard deviation is above the mean.')## [1] "Mary Women group Z score is 0.312267657992565, the number of standard deviation is above the mean."
paste('Mary had a lower Z score of', MWgZ,'than Leo Z score of', LMgZ,' which would mean that Mary got faster time than Leo within their respective groups.')## [1] "Mary had a lower Z score of 0.312267657992565 than Leo Z score of 1.08919382504288 which would mean that Mary got faster time than Leo within their respective groups."
paste0('Percent of the triathletes who finished slower than Leo in his Men group ', (1-pnorm(LMgZ))*100, '%')## [1] "Percent of the triathletes who finished slower than Leo in his Men group 13.803421070203%"
paste0('Percent of the triathletes who finished slower than Mary in her Women group ', (1-pnorm(MWgZ))*100, '%')## [1] "Percent of the triathletes who finished slower than Mary in her Women group 37.74185585735%"
Explain your reasoning.
The part b and c would not change, because the ranking will not change and hence Zscore will still reflect above or below mean. But the part d and e will change due to changes in density and percentiles, “Pnorm” only used for normal distribution.
Below are heights of 25 female college students. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25 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
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)
summary(heights)## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 54.00 58.00 61.00 61.52 64.00 73.00
glimpse(heights)## num [1:25] 54 55 56 56 57 58 58 59 60 60 ...
Use this information to determine if the heights approximately follow the 68-95-99.7% Rule.
mean <- 61.52
sd <- 4.58
#prove 68% rule
lb1 <- mean - sd
ub1 <- mean + sd
cat(paste0('68% rule calculation as :'),
paste0('1. (pnorm(ub1, mean, sd) - pnorm(lb1, mean, sd)) = ',(pnorm(ub1, mean, sd) - pnorm(lb1, mean, sd))),
paste0('2. (1-2*pnorm(ub1, mean, sd, lower=FALSE))= ', (1-2*pnorm(ub1, mean, sd, lower=FALSE))),
paste0('4. (quantile(heights,0.68)) = ', quantile(heights,0.68)),sep='\n')## 68% rule calculation as :
## 1. (pnorm(ub1, mean, sd) - pnorm(lb1, mean, sd)) = 0.682689492137086
## 2. (1-2*pnorm(ub1, mean, sd, lower=FALSE))= 0.682689492137087
## 4. (quantile(heights,0.68)) = 63
#prove 95% rule
lb2 <- mean - (sd*2)
ub2 <- mean + (sd*2)
cat(paste0('95% rule calculation as :'),
paste0('1. pnorm(ub2, mean, sd) - pnorm(lb2, mean, sd) = ',(pnorm(ub2, mean, sd) - pnorm(lb2, mean, sd))),
paste0('2. (1-2*pnorm(ub2, mean, sd, lower=FALSE))= ', (1-2*pnorm(ub2, mean, sd, lower=FALSE))),
paste0('3. (quantile(heights,0.95)) = ', quantile(heights,0.95)),sep='\n')## 95% rule calculation as :
## 1. pnorm(ub2, mean, sd) - pnorm(lb2, mean, sd) = 0.954499736103642
## 2. (1-2*pnorm(ub2, mean, sd, lower=FALSE))= 0.954499736103642
## 3. (quantile(heights,0.95)) = 68.6
#prove 99.7% rule
lb3 <- mean - (sd*3)
ub3 <- mean + (sd*3)
cat(paste0('99.7% rule calculation as :'),
paste0('1. pnorm(ub3, mean, sd) - pnorm(lb3, mean, sd) = ',(pnorm(ub3, mean, sd) - pnorm(lb3, mean, sd))),
paste0('2. (1-2*pnorm(ub3, mean, sd, lower=FALSE))= ', (1-2*pnorm(ub3, mean, sd, lower=FALSE))),
paste0('3. (quantile(heights,0.997)) = ', quantile(heights,0.997)),sep='\n')## 99.7% rule calculation as :
## 1. pnorm(ub3, mean, sd) - pnorm(lb3, mean, sd) = 0.99730020393674
## 2. (1-2*pnorm(ub3, mean, sd, lower=FALSE))= 0.99730020393674
## 3. (quantile(heights,0.997)) = 72.712
Hence, these heights approximately follow the 68-95-99.7% Rule since:
(1) 63% of the data are within 1 standard deviation of the mean.
(2) 68.6% of the data are within 2 standard deviation of the mean.
(3) 72.7% of the data are within 3 standard deviation of the mean.
Explain your reasoning using the graphs provided below.
qqnormsim(heights)par(mfrow=c(2,2))
qqnorm(heights)
qqline(heights, col = 2)
histPlot(heights, main="Histogram")
hist(heights, probability = TRUE, xlab = "Heights", ylim = c(0, 0.1))
x <- 50:75
y <- dnorm(x = x, mean = mean, sd = sd)
lines(x = x, y = y, col = "blue")
abline(v = mean, col = "red")
hist(heights, freq=F, col ="red", ylim=c(0,0.1))
curve(dnorm(x, 61.52, 4.58),min(heights), max(heights), add=T, col="blue")The distriubtion is unimodal, symmetric and similar to normal. The theoretical quantiles are also keeping the trend of lines. The normal curve depicts the bell shaped curve of the distribution in histogram. The data on the normal probability fall on the line, apart from one outlier at the end of the line resulting in slight right skewness
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.
# 1 2 3 4 5 6 7 8 9 Defect ...... Probaility of 1 defect in 10
# In this case, 9 is the number of success until we find a defective part
defectRate <- 0.02
successRate <- (1-defectRate)paste('probability that the 10th transistor produced is the first with a defect =',((successRate^9)*(defectRate^1)))## [1] "probability that the 10th transistor produced is the first with a defect = 0.016674955242603"
paste('Calculating probability of 10th transistor produced is the first with a defect =',dgeom(9, defectRate))## [1] "Calculating probability of 10th transistor produced is the first with a defect = 0.016674955242603"
paste('probability that the machine produces no defective transistors in a batch of 100 =',((successRate^100)*(defectRate^0)))## [1] "probability that the machine produces no defective transistors in a batch of 100 = 0.132619555894753"
paste('Calculating probability of 0 defect in nbatch of 100 transistors produced =',dbinom(0, 100, defectRate))## [1] "Calculating probability of 0 defect in nbatch of 100 transistors produced = 0.132619555894753"
#pgeom(100, defectRate, lower.tail = FALSE)paste('probability how many transistors would you expect to be produced before the first with a defect =',(1/defectRate))## [1] "probability how many transistors would you expect to be produced before the first with a defect = 50"
paste('standard deviation =',sqrt(successRate/defectRate^2))## [1] "standard deviation = 49.4974746830583"
On average how many transistors would you expect to be produced with this machine before the first with a defect? What is the standard deviation?
newDefectRate <- 0.05
newSuccessRate <- (1-newDefectRate)
paste('probability how many transistors would you expect to be produced before the first with a defect =',(1/newDefectRate))## [1] "probability how many transistors would you expect to be produced before the first with a defect = 20"
paste('standard deviation =',sqrt(newSuccessRate/newDefectRate^2))## [1] "standard deviation = 19.4935886896179"
When the probability of defective rate increases, the expected number iterations of product having first defect decreases i.e, it gets to a defect faster. And the normal distribution would become narrow due to decrease in standard deviation and in mean.
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.
boyRate <- 0.51
girlRate <- 1-boyRatepaste('probability of having 2 boys out of 3 =', (girlRate^(3-2)) * (boyRate^2) * (choose(3,2)))## [1] "probability of having 2 boys out of 3 = 0.382347"
possible3KidPermutation <- factorial(3) # Permutations (ggg, bgg, bbg, bbb) / Combinations (ggg, bgg, gbg, ggb, bgb, bbg, gbb, bbb)
possible2BoyPermutation <- factorial(2) # bbg, bgb, gbb
paste('Calculating probability of having 2 boys out of 3 =',(girlRate^(3-2)) * (boyRate^2) * (possible3KidPermutation/possible2BoyPermutation))## [1] "Calculating probability of having 2 boys out of 3 = 0.382347"
Use these scenarios to calculate the same probability from part (a) but using the addition rule for disjoint outcomes. Confirm that your answers from parts (a) and (b) match.
paste('Possible combinations of having 2 boys out of 3 =', sum((boyRate*boyRate*girlRate),(boyRate*girlRate*boyRate),(girlRate*boyRate*boyRate)))## [1] "Possible combinations of having 2 boys out of 3 = 0.382347"
briefly describe why the approach from part (b) would be more tedious than the approach from part (a).
To calculate the probability of 8 kids having 3 boys, there would be 56 combinations to be calculated, hence calculations of part(b) would be more tedious for all possible scenarios of atleast 3 boys out of 8 kids than atleast 2 boys out of 3 kids.
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.
serveRate <- 0.15
failRate <- 1-0.15paste('probability of having 3rd successful serve on the 10th try =', (failRate^7) * (serveRate^3) * (choose(9,2))) # Negative Binomial distribution## [1] "probability of having 3rd successful serve on the 10th try = 0.0389501162261719"
possible9Permutation <- factorial(9) / (factorial(2)*factorial(7)) #number of cases with 2 successes and 7 failures in 9 first attemps
paste('Calculating probability of having 3rd successful serve on the 10th try =',(failRate^7) * (serveRate^3) * (possible9Permutation))## [1] "Calculating probability of having 3rd successful serve on the 10th try = 0.0389501162261719"
The probability that her 10th serve will be successful is 15% since all her serves are independent of each other.
For part a, it is calculated by negative binonmial distribution to count 3rd successful serve in 10th attempt (Only 2 of the former 9 attempts are success).
For part b, it is only calculated the probability that 10th attempt will be successful assuming that previous 9 attempts already had 2 successful serve.