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.

baby.weights <- matrix(c(120.07, 0.60, 199.94, 0.0000, -1.93, 1.19, -1.62, 0.1052), nrow = 2, byrow = TRUE)
row.names(baby.weights) <- c("(Intercept)", "parity")
colnames(baby.weights) <- c("Estimate", "Std. Error", "t value", "Pr(>|t|)")
baby.weights
##             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
  1. Write the equation of the regression line.

The regression line is y = 120.07 -1.93X or in actual variable names: baby.weight (oz) = 120.97 - 19.3 X Parity

  1. Interpret the slope in this context, and calculate the predicted birth weight of first borns and others.

The slope is -1.93, which indicates that we substract -1.93 is the child is not a first born, otherwise this value is not included

first_born = 120.07 -1.93 * 0 = 120.97

others = 120.07 - 1.93 * 1 = 118.14 (c) Is there a statistically significant relationship between the average birth weight and parity?

Based on the p-value, no since it is 10.52%. We should need for it to be below the 5% significance level

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 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).

  1. Write the equation of the regression line.

days_absent = 18.93 - 9.11 X eth + 3.10 X sex + 2.15 X lrn

  1. Interpret each one of the slopes in this context.

For each of the slopes: * we subtract -9.11 days of absence if the student is not aboriginal * We add 3.10 days if the student is a male, 0 if female * We add 2.15 extra days if the student is a slow learner, and 0 if not

  1. Calculate the residual for the first observation in the data set: a student who is aboriginal, male, a slow learner, and missed 2 days of school.
eth <- 0
sex <- 1
lrn <- 1
actual <- 2
days_absent <- 18.93 - (9.11 * eth) + (3.10 * sex) + (2.15 * lrn)
paste0("The expected value is " , days_absent)
## [1] "The expected value is 24.18"
residual <- actual - days_absent
paste0("The residual is ", residual)
## [1] "The residual is -22.18"
  1. The variance of the residuals is 240.57, and the variance of the number of absent days for all students in the data set is 264.17. Calculate the R2 and the adjusted R2. Note that there are 146 observations in the data set.
n <- 146
k <- 3
var.e.i <- 240
var.y.i <- 264.17
r.squared.adj = 1 - (var.e.i/var.y.i) * ((n-1)/(n-k-1))
paste0("R Sqaured Adjusted Value is ", r.squared.adj)
## [1] "R Sqaured Adjusted Value is 0.0723003273073731"

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.

I would start with no ethicity since it has the lowest R square adjusted score.

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.

  1. Each column of the table above represents a different shuttle mission. Examine these data and describe what you observe with respect to the relationship between temperatures and damaged O-rings.

It appears that lower temperatures seem to lead to more failures. This is showed by missions 1-4.

  1. Failures have been coded as 1 for a damaged O-ring and 0 for an undamaged O-ring, and a logistic regression model was fit to these data. A summary of this model is given below. Describe the key components of this summary table in words.

the intercept starts with the predicted undamaged at 11.6630. For each decrease in -0.2162 degrees of temperature, we can expect a drop in undamaged rings.

  1. Write out the logistic model using the point estimates of the model parameters. log(pi/(1-pi)) = 11.6630 -0.2162 * temp

  2. Based on the model, do you think concerns regarding O-rings are justified? Explain.

Based on the data, it does appear that there is a valid concern

8.18

The data provided in the previous exercise are shown in the plot. The logistic model fit to these data may be written as \(log\left( \frac { \hat { p } }{ 1-\hat { p } } \right) =\quad 11.6630\quad -\quad 0.2162\quad X\quad Temperature\) where \(\hat {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: The values for 51, 53, and 55 are below:

p.i <- function(temp)
{
  x <- 11.6630-(0.2162*temp)
  return( exp(1)^(x)/(1+ exp(1)^x ))
}
p.i.51 <- p.i(51)
p.i.53 <- p.i(53)
p.i.55 <- p.i(55)

paste0("The probability values for 51, 53, and 55 are: ", round(p.i.51,2)," " ,round(p.i.53,2), " ", round(p.i.55, 2))
## [1] "The probability values for 51, 53, and 55 are: 0.65 0.55 0.44"
  1. Add the model-estimated probabilities from part (a) on the plot, then connect these dots using a smooth curve to represent the model-estimated probabilities.
x <- c(51,53,55,57,59,61,63,65,67,69,71)
y <- c(p.i.51, p.i.53, p.i.55, 0.341, 0.251, 0.179, 0.124, 0.084, 0.056, 0.037, 0.024)

df <- as.data.frame(cbind(x,y))
ggplot(df, aes(x=df$x,y=df$y)) + geom_point() + ylim(0, 1.0) + xlim(50, 80) + xlab("Temperature (F)") + ylab("Probability of damage") + geom_smooth(method = "auto", se=TRUE, level=0.95)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

  1. Describe any concerns you may have regarding applying logistic regression in this application, and note any assumptions that are required to accept the model’s validity.

The one concern I have with this model is that we have a few outliners in the given graph where it does not have a low probability for temperatures 70 and 75. The residuals are off. Second, The way the graph is drawn, it appears to be a very smooth inverted exponential curve. This may not be true. Also the model is only taking into account temperature. There may be other factors that may contribute to failures.