See https://data606.net/assignments/homework/ for more information. Chapter 8 - Multiple and Logistic Regression Practice: 8.1, 8.3, 8.7, 8.15, 8.17 Graded: 8.2, 8.4, 8.8, 8.16, 8.18
Refer to “Getting Started with R” in https://data606.net/post/
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
\[w_{b} = 120.07 - 1.97*p\] where \[w_{b}\] is birth weight in oz, and p is parity.
The slope means a baby with parity of 0 ,i.e., first born, weighs 120.07 oz on average.
A baby of parity of 1, second born or more, will have a birth weight of 118.1 oz.
p = 0.1052 which is greater than 0.05 and 0.1 so it is not statistically significant at the 95% or 90% confidence level.
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).18 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
abs = 18.93 - 9.11eth + 3.1sex + 2.15*lrn
All other factors being the same:
The slope of eth indicates that non-aboriginal students miss 9.11 fewer days on average.
The slope of sex indicates that male students miss 3.10 days more on average.
The slope of lrn indicates that slow learners miss 2.15 more days on average.
a student who is aboriginal, male, a slow learner, and missed 2 days of school.
eth <- 0 # Aboriginal
sex <- 1 # Male
lrn <- 1 # Slow Learner
missedActualDays = 2
predictedDays = 18.93 - 9.11*eth + 3.1*sex + 2.15*lrn
paste0("Predicted Days: ", predictedDays)## [1] "Predicted Days: 24.18"
residualDays <- missedActualDays - predictedDays
paste0("Residual Days: ", residualDays)## [1] "Residual Days: -22.18"
Calculate the R2 and the adjusted R2. Note that there are 146 observations in the data set.
\[R^2 = 1 - \frac{Var(e)}{Var(y)} = 1 - 240.57264.17 = 0.08933641\]
\[R^2_{adjusted} = 1 - (\frac{Var(e)}{Var(y)}) * (\frac{n???1}{n???k???1}) = 1 ??? (240.57/264.17)*(146???1/146???3???1)) = 0.07009704\]
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?
paste0("Since adjusted R2 improves when learner status is removed, learner status should be removed first.")## [1] "Since adjusted R2 improves when learner status is removed, learner status should be removed first."
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
Examine these data and describe what you observe with respect to the relationship between temperatures and damaged O-rings.
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)
ShuttleMission <- data.frame(temperature, damaged, undamaged)
plot(ShuttleMission)According to the above data, - Higher number of damaged O-rings are observed when lower temperatures were recorded. - Less number of damaged O-rings are observed when higher temperatures were recorded.
A summary of this model is given below. Describe the key components of this summary table in words. 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
This model is represented by two components: One, is the Intercept and the second one is the Temperature values.
The Estimate identifies the parameter estimate for the model. The Z value and the P-value help with distinguishing important information from less significant parameters by telling us how good the variables predict this model.
\[log(\frac{p}{1???p} ) = 11.6630 ??? 0.2162???T\]
Where p is the probability of damaged o-rings and T is temperature (F).
Yes, the result is statistically significant beyond the 95% confidence level at p=0.0000. The slope also indicates that lower temperatures result in greater probability of o-ring damage.
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.
The logistic model fit to these data may be written as
\[log(\frac{p}{1-p}) = 11.6630 - 0.2162 * Temperature\]
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: \[p_{57} = 0.341\] \[p_{59} = 0.251\] \[p_{61} = 0.179\] \[p_{63} = 0.124\] \[p_{65} = 0.084\] \[p_{67} = 0.056\] \[p_{69} = 0.037\] \[p_{71} = 0.024\]
\[log(\frac{p}{1-p}) = e^{11.6630-0.2162???T}\] \[p + p*e^{11.6630-0.2162*T} = e^{11.6630-0.2162*T}\] \[p=\frac{e^{11.6630-0.2162???T}}{1+e^{11.6630???0.2162???T}}\] \[p_{51} = \frac{e^{11.6630-0.2162???51}}{1 + e^{11.6630-0.2162???51}} = 0.6540297\] \[p_{53} = \frac{e^{11.6630-0.2162???53}}{1 + e^{11.6630-0.2162???53}} = 0.5509228\] \[p_{55} = \frac{e^{11.6630-0.2162???55}}{1 + e^{11.6630-0.2162???55}} = 0.4432456\]
p_51 = exp(11.663-0.2162*51)/(1+exp(11.663-0.2162*51))
p_51## [1] 0.6540297
p_53 = exp(11.663-0.2162*53)/(1+exp(11.663-0.2162*53))
p_53## [1] 0.5509228
p_55 = exp(11.663-0.2162*55)/(1+exp(11.663-0.2162*55))
p_55## [1] 0.4432456
temp.x <- seq(from = 51, to = 71, by = 2)
y <- c(round(p_51, 4), round(p_53, 4), round(p_55, 4), 0.341, 0.251, 0.179, 0.124, 0.084, 0.056, 0.037, 0.024)
plot(temp.x, y, type = "o", col = "blue")library(ggplot2)
logistic_df <- as.data.frame(cbind(temp.x, y))
ggplot(NULL, aes(x=temp.x, y=y)) +
geom_line(data = logistic_df, colour = 'red')ggplot(ShuttleMission, aes(x=temperature,y=damaged)) +
geom_point() +
stat_smooth(method = 'glm', family = 'binomial')Logistic Regression requires that we fulfill their two key conditions for creating this model.
Both conditions are difficult to verify. There has only been 23 shuttle missions, which may not be enough of a sample size to adequate see if the first criteria can be satisfied. And for number 2, shuttles are very complicated. It is unclear that the O ring is independent of other outcomes. This needs further investigation. Therefore, we may have difficulty assuming that this logistic regression can be used with the information that we have right now.
We need to make sure that the residuals have a Normal distribution, and that the variance of the residuals is constant.