link <- url("https://gregorkb.github.io/data/height_length_index_pinky_shoesize_combined.csv")
hg0 <- read.table(link,
sep = ",",
header = T,
col.names = c("ft","inches","ind","pnk","shoe","shoe_wm","class"))
# remove a 'uk' shoe size
hg <- hg0[hg0$shoe_wm %in% c("m","w"),]
# create response taking the value 1 for "w" and 0 for "m"
hg$w <- ifelse(hg$shoe_wm == "w", 1, 0)
# convert feet + inches to cm
hg$hgt <- (hg$ft*12 + hg$inches)*2.54STAT 516 hw 10
Students in several statistics courses completed a survey in which they reported their heights (in feet and inches), index and pinky finger lengths (mm), shoe size, and shoe size gender (“w”/“m”). Here we will consider using logistic regression to predict the reported shoe size gender (“w”/“m”) based on the other reported measurements. The R code below reads in and cleans the data, constructing a response variable equal to \(1\) for shoe size gender “w” and equal to \(0\) for shoe size gender “m”.
The next chunk of R code creates a training data set from observations collected in STAT 516 classes and a testing data set from the remaining observations.
# make training and testing data sets
tr_obs <- grep("516",hg$class) # look for string "516" in class
tr <- hg[tr_obs,] # create training data set
ts <- hg[-tr_obs,] # create testing data set1.
Using the data collected from STAT 516 students (the training data set), fit a logistic regression model for predicting shoe size gender response “w” based on the index finger length. Report the slope coefficient estimate and interpret its value.
2.
Make a scatter plot of the response values against the index finger lengths. Include the fitted probabilities on the scatterplot.
3.
Comment on the strength of evidence in the data of a relationship between the shoe size gender response and index finger length.
4.
Report the p value for the Hosmer-Lemeshow goodness of fit test for the logistic regression model and interpret the result of the test (you may have to reduce the number of “bins” to avoid getting a warning message).
5.
Make a plot of the ROC curve for classifying STAT 516 students as wearing “w” or “m” shoes based on the fitted model.
5.
Using the model trained on the STAT 516 students, obtain predicted probabilities for the students in the testing data set. Then report the proportion of students in the testing data set correctly classified as wearing “w” or “m” shoes under the rule which assigns the class “w” when the predicted probability is at least \(0.5\).
6.
Now fit a model on the STAT 516 students which uses height to predict the shoe size gender response “w”. Then, as in the previous part, obtain predicted probabilities based on this model for the students in the testing data set and report the proportion of these correctly classified as “w” or “m” under the rule which assigns the class “w” when the predicted probability is at least \(0.5\).
7.
State whether you believe index finger length or height is a better predictor of the shoe size gender response. Explain your answer.
8.
Investigate whether one should include height, index finger, and pinky finger length all together in one model to predict the shoe size gender response. Report your findings. There is more than one way to answer this!