title: Data 607 “Chapter 4 - Distributions of Random Variables”

author: “Sufian”

output:

html_document:

df_print: paged

pdf_document:

extra_dependencies:

- geometry
- multicol
- multirow

Rpubs link:

http://rpubs.com/ssufian/533189

Github link:

https://github.com/ssufian/Data_606

Area under the curve, Part I. (4.1, p. 142) What percent of a standard normal distribution \(N(\mu=0, \sigma=1)\) is found in each region? Be sure to draw a graph.

  1. \(Z < -1.35\)
  2. \(Z > 1.48\)
  3. \(-0.4 < Z < 1.5\)
  4. \(|Z| > 2\)

# use the DATA606::normalPlot function
rm(list = ls())
library(DATA606)
## Loading required package: shiny
## Loading required package: openintro
## Please visit openintro.org for free statistics materials
## 
## Attaching package: 'openintro'
## The following objects are masked from 'package:datasets':
## 
##     cars, trees
## Loading required package: OIdata
## Loading required package: RCurl
## Loading required package: bitops
## Loading required package: maps
## Loading required package: ggplot2
## 
## Attaching package: 'ggplot2'
## The following object is masked from 'package:openintro':
## 
##     diamonds
## Loading required package: markdown
## 
## Welcome to CUNY DATA606 Statistics and Probability for Data Analytics 
## This package is designed to support this course. The text book used 
## is OpenIntro Statistics, 3rd Edition. You can read this by typing 
## vignette('os3') or visit www.OpenIntro.org. 
##  
## The getLabs() function will return a list of the labs available. 
##  
## The demo(package='DATA606') will list the demos that are available.
## 
## Attaching package: 'DATA606'
## The following object is masked from 'package:utils':
## 
##     demo
#Prob 4.1 (a) $Z < -1.35

normalPlot(0, 1, c(-1.35, Inf)) 

#Prob 4.1 (a) Probability of (1-pnorm(-1.35)) to  confirm
1-pnorm(-1.35)
## [1] 0.911492
# Prob 4.1 (b) $Z > 1.48$

normalPlot(0, 1, c(1.48,Inf))

#Prob 4.1 (b) Probability of (1-pnorm(1.48)) to  confirm
1-pnorm(1.48)
## [1] 0.06943662
#Prob 4.1 (c) $-0.4 < Z < 1.5$
  
normalPlot(0, 1, c(-0.4, 1.5)) 

#Prob 4.1 (c) Probability of pnorm(1.5)-pnorm(-0.4) to  confirm
pnorm(1.5)-pnorm(-0.4)
## [1] 0.5886145
#Prob 4.1 (d) $|Z| > 2$

normalPlot(0, 1, c(2, Inf))

#Prob 4.1 (d) Probability of 1-pnorm(2) to  confirm

1-pnorm(2)
## [1] 0.02275013

Triathlon times, Part I (4.4, p. 142) 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:

Remember: a better performance corresponds to a faster finish.

  1. Write down the short-hand for these two normal distributions.

ans:

Men 30-34: N(μ=4313,σ=583)

Women 25-29: N(μ=5261,σ=807)

  1. What are the Z-scores for Leo’s and Mary’s finishing times? What do these Z-scores tell you?

Leo:

Z=(4948−4313)/583=635/583=1.09

Mary:

Z=(5513−5261)/807=252/807=0.31

A Z-score is a numerical measurement of a value’s relationship to the normalized mean. This

relationship is measured in terms of standard deviations from this reference point.

For instance, if you have a z score of 1, then you are 1 positive standard deviation higher

than the mean.

  1. Did Leo or Mary rank better in their respective groups? Explain your reasoning.

Leo was about 1 above mean than his peers while Mary is about 0.3; They both did better than

the average.

The Z-scores tells you whether you’re above or lower the normalized reference point of the

mean = 0.

  1. What percent of the triathletes did Leo finish faster than in his group?

Using the table:

P(Z<1.09)=0.8621 or he did better than 86% of his peers while about 14% of his peers performed better

normalPlot(0, 1, c(-Inf, 1.09))

  1. What percent of the triathletes did Mary finish faster than in her group?

Using the table:

P(Z<0.31)=0.6217 or she did better than 62% of her peers while about 38% of her peers performed better

normalPlot(0, 1, c(-Inf, 0.31))

  1. If the distributions of finishing times are not nearly normal, would your answers to parts (b) - (e) change? Explain your reasoning.

If you are nearly normal, you can still use this parametric analysis, provided you

have a good enough sample size. Because one of the beauty of parametric studies is that the

central limit theorem is your friend. The power of normal distribution is that you only

need a small sample size to perform your hypothesis tests and interval estimaters. But if

you have a huge violation of normality assumption, this means your statistical testings are

less powerful and therefore, drastically need more samples to offset the non-normality

problem But if you are drastically non-normal, then you may never have enough samples to

overcome this defficiency. Perhaps there are more powerful non-parametric tests you can

lean on


Heights of female college students Below are heights of 25 female college students.

\[ \stackrel{1}{54}, \stackrel{2}{55}, \stackrel{3}{56}, \stackrel{4}{56}, \stackrel{5}{57}, \stackrel{6}{58}, \stackrel{7}{58}, \stackrel{8}{59}, \stackrel{9}{60}, \stackrel{10}{60}, \stackrel{11}{60}, \stackrel{12}{61}, \stackrel{13}{61}, \stackrel{14}{62}, \stackrel{15}{62}, \stackrel{16}{63}, \stackrel{17}{63}, \stackrel{18}{63}, \stackrel{19}{64}, \stackrel{20}{65}, \stackrel{21}{65}, \stackrel{22}{67}, \stackrel{23}{67}, \stackrel{24}{69}, \stackrel{25}{73} \]

  1. 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.
# heights of the 25 college students

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)

mean_hts <- mean(heights)

sd_hts <- sd(heights)

# 68% confidence interval
(oneSD <- heights[heights < mean_hts + sd_hts & heights > mean_hts - sd_hts])
##  [1] 57 58 58 59 60 60 60 61 61 62 62 63 63 63 64 65 65
length(oneSD)/length(heights) # 1 std dev
## [1] 0.68
#95% confidence interval
(twoSD <- heights[heights < mean_hts + 2*sd_hts & heights > mean_hts - 2*sd_hts])
##  [1] 54 55 56 56 57 58 58 59 60 60 60 61 61 62 62 63 63 63 64 65 65 67 67
## [24] 69
length(twoSD)/length(heights)
## [1] 0.96
#99% confidence interval
(threeSD <- heights[heights < mean_hts + 3*sd_hts & heights > mean_hts - 3*sd_hts])
##  [1] 54 55 56 56 57 58 58 59 60 60 60 61 61 62 62 63 63 63 64 65 65 67 67
## [24] 69 73
length(threeSD)/length(heights)
## [1] 1
  1. Do these data appear to follow a normal distribution? Explain your reasoning using the graphs provided below.

Yes, they do as the (mostly) segments of populations follow the 68-95-99.7% Rule

hist(heights, probability = TRUE, ylim = c(0, 0.11), col = "yellow")
x <- 50:75
y <- dnorm(x = x, mean = mean_hts, sd = sd_hts)
lines(x = x, y = y, col = "blue")

#Q-Q plot to verify if they are normal?

qqnorm(heights)
qqline(heights)


Ans:

Based on the Q-Q plot, this distrbution do exhibit normaility; most of the data lies in a

45 degree angle of the line

# Use the DATA606::qqnormsim function

Defective rate. (4.14, p. 148) 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. What is the probability that the 10th transistor produced is the first with a defect?
dgeom(9, 0.02)
## [1] 0.01667496
  1. What is the probability that the machine produces no defective transistors in a batch of 100?

Ans:

\(P(no-defects-in-100) = (1-0.02)^{100} = 0.1326\)

  1. On average, how many transistors would you expect to be produced before the first with a defect? What is the standard deviation?

Ans:

\(\mu = 1/p = 1/0.02 = 50\)

\(\sigma = sqrt(p/(1-p)^2=sqrt(0.02/(1-0.02)^2)=0.1443\)

  1. Another machine that also produces transistors has a 5% defective rate where each transistoris produced independent of the others. 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?

Ans:

\(\mu= 1/p = 1/0.05 = 20\)

\(\sigma = sqrt(p/(1-p)^2=sqrt(0.05/(1-0.05)^2)=0.235\)

  1. Based on your answers to parts (c) and (d), how does increasing the probability of an event affect the mean and standard deviation of the wait time until success?

Ans:

mean decreased, shorter wait time but Std Dev increase


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.

  1. Use the binomial model to calculate the probability that two of them will be boys.

Ans:

P(X=2)=\((^3 _2)(0.51)^2x(0.49)^1 = 0.38\)

#Run dbinom to confirm manual calculaton
dbinom(2, 3, 0.51)
## [1] 0.382347
  1. Write out all possible orderings of 3 children, 2 of whom are boys. 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.

Ans:

P(BBG|GBB|BGB) = P(BBG)+P(BGB)+P(GBB) + P(B)XP(B)XP(G)+P(B)XP(G)xP(B)+P(G)xP(B)xP(B)

= (0.51)(0.51)(0.49)+(0.51)(0.49)(0.51)+(0.49)(0.51)(0.51)

= 0.127+0.1274+0.1274 = 0.382, which matches the previous answer

  1. If we wanted to calculate the probability that a couple who plans to have 8 kids will have 3 boys, briefly describe why the approach from part (b) would be more tedious than the approach from part (a).

Ans:

To write out all the individual probabilities would require writing out all the 56 instances

and then sum it all out, as shown below:

\((^8 _3) = 8!/(3!(8-3)! = 8!/3!5! = (8)(7)(6)/(3*2*1)\) = 56 times confirmed


Serving in volleyball. (4.30, p. 162) 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. What is the probability that on the 10th try she will make her 3rd successful serve?

Ans:

The Negative Binomial Distribution: In the negative binomial case, we examine how many

trials it takes to observe a fixed number of successes and require that the last observation

be a success.

\((^{n-1}_{k-1})p^k(1-p)^{n-k}=n!/(k!(n-k)!p^k(1-p)^{n-k}\)

\((^{10-1}_{3-1})(0.15)^3(1-0.15)^{10-3}\)= 0.039

  1. Suppose she has made two successful serves in nine attempts. What is the probability that her 10th serve will be successful?

Ans:

Since this is an independent event, the probaiblity is still 15%

  1. Even though parts (a) and (b) discuss the same scenario, the probabilities you calculated should be different. Can you explain the reason for this discrepancy?

The reason is we are looking at the probabilities of fixed successes given a certain number

of trials. However, in part (b), we are looking at an individual event level and since

these are disjointed events, each sucesses is an event unto itself.