# Illogical probabilities from logistic regression: with example

I have nine variables, age, bmi, duration of disease, fasting blood glucose, diastolic blood pressure, systolic blood pressure, cholesterol, triglyceride, and HbA1c. Using these variables I want to predict the prevalence of an event (outcome: 1=yes, 0=no) related to this specific disease. I applied logistic regression using stepwise backward elimination.

I got fasting blood glucose, diastolic and systolic blood pressure, cholesterol and triglyceride as non significant variables. The regression coefficients for the remaining variables are:

Next, I want to calculate the probabilities of the event for each patient by the formula $$p = \exp(B_o+B_1X_1+\dotso+B_nX_n)/(1+\exp(B_o+B_1X_1+\dotso+B_nX_n))$$ Out of the total patients that were included in the study only 8% had the event. I don't know why but all the probabilities are coming out to be 1 or approximately 1 for every case.

Neither the regression coefficients nor the variable values are too high. Even with 92% negative events, why is the probability prediction always 1? Is overfitting the reason? If so, how to detect and solve overfitting? My question is why are my probabilities always 1 and how can I fix it? Is there any other method to calculate probabilities?

I am stuck in my research at this point and will be highly grateful to anyone who assists me with this problem.

• I cannot reproduce your calculations of "Probability." (1) Did you remember to include the constant in your calculations? (2) Are you sure you are interpreting these log odds in terms of natural logs and not common logs? – whuber Oct 19 '16 at 23:11
• From what I'm seeing in your coefficients, the larger the variables values in a patient, the more likely the outcome will be 1. I've checked your probability estimates and they are all 1. I think there must be an error when fitting the model, the terms associated with age are very large. Maybe when you adjusted the model you used a factor instead of the continuous values of age and thus you have such large coefficients. – Camila Burne Oct 20 '16 at 2:23
• Thank you for your replies. I have used natural log and yes the constant as well. I calculated the probabilities by first calculating the Bo+B1X1+...+BnXn, just multiplying the variable value with its beta value and adding them. I took the exponential and divided it by adding 1 to it. – Faiz_Yusufi Oct 20 '16 at 14:41
• Respected Camilaaab: Do you think I should run the logistic regression one more time without taking categorical values and use continuous instead? I read another research paper in which they categorized their variables. When I calculated the probabilities for their paper I got all 1. So if I run the logistic regression once more then I might get other variables to be significant as well. – Faiz_Yusufi Oct 20 '16 at 14:50
• You made some kind of mistake in your spreedsheet, obviously: eta = -1.7 + 0.216 + 0.471 + 0.638 + 0.187 + 0.347; exp(eta) / (1 + exp(eta)) [example row from your sheet] does NOT return 1. – Tim Sep 6 '17 at 14:54

## 1 Answer

You didn't show us how did you calculate those "probabilities". You said that you used the formula

$$p = \exp(B_o+B_1X_1+\dotso+B_nX_n)/(1+\exp(B_o+B_1X_1+\dotso+B_nX_n))$$

However, if you used it, then you would get correct results, for example, for the fifth line of your table we have

\begin{align} \eta &= -1.7 + 0.216 + 0.471 + 0.638 + 0.187 + 0.347 \\ p &= e^\eta / (1 + e^\eta) = 0.54 \ne 1 \end{align}

Knowing that all the values you got are obvious overestimates, I guess that the only error that you could have made is that you incorrectly used the formula. As we can see from the first table you provided, you are conducting your logistic regression using dummy variables for levels of your variables. This means that your $X_i$'s are not the actual values of the variables, but rather indicator functions of those variables. For example, parameter for "Age 40-49" is a parameter for $I(X_\text{age} \in (40, 49])$, where indicator function returns $1$ if the condition is met and $0$ otherwise, so for a person in that age we have $\beta_{\text{Age 40-49}} I(X_\text{age} \in (40, 49]) = 0.471 \times 1 = 0.471$, and for a person from other age group it is equal to $\beta_{\text{Age 40-49}} \times 0 = 0$. If you multiplied the parameters by the actual values of your variables, that are in each case greater than $1$, then you obviously got incorrect results.

If this is not the case, then you must have made other kind of error in your computation since if you used the formula correctly, then you wouldn't see all-ones in your results.