8.2 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.
babies <- read.csv('https://raw.githubusercontent.com/jbryer/DATA606Fall2018/master/data/os3_data/Ch%208%20Exercise%20Data/babies.csv')
#a ^y = 120.0684 - 1.9287 * parity
summary(lm(babies$bwt ~ babies$parity))
##
## Call:
## lm(formula = babies$bwt ~ babies$parity)
##
## Residuals:
## Min 1Q Median 3Q Max
## -65.068 -11.068 0.396 10.932 57.860
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 120.0684 0.6005 199.942 <2e-16 ***
## babies$parity -1.9287 1.1895 -1.621 0.105
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 18.22 on 1234 degrees of freedom
## Multiple R-squared: 0.002126, Adjusted R-squared: 0.001317
## F-statistic: 2.629 on 1 and 1234 DF, p-value: 0.1052
#b Predicted weight of first born is 120.0684
# Predicted weight of second born and so forth is 118.1397
120.0684 - 1.9287 * 0
## [1] 120.0684
120.0684 - 1.9287 * 1
## [1] 118.1397
#c No there is not statistically significant relationship between the average weight and parity because p-value is greather than 0.05.
8.4 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 South Wales, Australia, in a particular school year. Below are three observations from this data set.
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).
#a ^y = 18.93 ??? 9.11 * eth + 3.10 * sex + 2.15 * lrn
#b The slope of eth says that, all else being equal, there is a 9.11 day decrease in the predicted absenteeism when the subject is not aboriginal.
# The slope of sex says that, all else being equal, there is a 3.10 day increase in the predicted absenteeism when the subject is male.
# The slope of lrn says that, all else being equal, there is a 2.15 day increase in the predicted absenteeism when the subject is a slow learner.
#c The residuals is -22.18
eth <- 0 #aboriginal
sex <- 1 #male
lrn <- 1 #slow learner
missed_days <- 2
prediction <- 18.93 - 9.11 * eth + 3.1 * sex + 2.15 * lrn
missed_days - prediction #residuals
## [1] -22.18
#d R2: 0.08933641, Adjusted R2: 0.07009704
n <- 146 #number of observations
k <- 3 #number of explanatory variables
variance_residual <- 240.57
varriance_all_students <- 264.17
1 - (variance_residual / varriance_all_students) # R2
## [1] 0.08933641
1 - (variance_residual / varriance_all_students) * ( (n-1) / (n-k-1) )
## [1] 0.07009704
8.8 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.
# No learner status variable should be removed from the model first because it has the highest adjusted R2.
8.16 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.
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(1,5,5,5,6,6,6,6,6,6,5,6,5,6,6,6,6,5,6,6,6,6,6)
orings <- data.frame(temperature, damaged, undamaged)
#a When the temperature is low, there is more damage to the o-rings
plot(orings$temperature, orings$damaged)
#b The summary of this model tells the number of damaged O-rings, with 11.66 as the y-intercept and number of O-rings damaged to decrease by -0.2162 as temperature increases. This is statistically significant because of z-value is -4.07 and the p-value is less than 0.05.
#c log(pi/1-pi) = y-intercept + b1(temperature)
# log(pi/1-pi) = 11.6630 - .2172 * temperature
#d Based on the model, I do think concerns regarding o-rings are justified because temperature drops as we go higher. Therfore, its essential to have o-rings that can withstand the temeperature drop.
8.18 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 takeoff 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.
temperature <- c(51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71)
p <- function(temperature){
regression_line <- 11.6630 - 0.2162 * temperature
p_hat <- exp(regression_line) / (1 + exp(regression_line))
return (round(p_hat*100,2))
}
#a Probablity of O-rings becoming damaged at each of the following temperature:
p(51)
## [1] 65.4
p(53)
## [1] 55.09
p(55)
## [1] 44.32
p(57)
## [1] 34.06
p(59)
## [1] 25.11
p(61)
## [1] 17.87
p(63)
## [1] 12.37
p(65)
## [1] 8.39
p(67)
## [1] 5.61
p(69)
## [1] 3.72
p(71)
## [1] 2.44
#b
probability <- c(p(51), p(53), p(55), p(57), p(59), p(61), p(63), p(65), p(67), p(69), p(71))
model_plot <- data.frame(temperature, probability)
library(ggplot2)
ggplot(model_plot, aes(temperature, probability)) +
geom_point() +
geom_smooth()
#c There are two key conditions for fitting a logistic regression model:
# 1. Each predictor xi is linearly related to logit(pi) if all other predictors are held constant.
# 2. Each outcome Yi is independent of the other outcomes.
# Condition 1 is hard to say because we do not have that many observations. But we can assume that the observations we have are independent.