Chapter 8 - Multiple and Logistic Regression
Graded: 8.2, 8.4, 8.8, 8.16, 8.18
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
b0 = 120.07 partity,b1 = -1.93
y = 120.07 - 1.93 * x
Parity, x =0 y= 120.07 the predicated birth weight is 120.07 when first borns, x =0.
Other, x =1,
y <- 120.07 - 1.93*1
y
## [1] 118.14
The p-value of 0.1052 is given larger than 0.05, the H0, hypothesis can not be rejected, so it is not a statistically significant relationship between the average birth weight and partity.
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.
predictabsences = 18.93 - 9.11eth + 3.10sex + 2.15*lrn
The slope of ethic indicate that it is 9.11 decreasing in predicted absenteeism when children are not .
The slope of sex indicate that it is 3.10 increaseing in predicated absenteeism when children are male.
The slope of lrn indicate that it is 2.15 increasing in predicated absenteeism when children are in slower learning status.
eth <- 0
sex <- 1
lrn <- 1
actualabsences <- 2
predictabsences <- 18.93 - 9.11*eth + 3.10*sex + 2.15*lrn
predictabsences
## [1] 24.18
residual <- actualabsences - predictabsences
residual
## [1] -22.18
variability_residual <- 240.57
variability_outcome <-264.17
R2 <- 1-(variability_residual/variability_outcome)
R2
## [1] 0.08933641
n <- 146
# predicator variable, k
k <- 3
adjust_R2 <- 1 - ((variability_residual/variability_outcome)*((n-1)/(n-k-1)))
adjust_R2
## [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?
The forth model without learner status has the highest adjusted R2 of 0.0723, so we compare it to the adjusted R2 for the full model. Because eliminating duration leads to a model with a higher adjusted R2, we drop learner status from the model.
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.
The damage o-rings occurred under 66 temperature from 1 to 5, and it seem over the 66 degree of temperature which show more stable only one or no failure of o-rings.
The key components are the Intercept and the Temperature values. The intercepts is the value of damage o-ring when temperature is 0. And the temperature values is the slope of increasing temperature per each degrees.
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
log(p / (1-p))= 11.6630 ??? 0.2162 * Temperature
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 takeo??? 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.
log(p / (1-p))= 11.6630 ??? 0.2162 * Temperature
tem <- c(51,53,55)
model <-function(x){
f <-11.6630 - 0.2162*x
p <- exp(f)/(1+exp(f))
return(p)
}
model(tem)
## [1] 0.6540297 0.5509228 0.4432456
where ??p is the model-estimated probability that an O-ring will become damaged. Use the model to calculate the probability that an O-ring will become damaged at each of the following ambient temperatures: 51, 53, and 55 degrees Fahrenheit. The model-estimated probabilities for several additional ambient temperatures are provided below, where subscripts indicate the temperature: ??p57 = 0.341 ??p59 = 0.251 ??p61 = 0.179 ??p63 = 0.124 ??p65 = 0.084 ??p67 = 0.056 ??p69 = 0.037 ??p71 = 0.024
library(ggplot2)
df <- 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)))
df$rating <- df$damaged / (df$damaged + df$undamaged)
head(df)
## shuttle temperature damaged undamaged rating
## 1 1 53 5 1 0.8333333
## 2 2 57 1 5 0.1666667
## 3 3 58 1 5 0.1666667
## 4 4 63 1 5 0.1666667
## 5 5 66 0 6 0.0000000
## 6 6 67 0 6 0.0000000
ggplot(df,aes(x=temperature,y=damaged)) + geom_point() + geom_smooth(se = TRUE, method = "lm")
The model can show the degree of temperature at lower level, like 51, the rating of damaged are proportionally large, and the boundary between worst and best condition.
The outcome of result seem to be indepentant condition for every mission.