Stroke is a global health crisis, causing widespread mortality and disability[1]. Because strokes occur suddenly and often lead to long-term neurological damage, early detection in high-risk individuals is critical for prevention and prompt intervention. By using data-driven risk prediction models, clinicians and public health experts can better identify high-risk populations, allowing for targeted clinical management and lifestyle counseling.
Logistic Regression (LR) is one of the most widely used methods for modeling binary outcomes, such as the presence or absence of a disease[2]. It extends linear regression to categorical outcomes, providing interpretable coefficients that explain how specific factors influence the probability of an event. LR has been applied across diverse fields, including child health[3], road safety[4–6], healthcare resource management[7], and fraud detection[8]. These varied applications demonstrate LR’s flexibility and suitability for real-world decision-making.
In this project, we analyze a publicly available stroke dataset containing key demographic, behavioral, and clinical predictors—such as age, gender, hypertension, heart disease, marital status, work type, residence, smoking status, Body Mass Index (BMI), and average glucose level. These variables are well-documented in cardiovascular literature as significant risk determinants. We cleaned and recoded this data into appropriate numeric formats to develop a series of supervised learning models.
We establish Logistic Regression as our primary, interpretable baseline model and compare its performance against more complex machine learning techniques, including Decision Tree, Random Forest, Gradient Boosted Machine, \(k\)-Nearest Neighbours, and Support Vector Machine (radial).
Methodology
This section outlines our data, how we prepared it, and the modeling framework we used to compare different classifiers.
We started with a dataset of 5,110 observations and 11 predictors commonly linked to stroke risk. We filtered out missing data and inconsistent entries—such as “Unknown,” “N/A,” or rare labels like “children”—which left us with a final group of 3,357 individuals. This clean dataset is stored in the object strokeclean.
Because our goal is to predict a binary outcome (Yes/No), Logistic Regression is our primary approach for determining if a patient has had a stroke (\(Y=1\)) or not (\(Y=0\))[hosmer2013applied?,james2021isl?].
Variables
The key predictors used in our analysis are listed below:
Variable
Type
Description
age
Numeric
Age of the individual (years)
gender
Categorical
Biological sex (Male/Female)
hypertension
Binary (0/1)
Prior hypertension diagnosis
heart_disease
Binary (0/1)
Presence of heart disease
ever_married
Binary
Marital status
work_type
Categorical
Employment category
Residence_type
Binary
Urban vs. Rural
smoking_status
Categorical
Never / Former / Smokes
bmi
Numeric
Body Mass Index
avg_glucose_level
Numeric
Average glucose level
stroke
Binary
Outcome (0=No, 1=Yes)
Addressing Class Imbalance
Our dataset is highly unbalanced:
Yes (Stroke): ~5%
No (No Stroke): ~95%
This imbalance makes model evaluation tricky. A model could simply guess “No Stroke” for everyone and still achieve 95% accuracy, despite being useless for medical diagnosis. To avoid this trap, we look beyond simple accuracy and focus on metrics like sensitivity, specificity, ROC curves, AUC, and Youden’s J statistic.
Dataset Preparation
To ensure our model is valid and to prevent “data leakage” (where the model accidentally sees data it shouldn’t), we applied several preprocessing steps[9]:
Removed Identifiers: We dropped columns like Patient ID since they don’t predict medical risk.
Cleaned Labels: We removed rows with vague labels (e.g., “Unknown”) and standardized rare categories.
Numeric Conversion: We converted age, BMI, and glucose levels into standard numeric formats and turned categorical variables (like gender) into dummy variables.
Consistency Checks: We verified that all values fell within realistic ranges.
Model Validation
Finally, we split the data into training and testing sets. For the machine-learning comparison, we used stratified sampling (via caret::createDataPartition). This ensures that the ratio of stroke to non-stroke patients remains consistent in both the training and testing data, preventing the model from learning from a skewed sample[6].
Logistic regression model
Let \(Y_i\) denote the stroke status for patient \(i\), where
Here, \(\beta_0\) is the intercept, \(\beta_j\) is the change in log-odds of stroke for a one-unit increase in predictor \(x_j\), holding other variables constant.
Exponentiating \(\beta_j\) gives the odds ratio (OR): \[
\text{OR}_j = e^{\beta_j},
\]
which represents the multiplicative change in the odds of stroke for a one-unit increase in \(x_j\).
Model Estimation
Let \(\boldsymbol{\beta} = (\beta_0, \beta_1, \ldots, \beta_p)^\top\) denote the vector of regression coefficients. For independent observations, the likelihood of the data is \[
L(\boldsymbol{\beta})
= \prod_{i=1}^{n}
\pi(\mathbf{x}_i)^{\,y_i}
\left[1 - \pi(\mathbf{x}_i)\right]^{\,1-y_i},
\]
where \(\pi(\mathbf{x}_i) = P(Y_i = 1 \mid \mathbf{x}_i)\).
The maximum likelihood estimate \(\hat{\boldsymbol{\beta}}\) is the value of \(\boldsymbol{\beta}\) that maximizes \(\ell(\boldsymbol{\beta})\). In R, this optimization is carried out automatically using glm(..., family = binomial)
Machine Learning Models and Evaluation
To see if advanced technology could outperform standard methods, we built six different supervised learning models using the caret framework. We wanted to determine if sophisticated algorithms could improve our ability to classify stroke risk compared to the baseline.
The six models were:
Logistic Regression (LR) – Our baseline.
Decision Tree (rpart) – A simple rule-based model.
Random Forest (RF) – An ensemble of many decision trees.
Gradient Boosted Machine (GBM) – A powerful, iterative learning model.
k-Nearest Neighbours (k-NN) – Classification based on similarity to other patients.
Support Vector Machine (SVM-Radial) – A model that finds complex boundaries between groups.
To guarantee a fair fight, every model was treated exactly the same. We used the same 70% training / 30% testing split and applied a consistent cross-validation procedure across the board.Once the model was fitted, we calculated the Odds Ratios and 95% Confidence Intervals to interpret the effect of each predictor.
Data Splitting and Model Fitting in R
We began with our processed dataset, strokeclean. As a reminder, our target outcome is stroke (0 = No, 1 = Yes), and we are using predictors such as age, hypertension, heart_disease, avg_glucose_level, and bmi.
First, we randomly split the data to create a training set (70%) for building the models and a hold-out test set (30%) to evaluate how well they perform on new data.
Data Splitting and Model Fitting in R
The cleaned dataset is stored in the object strokeclean, where the outcome variable is stroke (0 = No stroke, 1 = Stroke), and predictors include age, hypertension, heart_disease, avg_glucose_level, bmi, smoking_status, and others.
First, the dataset is randomly divided into a training set (70%) and a test set (30%) to evaluate out-of-sample performance, logistic regression model is then fitted on the training data:
From this model, estimated odds ratios and 95% confidence intervals are computed as:
Model Predictions and Performance Measures
Predicted probabilities on the test set are obtained as:
Using a classification threshold \(c = 0.5\), the predicted class for patient \(i\) is
These metrics are widely used in stroke-risk modeling literature and as per article it is often used to find optimial classidfication threshhold.[6].
Analysis
Before starting to generate predictive models, an exploratory analysis was conducted to understand the distribution, structure, and relationships within the cleaned dataset (N = 3,357). This step is crucial in rare-event medical modeling because data imbalance, skewed predictors, or correlated variables can directly influence model behavior and classification performance.
Distribution of Key Continuous Variables
Histograms were used to assess the spread of the primary numeric predictors (Age, BMI, and Average Glucose Level). These variables demonstrate clinically expected right-skewness, particularly glucose and BMI, consistent with published literature on metabolic and cardiovascular risk distributions.
We examined the distributions of our three main numeric variables to identify patterns and potential risk factors.
Age The age distribution is smooth, starting from late adolescence. The majority of individuals fall between 40 and 70 years old, which corresponds to the population at highest risk for stroke. Since there are no extreme clusters or gaps, Age serves as an excellent continuous predictor.
Average Glucose Level This variable shows a clear right-skew, meaning most people have normal levels, but there is a long “tail” of data extending above 200 mg/dL. This highlights a specific subgroup of patients with poor metabolic health (likely indicating diabetes), which is a critical driver for heart disease and stroke risk.
BMI BMI values are tightly grouped between 22 and 35, with relatively few outliers. Because there is less variation here compared to Age or Glucose, it may play a slightly weaker role in distinguishing between stroke and non-stroke cases. This observation aligns with our regression results, where BMI showed a smaller contribution than vascular predictors.
Distribution of Key Categorical Variables
Bar charts help visualize population composition. The dataset shows more females than males, a balanced rural–urban distribution, and substantial variation in work type and smoking behavior.
Figure 1: Sample composition by gender, residence type, and smoking status.
Interpreatation
Gender:The dataset has more female patients (61%) than males (39%). This imbalance should be noted because gender-related model effects may partly reflect sample composition.
Residence Type: The population is nearly evenly split between urban (51%) and rural (49%) residents. This indicates no geographic bias and good representation of both environments.
Smoking Status: Most participants never smoked (54%), while 25% are former smokers and 22% are current smokers. This provides enough variation to meaningfully examine smoking as a behavioral risk factor for stroke.
Stroke Risk for Clinical and Behavioral Predictors
Figure 2: Stroke percentages (95% CI) by hypertension, heart disease, and smoking status.
Interpretation
The figure summarises how stroke risk varies across key categorical predictors:
Hypertension
Stroke risk is clearly higher among hypertensive patients.
Confidence intervals show a noticeable separation, supporting a strong association.
Heart Disease
Patients with heart disease show higher stroke percentages than those without.
The pattern is consistent with cardiovascular disease being a major clinical risk factor.
Smoking Status
Former and current smokers have higher stroke percentages than never-smokers.
This reflects the long-term vascular effects of tobacco exposure.
Overall, these categorical predictors show patterns aligned with clinical expectations:
vascular risks (hypertension, heart disease) and behavioural risks (smoking) are all associated with elevated stroke likelihood.
Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
ℹ Please use tidy evaluation idioms with `aes()`.
ℹ See also `vignette("ggplot2-in-packages")` for more information.
ℹ The deprecated feature was likely used in the ggcorrplot package.
Please report the issue at <https://github.com/kassambara/ggcorrplot/issues>.
Interpretation
Correlation Heatmap of Key Numeric Predictors, all correlations are weak to moderate (0.00–0.26) = no multicollinearity concerns.
Age shows small but meaningful positive correlations with:
glucose (0.24)
hypertension (0.26)
heart disease (0.26) = consistent with known aging-related cardiovascular risk patterns.
BMI has very weak correlations with all other predictors (0.04–0.16) = behaves independently in this dataset.
Avg glucose moderately correlates with:
hypertension (0.17)
heart disease (0.14) = aligns with metabolic/vascular relationships.
Hypertension and heart disease are weakly correlated (0.11) = related but not redundant.
These correlations confirm that the predictors provide unique, non-overlapping information, and all can be safely included in the logistic regression model without multicollinearity issues.
Call:
glm(formula = stroke ~ age + hypertension + heart_disease + avg_glucose_level +
bmi + smoking_status + gender + ever_married, family = binomial(link = "logit"),
data = stroke_train)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -8.924079 0.992603 -8.991 <2e-16 ***
age 0.072637 0.008089 8.979 <2e-16 ***
hypertension 0.455377 0.229005 1.988 0.0468 *
heart_disease 0.487385 0.270707 1.800 0.0718 .
avg_glucose_level 0.003777 0.001705 2.215 0.0267 *
bmi 0.006536 0.015709 0.416 0.6774
smoking_status 0.234263 0.129934 1.803 0.0714 .
gender 0.230592 0.206934 1.114 0.2651
ever_married 0.118496 0.311030 0.381 0.7032
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 953.42 on 2348 degrees of freedom
Residual deviance: 776.77 on 2340 degrees of freedom
AIC: 794.77
Number of Fisher Scoring iterations: 7
Interpretation — Logistic Regression Coefficients
Age is a strong and highly significant predictor (p < 0.001). Higher age is associated with a substantial increase in the odds of stroke.
Hypertension has a significant positive effect on stroke risk (p = 0.0468), indicating hypertensive individuals are more likely to experience stroke.
Average glucose level is also a important predictor (p = 0.0267). Higher glucose values modestly increase stroke risk.
Heart disease shows a positive association but is only borderline significant (p = 0.0718). This suggests a potential effect, but not statistically explainable in this model.
Smoking has likewise borderline significant (p = 0.0714), indicating a increased risk among smokers, but the evidence is not too much strong.
BMI, gender, and marital status show no meaningful statistical association with stroke in this dataset (all p > 0.26). These variables did not contribute substantially to prediction after accounting for other factors.
Model fit improved substantially from the null model (deviance reduced from 953.4 to 776.8; AIC = 794.8), indicating a reasonable fit and useful predictive value.
The logistic regression results give us a clear picture of how each predictor influences the likelihood of having a stroke, assuming all other factors stay the same.
Age (OR = 1.075, CI: 1.059–1.093) Age is by far the strongest continuous predictor. For every additional year of age, the odds of having a stroke increase by about 7.5%. The confidence interval is tight and stays well above 1, confirming that this is a highly significant risk factor.
Hypertension (OR = 1.577, CI: 0.996–2.450) Individuals with a history of hypertension have roughly 58% higher odds of stroke compared to those without it. However, the confidence interval dips just below 1, meaning the effect is on the borderline of statistical significance. Despite this uncertainty, the large increase in odds suggests it is still clinically important.
Heart Disease (OR = 1.628, CI: 0.942–2.733) Similar to hypertension, heart disease raises stroke odds by about 63%. While the link is positive, the wide confidence interval (which crosses 1) indicates that the statistical evidence in this specific dataset is not definitive.
Average Glucose Level (OR = 1.004, CI: 1.000–1.007) Higher glucose levels are linked to a slightly increased risk. Although the per-unit effect looks small, the confidence interval suggests marginal significance, which aligns with the known medical link between metabolic health and stroke.
BMI (OR = 1.007, CI: 0.975–1.037) Interestingly, BMI showed almost no meaningful effect on stroke risk in our model. The confidence interval overlaps 1, suggesting that once we account for other factors (like age and glucose), BMI itself is not a significant driver here.
Smoking Status
Former Smokers (OR = 1.263): Show 26% higher odds, though the evidence is statistically weak.
Current Smokers (OR = 1.598): Face nearly 60% higher odds of stroke. While the confidence interval still overlaps 1 (likely due to sample size), the trend clearly points to increased risk for active smokers.
Gender & Marital Status Females showed slightly higher odds (OR = 1.259), and Marital Status (OR = 1.126) showed a small positive association, but neither factor was statistically significant in this analysis.
Positive Predictive Value (Precision)\[
\text{PPV} =
\frac{TP}{TP + FP}.
\]Negative Predictive Value (NPV)
\[
\text{NPV} =
\frac{TN}{TN + FN}.
\]
Interpretation of Logistic Regression Performance (Test Set)
Accuracy = 94.25% The model correctly classified most cases, mainly because the dataset is highly imbalanced (only ~6% stroke cases). High accuracy here does not mean good stroke detection.
Sensitivity (True Positive Rate) = 0.017 The model correctly identified only 1 out of 59 actual stroke cases (≈1.7%). = This shows the model fails to detect stroke cases, which is common in rare-event medical datasets.
Specificity (True Negative Rate) = 1.00 The model correctly classified all non-stroke cases. = It is extremely good at predicting “No stroke,” which dominates the dataset.
Positive Predictive Value (Precision) = 1.00 When the model predicts “Yes,” it is always correct — but it predicted “Yes” only once. High precision is misleading because the model rarely predicts a positive case.
Negative Predictive Value = 0.942 Most “No” predictions are correct, matching the overall class imbalance.
Kappa = 0.031 Kappa measures agreement beyond chance. A value near zero shows the model performs only slightly better than random when considering class imbalance.
Balanced Accuracy = 0.508 When weighting sensitivity and specificity equally, the model performs at chance level (~50%). = Confirms that stroke detection is weak.
McNemar’s Test p < 0.0001 Strong evidence that the model’s errors are systematically skewed—it overwhelmingly predicts “No stroke.”
The logistic regression model achieves high accuracy only because the negative class dominates.It detects almost no true stroke cases, giving extremely poor sensitivity. It performs well for the majority class (non-stroke), but fails for the minority class (stroke).
These results highlight the challenge of severe class imbalance, which requires additional techniques (e.g., SMOTE, class weights, resampling) to improve medical-event prediction.
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
A higher AUC (closer to 1) indicates better discrimination between stroke and non-stroke cases. Values substantially above 0.5 indicate that the model performs better than random classification.
Interpretation of ROC Curve and AUC (Test Set)
The ROC curve evaluates the model’s ability to distinguish between stroke and non-stroke cases across all possible classification thresholds, not just the default 0.5 cutoff.
The AUC = 0.815, which indicates good discriminative performance.
AUC = 0.5 is no discrimination (random guessing)
AUC = 0.7–0.8 is acceptable
AUC = 0.8–0.9 is good
AUC > 0.9 is excellent
Even though the confusion matrix showed poor sensitivity at threshold 0.5, the AUC reveals that the model can separate the two classes reasonably well if a better threshold is chosen.
The strong AUC compared to weak sensitivity highlights the impact of severe class imbalance and the importance of customizing the probability cutoff for medical prediction tasks.
Overall, the ROC analysis suggests that the logistic model contains useful predictive signal, but performance for detecting stroke can be improved with:
set.seed(123)index <-createDataPartition(model_df$stroke, p =0.70, list =FALSE)train_data <- model_df[index, ]test_data <- model_df[-index, ]train_data$stroke <-factor(train_data$stroke, levels =c("No","Yes"))test_data$stroke <-factor(test_data$stroke, levels =c("No","Yes"))
Train control settings
library(caret) # <- add this line to be safectrl <-trainControl(method ="repeatedcv",number =5,repeats =3,classProbs =TRUE,summaryFunction = twoClassSummary,verboseIter =FALSE)
Across all six models, overall accuracy and specificity are very high, mainly because the dataset is highly imbalanced (only ~6% stroke cases). However, sensitivity is extremely low across every model, meaning that almost none of the models correctly identify stroke cases.
Logistic Regression (AUC = 0.78) and GBM (AUC = 0.76) show the best overall discrimination, indicated by the highest AUC values. These models are better at ranking high-risk vs. low-risk individuals, even though they still fail at detecting positives under the default 0.5 threshold.
Tree-based models (Decision Tree, Random Forest, GBM) achieve slightly higher sensitivity than LR, but only marginally (still around 1–2%). KNN and SVM detect 0 stroke cases at this threshold, despite high accuracy.
All models appear to perform well based on accuracy and specificity, but this is misleading—they are failing at the most important task: detecting stroke cases. This confirms that class imbalance severely affects performance and requires threshold tuning, resampling, or cost-sensitive learning to achieve meaningful sensitivity.
ROC curve comparison across models
library(scales)roc_list <-list(LR =roc(test_data$stroke,predict(model_lr, test_data, type ="prob")[, "Yes"],levels =c("No","Yes"), direction ="<"),Tree =roc(test_data$stroke,predict(model_tree, test_data, type ="prob")[, "Yes"],levels =c("No","Yes"), direction ="<"),RF =roc(test_data$stroke,predict(model_rf, test_data, type ="prob")[, "Yes"],levels =c("No","Yes"), direction ="<"),GBM =roc(test_data$stroke,predict(model_gbm, test_data, type ="prob")[, "Yes"],levels =c("No","Yes"), direction ="<"),KNN =roc(test_data$stroke,predict(model_knn, test_data, type ="prob")[, "Yes"],levels =c("No","Yes"), direction ="<"),SVM =roc(test_data$stroke,predict(model_svm, test_data, type ="prob")[, "Yes"],levels =c("No","Yes"), direction ="<"))auc_vals <-sapply(roc_list, auc)roc_df <-do.call(rbind, lapply(names(roc_list), function(m) { r <- roc_list[[m]]data.frame(model = m,specificity =rev(r$specificities),sensitivity =rev(r$sensitivities) )}))roc_df$model <-factor(roc_df$model, levels =names(roc_list))label_map <-paste0(names(auc_vals), " (AUC = ", sprintf("%.3f", auc_vals), ")")names(label_map) <-names(auc_vals)model_cols <-c(LR ="#E69F00",Tree ="#0072B2",RF ="#009E73",GBM ="#CC79A7",KNN ="#F0E442",SVM ="#000000")ggplot(roc_df, aes(x =1- specificity, y = sensitivity,colour = model, group = model)) +geom_abline(intercept =0, slope =1,linetype ="dashed", colour ="grey70", linewidth =0.6) +geom_line(linewidth =1) +scale_color_manual(values = model_cols,breaks =names(label_map),labels = label_map,name ="Model" ) +scale_x_continuous(labels =percent_format(accuracy =1)) +scale_y_continuous(labels =percent_format(accuracy =1)) +labs(x ="1 – Specificity (False Positive Rate)",y ="Sensitivity (True Positive Rate)" ) +theme_bw(base_size =12) +theme(legend.position =c(0.65, 0.25),legend.background =element_rect(fill ="white", colour ="grey80"),legend.title =element_text(face ="bold"),panel.grid.minor =element_blank() )
Interpretation
Interpretation of ROC Comparison Across Models
Logistic Regression (AUC = 0.779) performs the best among all six models, showing the strongest ability to differentiate stroke vs. non-stroke cases.
Random Forest (AUC = 0.725) and GBM (AUC = 0.759) also show good discriminative ability and are close competitors to logistic regression.
KNN (AUC = 0.667) performs moderately, better than random guessing but weaker than the tree-based and regression models.
Decision Tree (AUC = 0.648) and SVM (AUC = 0.639) show the lowest AUC values, indicating weaker predictive performance.
All models perform above 0.5, meaning they all do better than random chance — but with large differences in quality.
The ROC curves demonstrate that tree-based ensemble models (RF, GBM) and logistic regression extract more meaningful patterns from the data compared to simpler (Tree) and distance-based (KNN, SVM) methods.
Overall, logistic regression remains the most stable and best-performing model for this dataset, despite class imbalance challenges.
This is the strongest predictor. Its OR is clearly > 2, and the whole 95% CI lies above 1 (orange point), meaning hypertensive patients have more than double the odds of stroke, with strong statistical evidence.
Age (per year)
The OR is slightly above 1 with a narrow CI fully above 1 (orange).
Each additional year of age increases stroke odds by a small but consistent amount, making age an important continuous risk factor.
Average glucose level
OR is just above 1 with a tight CI above 1 (orange).
Higher glucose is associated with a modest but statistically reliable increase in stroke risk, consistent with metabolic / diabetes-related vascular risk.
Ever married, heart disease, smoking status, gender, BMI, residence, work type
Their confidence intervals all cross 1 (grey points), so in this multivariable model they do not show statistically significant effects after adjusting for age, hypertension and glucose.Some (e.g., heart disease, smoking) still have ORs above 1, suggesting possible elevated risk, but the evidence is weaker in this dataset.
Overall message: The forest plot shows that, after adjusting for other variables, hypertension, older age, and higher average glucose level are the clearest independent predictors of stroke, while other factors have smaller or more uncertain effects. This aligns well with established clinical knowledge and supports your logistic regression model as a sensible risk-stratification tool.
Confusion Matrix and Statistics
Reference
Prediction No Yes
No 903 46
Yes 46 13
Accuracy : 0.9087
95% CI : (0.8892, 0.9258)
No Information Rate : 0.9415
P-Value [Acc > NIR] : 1
Kappa : 0.1719
Mcnemar's Test P-Value : 1
Sensitivity : 0.22034
Specificity : 0.95153
Pos Pred Value : 0.22034
Neg Pred Value : 0.95153
Prevalence : 0.05853
Detection Rate : 0.01290
Detection Prevalence : 0.05853
Balanced Accuracy : 0.58593
'Positive' Class : Yes
Interpretation (threshold = 0.2)
With a lower decision criterion of 0.2, the model successfully identifies 13 out of 59 stroke cases (sensitivity = 22%), compared to only one case with the default 0.5 threshold.
Specificity remains high at almost 95%, indicating that the majority of non-stroke patients are still properly categorized as “no stroke” (903 out of 949).
While overall accuracy declines from 94% to 91%, balanced accuracy improves (from ≈0.51 to ≈0.59), indicating a greater balance of sensitivity and specificity.
This change indicates a therapeutically reasonable compromise: the model detects more possible stroke patients (fewer missed cases) at the expense of a moderate rise in false positives.
Conclusion
In this study, we set out to determine if standard demographic, behavioral, and clinical records could effectively predict stroke risk. We compared a traditional Logistic Regression model against several machine learning algorithms using a cleaned dataset of 3,357 individuals. Because strokes were rare in our sample (occurring in only about 5% of cases), we faced a classic “class imbalance” challenge, which made identifying high-risk patients particularly difficult.
Key Risk Factors
Our baseline Logistic Regression model confirmed what we know from clinical literature: Age, hypertension, heart disease, and high glucose levels are the strongest predictors of stroke. Smoking also stood out as a substantial risk factor. The model produced odds ratios significantly greater than 1 for these variables (with confidence intervals that did not cross 1), confirming them as statistically significant drivers of risk. This validates Logistic Regression as a transparent tool for explaining why a specific patient is at risk.
Model Performance and the “Imbalance” Challenge
When we first ran the Logistic Regression model using the standard decision threshold of 0.5, the results were mixed. While the model performed better than random guessing (based on AUC scores), it struggled to actually find the stroke cases. Specifically, the sensitivity was extremely low (around 2%), meaning the model missed almost every true stroke case because it was biased toward the majority “No Stroke” class.
To fix this, we adjusted the decision threshold down to 0.2. This simple change had a dramatic effect: * Sensitivity jumped from ~2% to ~22%. * Specificity remained high at around 95%. * Overall Accuracy dipped slightly to 91%, but the Balanced Accuracy improved.
This experiment illustrates a critical lesson for medical screening: when dealing with dangerous but rare events like stroke, it is often better to accept a few false alarms (lower precision) in exchange for catching more true cases (higher sensitivity).
Logistic Regression vs. Machine Learning
When we pitted Logistic Regression against advanced models like Random Forest and Gradient Boosted Machines, the advanced models did achieve slightly higher AUC scores. They were better at discriminating between groups across various thresholds.
However, this extra power came at a cost. The machine learning models are “black boxes”—harder to interpret and explain to a patient. In contrast, Logistic Regression provides precise odds ratios that doctors can easily translate into clinical advice.
Future Directions
Overall, our findings show that even simple models using routine health data can meaningfully distinguish stroke risk. While tree-based models offer a slight performance edge, Logistic Regression remains a robust, interpretable baseline.
Future work should focus on: 1. External Validation: Testing these models on data from different hospitals or regions. 2. Calibration: Ensuring the predicted probabilities match real-world risk levels. 3. Data Enrichment: Incorporating longitudinal data (health changes over time) to move this from a theoretical exercise to a practical clinical tool.
3. Asmare, A. A., & Agmas, Y. A. (2024). Determinants of coexistence of undernutrition and anemia among under-five children in rwanda; evidence from 2019/20 demographic health survey: Application of bivariate binary logistic regression model. Plos One, 19(4), e0290111.
4. Rahman, M. H., Zafri, N. M., Akter, T., & Pervaz, S. (2021). Identification of factors influencing severity of motorcycle crashes in dhaka, bangladesh using binary logistic regression model. International Journal of Injury Control and Safety Promotion, 28(2), 141–152.
5. Chen, Y., You, P., & Chang, Z. (2024). Binary logistic regression analysis of factors affecting urban road traffic safety. Advances in Transportation Studies, 3.
6. Chen, M.-M., & Chen, M.-C. (2020). Modeling road accident severity with comparisons of logistic regression, decision tree and random forest. Information, 11(5), 270.
7. Hutchinson, A., Pickering, A., Williams, P., & Johnson, M. (2023). Predictors of hospital admission when presenting with acute-on-chronic breathlessness: Binary logistic regression. PLoS One, 18(8), e0289263.
8. Samara, B. (2024). Using binary logistic regression to detect health insurance fraud. Pakistan Journal of Life & Social Sciences, 22(2).
9. Wang, M. (2014). Generalized estimating equations in longitudinal data analysis: A review and recent developments. Advances in Statistics, 2014.