library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.2.5
library('DATA606') # Load the package
##
## 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
library(knitr)
#vignette(package='DATA606') # Lists vignettes in the DATA606 package
#vignette('os3') # Loads a PDF of the OpenIntro Statistics book
#data(package='DATA606') # Lists data available in the package
#getLabs() # Returns a list of the available labs
#viewLab('Lab0') # Opens Lab0 in the default web browser
#startLab('Lab0') # Starts Lab0 (copies to getwd()), opens the Rmd file
#shiny_demo() # Lists available Shiny apps
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.
1 - pnorm(-1.13, mean = 0, sd = 1)
## [1] 0.8707619
library(ggplot2)
normalPlot(mean = 0, sd = 1, bounds = c(-1.13, 4))
pnorm(.18, mean = 0, sd = 1)
## [1] 0.5714237
normalPlot(mean = 0, sd = 1, bounds = c(-4, .18), tails = FALSE)
1 - pnorm(8, mean = 0, sd = 1)
## [1] 6.661338e-16
normalPlot(mean = 0, sd = 1, bounds = c(8, Inf), tails = FALSE)
1 - pnorm(.5, mean = 0, sd = 1)
## [1] 0.3085375
pnorm(.5, mean = 0, sd = 1)
## [1] 0.6914625
normalPlot(mean = 0, sd = 1, bounds = c((1 - pnorm(.5, mean = 0, sd = 1)), (pnorm(.5, mean = 0, sd = 1))), tails = FALSE)
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.
Men N(μ = 4313, σ = 583) Women N(μ = 5261, σ = 807)
ZLeo <- (4948 - 4313) / 583
ZLeo
## [1] 1.089194
ZMary <- (5513 - 5261) / 807
ZMary
## [1] 0.3122677
Z score tells us that Leo was 1.089 standard deviations away from the mean and Mary was .312 standard deviations away from the mean.
Mary was better than Leo as she was closer to mean than Leo in that group.
pnorm(ZLeo)
## [1] 0.8619658
pnorm(ZMary)
## [1] 0.6225814
The percentiles would change, but the Z scores will remain same.
3.18 Heights of female college students. Below are heights of 25 female college students.
fhgt <- c(54,55,56,56,57,58,58,59,60,60,61,61,62,62,63,63,63,64,65,65,67,67,69,73)
fhgtmean <- mean(fhgt)
fhgtsd <- sd(fhgt)
hist(fhgt)
qqnormsim(fhgt)
pnorm(fhgtmean+fhgtsd, mean = fhgtmean, sd = fhgtsd)
## [1] 0.8413447
pnorm(fhgtmean+2*fhgtsd, mean = fhgtmean, sd = fhgtsd)
## [1] 0.9772499
pnorm(fhgtmean+3*fhgtsd, mean = fhgtmean, sd = fhgtsd)
## [1] 0.9986501
Yes, it follow 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.
qqnorm(fhgt)
qqline(fhgt)
The distibution is normal with few outliers and most data points are close to the line.
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.
pgeom(10-1,0.02)
## [1] 0.1829272
1-pgeom(100,0.02)
## [1] 0.1299672
first_defect <- 1/0.02
first_defect
## [1] 50
sd <- sqrt((1 - 0.02)/0.02^2)
sd
## [1] 49.49747
first_defect <- 1/0.05
first_defect
## [1] 20
sd <- sqrt((1 - 0.05)/0.05^2)
sd
## [1] 19.49359
Higher probability decreases the wait time of the event.
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.
dbinom(2, 3, 0.51)
## [1] 0.382347
Possible ordering: GBB, BGB, BBG
#addition rule for disjoint
pb <- ((.49*.51*.51)+(.51*.49*.51)+(.51*.51*.49))
pb
## [1] 0.382347
Because for part (b) there will be 8 different equations with 8 different probabilities.
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.
p <- .15
n <- 10
s <- 3
choose(n - 1, s - 1) * (1 - p)^(n - s) * p^s
## [1] 0.03895012
Probability is 0.15 since each serve is independant.
Part (b) was only concerned with only one event where as part(a) was combination of events.