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
8.2 Baby weights, Part II. Exercise 8.1 introduces a data set on birth weight of babies. Another variable we consider is parity, which is 0 if the child is the first born, and 1 otherwise. The summary table below shows the results of a linear regression model for predicting the average birth weight of babies, measured in ounces, from parity.
Estimate Std. Error t value Pr(>|t|) (Intercept) 120.07 0.60 199.94 0.0000 parity -1.93 1.19 -1.62 0.1052
Answer:
y = 120.07−1.93×parity
Answer:
First born:
y0 = 120.07 - 1.93 * 0
y0
## [1] 120.07
Other:
y1 = 120.07 - 1.93 * 1
y1
## [1] 118.14
First born: 120.07 ounces Others: 118.14 ounces
Answer: p−value is about 0.1052 and greater than 0.05. , so we can say there is no statistical significance.
8.4 Absenteeism. Researchers interested in the relationship between absenteeism from school and certain demographic characteristics of children collected data from 146 randomly sampled students in rural New SouthWales, Australia, in a particular school year. Below are three observations from this data set. eth sex lrn days 1 0 1 1 2 2 0 1 1 11 … … … … … 146 1 0 0 37 The summary table below shows the results of a linear regression model for predicting the average number of days absent based on ethnic background (eth: 0 - aboriginal, 1 - not aboriginal), sex (sex: 0 - female, 1 - male), and learner status (lrn: 0 - average learner, 1 - slow learner).
Estimate Std. Error t value Pr(>|t|) (Intercept) 18.93 2.57 7.37 0.0000 eth -9.11 2.60 -3.51 0.0000 sex 3.10 2.64 1.18 0.2411 lrn 2.15 2.65 0.81 0.4177
Answer:
y = 18.93 - 9.11(eth) + 3.1(sex) + 2.15(lrn)
Answer:
eth: The model predicts that the average number of days absent by non-aboriginal students is 9.11 days lower than by aboriginal students.
sex: The model predicts that the average number of days absent by male students is 3.1 days higher than by female students.
lrn: The model predicts that the average number of days absent by slow learners is 2.15 days higher than by average learners.
Answer:
p <- 18.93 - (9.11 * 0) + (3.1 * 1) + (2.15 * 1)
p
## [1] 24.18
r <- 2 - p
r
## [1] -22.18
Residual will be -22.18
Answer:
n <- 146
k <- 3
vr <- 240.57
vall <- 264.17
R2 <- 1 - (vr/vall)
R2
## [1] 0.08933641
R2_adj <- 1 - (vr/vall) * ((n-1) / (n-k-1))
R2_adj
## [1] 0.07009704
8.8 Absenteeism, Part II. Exercise 8.4 considers a model that predicts the number of days absent using three predictors: ethnic background (eth), gender (sex), and learner status (lrn). The table below shows the adjusted R-squared for the model as well as adjusted R-squared values for all models we evaluate in the first step of the backwards elimination process.
Model Adjusted R2 1 Fullmodel 0.0701 2 Noethnicity -0.0033 3 Nosex 0.0676 4 No learner status 0.0723
Which, if any, variable should be removed from the model first?
Answer:
learner status should be eliminated from the model first.
8.16 Challenger disaster, Part I. On January 28, 1986, a routine launch was anticipated for the Challenger space shuttle. Seventy-three seconds into the flight, disaster happened: the shuttle broke apart, killing all seven crew members on board. An investigation into the cause of the disaster focused on a critical seal called an O-ring, and it is believed that damage to these O-rings during a shuttle launch may be related to the ambient temperature during the launch. The table below summarizes observational data on O-rings for 23 shuttle missions, where the mission order is based on the temperature at the time of the launch. Temp gives the temperature in Fahrenheit, Damaged represents the number of damaged O-rings, and Undamaged represents the number of O-rings that were not damaged.
Shuttle Mission 1 2 3 4 5 6 7 8 9 10 11 12
Temperature 53 57 58 63 66 67 67 67 68 69 70 70
Damaged 5 1 1 1 0 0 0 0 0 0 1 0
Undamaged 1 5 5 5 6 6 6 6 6 6 5 6
Shuttle Mission 13 14 15 16 17 18 19 20 21 22 23
Temperature 70 70 72 73 75 75 76 76 78 79 81
Damaged 1 0 0 0 0 1 0 0 0 0 0
Undamaged 5 6 6 6 6 5 6 6 6 6 6
Answer:
There may be some significant relationship between Temperature and Damaged. Lower temperatures lead to more damages.
Estimate Std. Error z value Pr(>|z|) (Intercept) 11.6630 3.2963 3.54 0.0004 Temperature -0.2162 0.0532 -4.07 0.0000
Answer:
There is a negative relationship between temperature and O-ring failures. Increase in temperature decreases the probability of an O-ring failure. Additionally, the p−value is close to 0, so the relationship between temperature and O-ring failure has significance.
Answer:
log(p/(1-p)) = 11.663 - 0.2162 x Temperature
Answer:
Concerns regarding O-rings are justified as there are more damaged O-rings at lower temperatures
8.18 Challenger disaster, Part II. Exercise 8.16 introduced us to O-rings that were identified as a plausible explanation for the breakup of the Challenger space shuttle 73 seconds into takeof in 1986. The investigation found that the ambient temperature at the time of the shuttle launch was closely related to the damage of O-rings, which are a critical component of the shuttle. See this earlier exercise if you would like to browse the original data.
Answer:
p <- function(temp)
{
phat <- exp(11.6630 - 0.2162 * temp) / (1 + exp(11.6630 - 0.2162 * temp))
return (round(phat,3))
}
p(51)
## [1] 0.654
p(53)
## [1] 0.551
p(55)
## [1] 0.443
Answer:
prob <- data.frame(shuttle=seq(1:23),
temperature=c(53,57,58,63,66,67,67,67,68,69,70,70,70,70,72,73,75,75,76,76,78,79,81),
damaged=c(5,1,1,1,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,0,0),
undamaged=c(c(1,5,5,5,6,6,6,6,6,6,5,6,5,6,6,6,6,5,6,6,6,6,6)))
prob$rating <- prob$damaged / (prob$damaged + prob$undamaged)
ggplot(prob,aes(x=temperature,y=damaged)) + geom_point() + stat_smooth(method = 'glm', family ='binomial')
## Warning: Ignoring unknown parameters: family
Answer:
We have make sure residuals have a Normal distribution, and that the variance of the residuals is constant. There is a linear relationship between temperature and the probability of a damaged O-ring. It assumes that observations are independent.