Muddy Points

Lesson 7: Prediction and Visualization in Simple Logistic Regression

Modified

April 20, 2026

Muddy Points from Spring 2026

1. A little confused about plugging in the predicted probability back into a distribution to predict outcome.

Yeah, so basically all we’ve done up through the predicted probability is find the average probability of the outcome for a specific covariate value. For example, in class, we found the predicted probability of late stage breast cancer for a 60 year old is 0.252. This means that, on average, we estimate 25.2% of 60 year olds diagnosed with breast cancer are late stage.

However, if we wanted to talk about a single individual, they either have late stage breast cancer (outcome of 1) or early stage breast cancer (outcome of 0). So we can use the predicted probability to simulate a draw of 1 or 0.

This is less about reporting our results and more about understanding the relationship between the predicted probability and the outcome. The predicted probability is an estimate of the average probability of the outcome, but it does not tell us for certain what the outcome will be for a specific individual.

2. Assuming assumptions are met, is there a preferred method for constructing intervals? Is normal approximation better to use when available? certain datasets that are better or worse for each? or is it just personal preference?

Basically asking if we should use option 1 or 2.

Option 1 is always correct. Option 2 is a good approximation is most scenarios. When in doubt, go with option 1.

3. Can you please review the augment function again in the context of categorical variables?

Yeah, let’s take a look at the augment() function again. The augment() function takes a fitted model object and adds columns to the original data frame with the fitted values, residuals, and other diagnostic measures.

We can take a look at the output from our model with late stage breast cancer diagnosis and age:

bc_reg = glm(Late_stage_diag ~ Age_c, data = bc, family = binomial)
bc_aug = augment(bc_reg)
glimpse(bc_aug)
Rows: 10,000
Columns: 8
$ Late_stage_diag <fct> 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
$ Age_c           <dbl> 8.1413596, -30.1757668, -2.7630262, 5.9173365, 9.71223…
$ .fitted         <dbl> -0.5256540, -2.7083700, -1.1468169, -0.6523443, -0.436…
$ .resid          <dbl> 1.4072119, -0.3592173, 1.6868099, 1.4639646, -0.998655…
$ .hat            <dbl> 0.0002232196, 0.0006361455, 0.0001291814, 0.0001591697…
$ .sigma          <dbl> 1.072901, 1.072987, 1.072860, 1.072893, 1.072947, 1.07…
$ .cooksd         <dbl> 1.888795e-04, 2.122507e-05, 2.033941e-04, 1.528545e-04…
$ .std.resid      <dbl> 1.4073690, -0.3593316, 1.6869189, 1.4640811, -0.998797…

We can see the variables from the model in the first two rows.

  • Then we get a .fitted column, which gives us the predicted log-odds for each observation.
  • Then we have a .se.fit column, which gives us the standard error of the predicted log-odds for each observation.
  • Then we have a .resid column, which gives us the residuals for each observation. These are not like the residuals in linear regression.
  • We have a .hat column, which gives us the leverage for each observation.

Muddy Points from Spring 2025

1. geom_ribbon() to add bands: is that just to view the range of values and or confidence interval?

geom_ribbon() can be used to add any range of values. In this case, we used geom_ribbon() with our calculated confidence intervals, so it is showing the confidence intervals. It will not automatically do this.

2. I had trouble grasping what it means that the predicted probability is not the same as the predicted outcome? Is it because the outcome is calculated differently?

Our outcome, \(Y\), is a binary value. We can have \(Y=1\) or \(Y=0\). The predicted probability is the estimated \(P(Y=1)\), the probability that \(Y\) is 1. So the probability is related to the outcome, but it is not the outcome itself.

3. Could you please describe why we need to create the new dataframe with the age variable?

I think this is referring to slide 23? And I think the newdata2 variable?

I create a new dataset with the age so that I could create a vector of equally spaced ages. The original observations were not necessarily evenly distributed in the range of age values. By making a vector of ages, I can create a smooth line for the predicted probability across ages.

Muddy Points from Spring 2024

None?? Wowza!