LASSO Logistic Regression for Clinical Prediction
Source:vignettes/19-lasso-logistic.Rmd
19-lasso-logistic.RmdLASSO Logistic (lassologistic(),
meddecide > Prediction Models > LASSO Logistic)
fits penalized binary logistic regression (LASSO, Ridge, or Elastic Net)
via glmnet::cv.glmnet(), with an automated data-suitability
check, bootstrap optimism correction, and an optional integer clinical
point-scoring system.
Bundled dataset
We illustrate lassologistic() on the bundled
dca_test_data cohort (800 patients, binary
cardiac_event outcome, demographic and laboratory
predictors). For a pathology grading example in jamovi, open
PanNEN Classification
(lassologistic_pannen.omv) from File > Open >
Data Library > meddecide. The saved analyses hold the
predictors, outcome level, folds and random seed fixed while changing
Lambda Selection in Model Options.
Minimum CV Error (lambda.min) minimizes mean
cross-validated deviance. One Standard Error (lambda.1se)
takes the largest penalty within one standard error of that minimum.
Both fits retain the same four predictors in this workbook. Compare
their coefficient magnitudes and cross-validation curves to see the
effect of stronger shrinkage.
Fitting a cross-validated LASSO model with internal validation
Always specify outcomeLevel explicitly so the positive
event class is never inferred from factor level order. Standardization
(standardize = TRUE) is performed strictly
inside every cross-validation fold and bootstrap
resample to prevent preprocessing leakage. This example uses 50
replicates to keep the vignette quick to run. Inspect the number of
successful replicates when assessing the stability of the optimism
correction.
res <- lassologistic(
data = df,
outcome = "cardiac_event",
outcomeLevel = "Yes",
explanatory = c("age", "sex", "diabetes", "hypertension",
"smoking", "cholesterol", "troponin", "creatinine"),
penalty = "lasso",
lambda = "lambda.1se",
nfolds = 10,
random_seed = 42,
suitabilityCheck = TRUE,
bootstrapValidation = TRUE,
bootstrapN = 50,
cv_plot = TRUE,
coef_plot = TRUE,
roc_plot = TRUE
)
res$suitabilityReport$asDF
#> check status
#> "epv" Events per variable No concern
#> "n" Sample size No concern
#> "balance" Class balance Marginal
#> "p" Predictor count No concern
#> "collinearity" Collinearity No concern
#> result
#> "epv" EPV = 12.1 (meets the EPV >= 10 convention)
#> "n" N = 800 (meets the N >= 100 convention)
#> "balance" Minority class: 13.6% (moderate imbalance)
#> "p" p = 9 predictors, n/p = 88.9 (good ratio)
#> "collinearity" Max |r| = 0.62 (<0.7: acceptable)
res$modelSummary$asDF
#> statistic value
#> 1 Complete cases analyzed 800
#> 2 Excluded from analysis None
#> 3 Event class (positive) Yes (n=109)
#> 4 Reference class No (n=691)
#> 5 Variables analyzed 8
#> 6 Model terms (after dummy coding) 9
#> 7 Terms selected 5
#> 8 Penalty type LASSO (L1)
#> 9 Alpha 1.00
#> 10 Lambda (optimal) 0.01906
#> 11 Lambda selection 1SE Rule (parsimonious)
#> 12 CV folds 10
#> 13 Random seed 42
res$coefficients$asDF
#> variable coefficient oddsRatio importance
#> 1 age 0.032753713 1.033296 1.0000000
#> 2 sexMale 0.356923774 1.428927 0.4484271
#> 3 diabetesYes 0.394816341 1.484112 0.4802394
#> 4 hypertensionYes 0.117876741 1.125105 0.1499823
#> 5 cholesterol 0.002279244 1.002282 0.2255026
#> "intercept" (Intercept) -4.990473352 NA NA
res$performance$asDF
#> metric value
#> "auc" AUC (apparent; DeLong 95% CI) 0.713 (0.660-0.765)
#> "threshold" Optimal threshold 0.153
#> "accuracy" Accuracy 0.696
#> "sensitivity" Sensitivity (Recall) 0.651
#> "specificity" Specificity 0.703
#> "precision" Precision (PPV) 0.257
#> "f1" F1 Score 0.369
#> "brier" Brier Score 0.1100
#> interpretation
#> "auc" Acceptable
#> "threshold" Youden index
#> "accuracy" <NA>
#> "sensitivity" <NA>
#> "specificity" <NA>
#> "precision" <NA>
#> "f1" <NA>
#> "brier" 7% better than predicting the base rate (Brier skill score)
res$validationTable$asDF
#> metric apparent optimism corrected
#> "auc" AUC 0.7125493 0.020030043 0.6925192
#> "brier" Brier Score 0.1099847 -0.001083199 0.1110679
#> "slope" Calibration slope 1.7588309 0.378277036 1.3805539
res$cv_plot
res$coef_plot
Optional integer clinical scoring system
scoringSystem = TRUE converts penalized log-odds
coefficients into rounded integer points
(scoringMethod = "max_scaled" by default;
"beta10", "schneeweiss" [smallest-contribution
units], or "compare" are also available). Continuous
predictors are binarized at their sample median (or manual cutpoints via
scoreCutMethod = "manual").
res_score <- lassologistic(
data = df,
outcome = "cardiac_event",
outcomeLevel = "Yes",
explanatory = c("age", "sex", "diabetes", "hypertension",
"smoking", "cholesterol", "troponin", "creatinine"),
penalty = "lasso",
lambda = "lambda.1se",
random_seed = 42,
scoringSystem = TRUE,
scoringMethod = "compare"
)
res_score$scoringTable$asDF
#> variable oddsRatio criterion direction points_beta10
#> 1 age 1.865434 > 66 Positive (+) 6
#> 2 sexMale 1.428927 present Positive (+) 4
#> 3 diabetesYes 1.484112 present Positive (+) 4
#> 4 hypertensionYes 1.125105 present Positive (+) 1
#> 5 cholesterol 1.152221 > 219 Positive (+) 1
#> points_smallest points_maxscaled points
#> 1 5 10 10
#> 2 3 6 6
#> 3 3 6 6
#> 4 1 2 2
#> 5 1 2 2
res_score$methodComparison$asDF
#> method auc accuracy info_loss
#> "beta10" Beta10 0.6831145 0.56375 4.130915
#> "smallest" Smallest-unit 0.6831809 0.58625 4.121598
#> "maxscaled" Max-scaled 0.6831809 0.58625 4.121598
#> "full" Full LASSO (L1) model (continuous) 0.7125493 NA 0.000000
#> reference
#> "beta10" Mehta et al. 2016
#> "smallest" Sullivan-type (Sullivan et al. 2004), B = smallest contribution
#> "maxscaled" beta / max|beta| x maximum points
#> "full" Reference (no rounding)Key statistical and clinical cautions
-
Apparent vs. internal vs. external validation:
Cross-validation chooses the penalty
;
it does not make the apparent training AUC in
performancean external validation estimate. EnablebootstrapValidation = TRUEto estimate optimism, note that internal correction can still leave residual optimism when events per variable are limited, and validate the locked model externally before clinical use. - Scoring-system performance is apparent: Point conversion and median binarization discard information and are evaluated on the development sample; a point score requires its own external validation and calibration check.
-
Collinearity and variable selection: When
predictors are strongly correlated, LASSO may select one predictor
arbitrarily over another — making individual variable selection unstable
even when overall risk predictions remain stable. Consider Elastic Net
(
penalty = "elastic", ) or Ridge (penalty = "ridge") when correlated predictors should share weight. -
Independent patients only: The analysis assumes
independent rows. Supply
patientIDto check for repeated patient IDs, and prepare one row per patient before fitting. Clustered or repeated-measures data require a method designed for that sampling structure. -
Clinical utility: After validating discrimination
and calibration, assess net clinical utility across decision thresholds
with Decision Curve
Analysis (
decisioncurve()).