Learn R Programming

riskscores

Risk scores are sparse linear models that map an integer linear combination of covariates to the probability of an outcome occurring. Unlike regression models, risk score models consist of integer coefficients for often dichotomous variables. This allows risk score predictions to be easily computed by adding or subtracting a few small numbers.

Risk scores developed heuristically by altering logistic regression models have decreased performance, as there is a fundamental trade-off between the model’s simplicity and its predictive accuracy. In contrast, this package presents an optimization approach to learning risk scores, where the constraints for sparsity and integer coefficients are integrated into the model-fitting process, rather than implemented afterward.

Installation

You can install the development version of riskscores from GitHub with:

# install.packages("devtools")
devtools::install_github("hjeglinton/riskscores", build_vignettes = TRUE)

Example

We’ll fit a risk score model to predict breast cancer from biopsy data. More details can be found in the package’s vignette.

library(riskscores)

# Prepare data
y <- breastcancer[,1]
X <- as.matrix(breastcancer[,-1])

# Fit risk score model 
mod <- risk_mod(X, y, lambda = 0.0392)

The integer risk score model can be viewed by calling mod$model_card. An individual’s risk score can be calculated by multiplying each covariate response by its respective number of points and then adding all points together. In our example below, a patient with a ClumpThickness value of 5, a BareNuclei value of 1, and a BlandChromatin value of 3 would receive a score of $9(5) + 7(1) + 8(3) = 76$.

Points
ClumpThickness9
BareNuclei7
BlandChromatin8

Each score can then be mapped to a risk probability. The mod$score_map dataframe maps an integer range of scores to their associated risk. We can see that a patient who received a score of 120 would have a 78.86% risk of their tissue sample being malignant.

ScoreRisk
300.0012
600.0176
900.2052
1200.7886
1500.9818
1800.9987
2100.9999
2401.0000

Copy Link

Version

Install

install.packages('riskscores')

Monthly Downloads

167

Version

1.2.3

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Hannah Eglinton

Last Published

July 28th, 2025

Functions in riskscores (1.2.3)

risk_mod_random_start

Run risk model with random start
stratify_folds

Generate Stratified Fold IDs
plot.cv_risk_mod

Plot Risk Score Cross-Validation Results
coef.risk_mod

Extract Model Coefficients
get_metrics_internal

Get Model Metrics for a Single Threshold
%>%

Pipe operator
clip_exp_vals

Clip Values
get_metrics

Get Model Metrics
cv_risk_mod

Run Cross-Validation to Tune Lambda0
get_risk

Calculate Risk Probability from Score
get_score

Calculate Score from Risk Probability
plot_deviance.cv_risk_mod

Plot Risk Score Cross-Validation Results
summary.risk_mod

Summarize Risk Model Fit
risk_mod

Fit an Integer Risk Score Model
randomized_rounding

Randomly round the initialized coefficients before coordinate descent
plot.risk_mod

Plot Risk Score Model Curve
breastcancer

Breast tissue biopsy data
plot_accuracy.cv_risk_mod

Plot Risk Score Cross-Validation Results
predict.risk_mod

Predict Method for Risk Model Fits