Title: | Construct Explainable Nomogram for a Machine Learning Model |
---|---|
Description: | Construct an explainable nomogram for a machine learning (ML) model to improve availability of an ML prediction model in addition to a computer application, particularly in a situation where a computer, a mobile phone, an internet connection, or the application accessibility are unreliable. This package enables a nomogram creation for any ML prediction models, which is conventionally limited to only a linear/logistic regression model. This nomogram may indicate the explainability value per feature, e.g., the Shapley additive explanation value, for each individual. However, this package only allows a nomogram creation for a model using categorical without or with single numerical predictors. Detailed methodologies and examples are documented in our vignette, available at <https://htmlpreview.github.io/?https://github.com/herdiantrisufriyana/rmlnomogram/blob/master/doc/ml_nomogram_exemplar.html>. |
Authors: | Herdiantri Sufriyana [aut, cre] , Emily Chia-Yu Su [aut] |
Maintainer: | Herdiantri Sufriyana <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.2 |
Built: | 2025-01-08 20:35:45 UTC |
Source: | CRAN |
This function constructs a nomogram for either binary or continuous outcomes based on provided sample features and outputs. It can also incorporate feature explainability values, such as SHAP values.
create_nomogram( sample_features, sample_output, feature_exp = NULL, threshold = 0.5, prob = FALSE, est = FALSE, verbose = FALSE )
create_nomogram( sample_features, sample_output, feature_exp = NULL, threshold = 0.5, prob = FALSE, est = FALSE, verbose = FALSE )
sample_features |
A data frame of feature values where each column represents a feature. The data frame must contain all possible combinations of feature values. There must be at least one categorical predictor and no more than one numerical predictor. Only factor and numeric data types are allowed. The column name 'output' is not allowed. Must not contain any NA values. |
sample_output |
A data frame with one column 'output' containing numeric values for either the predicted probabilities (for binary outcomes) or estimated values (for continuous outcomes). Must not contain any NA values. |
feature_exp |
Optional data frame containing feature explainability
values (e.g., SHAP values) with one column for each feature. The structure
must match |
threshold |
A numeric scalar between 0 and 1, used to define the threshold for classifying predicted probabilities into binary outcomes. A sample is predicted positive if the predicted probability is equal or greater than this threshold. |
prob |
A logical scalar indicating if the predicted probabilities should be shown in the nomogram. |
est |
A logical scalar indicating if the estimated values should be shown in the nomogram. |
verbose |
A logical scalar indicating whether to show a progress bar if it is required. |
A ggplot object representing the nomogram.
# Binary outcome (or class-wise multinomial outcome) ## 1 - Categorical predictors and binary outcome without probability data(nomogram_features) data(nomogram_outputs) create_nomogram(nomogram_features, nomogram_outputs) ## 2 - Categorical predictors and binary outcome with probability create_nomogram(nomogram_features, nomogram_outputs, prob = TRUE) data(nomogram_shaps) create_nomogram( nomogram_features, nomogram_outputs, nomogram_shaps , prob = TRUE ) ## 3 - Categorical and 1 numerical predictors and binary outcome with probability data(nomogram_features2) data(nomogram_outputs2) create_nomogram(nomogram_features2, nomogram_outputs2, prob = TRUE) data(nomogram_shaps2) create_nomogram( nomogram_features2, nomogram_outputs2, nomogram_shaps2 , prob = TRUE ) # Continuous outcome ## 4 - Categorical predictors and continuous outcome data(nomogram_features3) data(nomogram_outputs3) create_nomogram(nomogram_features3, nomogram_outputs3, est = TRUE) data(nomogram_shaps3) create_nomogram( nomogram_features3, nomogram_outputs3, nomogram_shaps3 , est = TRUE ) ## 5 - Categorical and 1 numerical predictors and continuous outcome data(nomogram_features4) data(nomogram_outputs4) create_nomogram(nomogram_features4, nomogram_outputs4, est = TRUE) data(nomogram_shaps4) create_nomogram( nomogram_features4, nomogram_outputs4, nomogram_shaps4 , est = TRUE )
# Binary outcome (or class-wise multinomial outcome) ## 1 - Categorical predictors and binary outcome without probability data(nomogram_features) data(nomogram_outputs) create_nomogram(nomogram_features, nomogram_outputs) ## 2 - Categorical predictors and binary outcome with probability create_nomogram(nomogram_features, nomogram_outputs, prob = TRUE) data(nomogram_shaps) create_nomogram( nomogram_features, nomogram_outputs, nomogram_shaps , prob = TRUE ) ## 3 - Categorical and 1 numerical predictors and binary outcome with probability data(nomogram_features2) data(nomogram_outputs2) create_nomogram(nomogram_features2, nomogram_outputs2, prob = TRUE) data(nomogram_shaps2) create_nomogram( nomogram_features2, nomogram_outputs2, nomogram_shaps2 , prob = TRUE ) # Continuous outcome ## 4 - Categorical predictors and continuous outcome data(nomogram_features3) data(nomogram_outputs3) create_nomogram(nomogram_features3, nomogram_outputs3, est = TRUE) data(nomogram_shaps3) create_nomogram( nomogram_features3, nomogram_outputs3, nomogram_shaps3 , est = TRUE ) ## 5 - Categorical and 1 numerical predictors and continuous outcome data(nomogram_features4) data(nomogram_outputs4) create_nomogram(nomogram_features4, nomogram_outputs4, est = TRUE) data(nomogram_shaps4) create_nomogram( nomogram_features4, nomogram_outputs4, nomogram_shaps4 , est = TRUE )
An example of a data frame for sample_features
argument in
create_nomogram
function, must only include all possible
combinations of feature values, where one column is available for each
feature.
nomogram_features
nomogram_features
A data frame with 16 rows and 4 columns:
A categorical predictor with values of 0 and 1.
A categorical predictor with values of 0 and 1.
A categorical predictor with values of 0 and 1.
A categorical predictor with values of 0 and 1.
Derived from mtcars
for examples in this package.
An example of a data frame for sample_features
argument in
create_nomogram
function, must only include all possible
combinations of feature values, where one column is available for each
feature.
nomogram_features2
nomogram_features2
A data frame with 80 rows and 4 columns:
.
A numerical predictor without decimal.
A categorical predictor with values of 0 and 1.
A categorical predictor with values of 0 and 1.
A categorical predictor with values of 0 and 1.
Derived from mtcars
for examples in this package.
An example of a data frame for sample_features
argument in
create_nomogram
function, must only include all possible
combinations of feature values, where one column is available for each
feature.
nomogram_features3
nomogram_features3
A data frame with 16 rows and 4 columns:
A categorical predictor with values of 0 and 1.
A categorical predictor with values of 0 and 1.
A categorical predictor with values of 0 and 1.
A categorical predictor with values of 0 and 1.
Derived from mtcars
for examples in this package.
An example of a data frame for sample_features
argument in
create_nomogram
function, must only include all possible
combinations of feature values, where one column is available for each
feature.
nomogram_features4
nomogram_features4
A data frame with 80 rows and 4 columns:
.
A numerical predictor without decimal.
A categorical predictor with values of 0 and 1.
A categorical predictor with values of 0 and 1.
A categorical predictor with values of 0 and 1.
Derived from mtcars
for examples in this package.
An example of a data frame for sample_output
argument in
create_nomogram
function, must only include the predicted
probabilities for binary outcome.
nomogram_outputs
nomogram_outputs
A data frame with 16 rows and 1 column:
A binary outcome with values from 0 to 1.
Generated by a caret randomforest model using categorical predictors for examples in this package.
An example of a data frame for sample_output
argument in
create_nomogram
function, must only include the predicted
probabilities for binary outcome.
nomogram_outputs2
nomogram_outputs2
A data frame with 80 rows and 1 column:
A binary outcome with values from 0 to 1.
Generated by a caret randomforest model using categorical and 1 numerical predictors for examples in this package.
An example of a data frame for sample_output
argument in
create_nomogram
function, must only include the estimated
values for numerical outcome.
nomogram_outputs3
nomogram_outputs3
A data frame with 16 rows and 1 column:
A numerical outcome.
Generated by a caret randomforest model using categorical predictors for examples in this package.
An example of a data frame for sample_output
argument in
create_nomogram
function, must only include the estimated
values for numerical outcome.
nomogram_outputs4
nomogram_outputs4
A data frame with 80 rows and 1 column:
A numerical outcome.
Generated by a caret randomforest model using categorical and 1 numerical predictors for examples in this package.
An example of a data frame for feature_exp
argument in
create_nomogram
function, must only include feature
explainability value per sample (i.e., SHAP value), where one column is
available for each feature.
nomogram_shaps
nomogram_shaps
A data frame with 16 rows and 4 columns:
A predictor with SHAP values.
A predictor with SHAP values.
A predictor with SHAP values.
A predictor with SHAP values.
Computed by iml from a caret randomforest model using categorical predictors for examples in this package.
An example of a data frame for feature_exp
argument in
create_nomogram
function, must only include feature
explainability value per sample (i.e., SHAP value), where one column is
available for each feature.
nomogram_shaps2
nomogram_shaps2
A data frame with 80 rows and 4 columns:
A predictor with SHAP values.
A predictor with SHAP values.
A predictor with SHAP values.
A predictor with SHAP values.
Computed by iml from a caret randomforest model using categorical and 1 numerical predictors for examples in this package.
An example of a data frame for feature_exp
argument in
create_nomogram
function, must only include feature
explainability value per sample (i.e., SHAP value), where one column is
available for each feature.
nomogram_shaps3
nomogram_shaps3
A data frame with 16 rows and 4 columns:
A predictor with SHAP values.
A predictor with SHAP values.
A predictor with SHAP values.
A predictor with SHAP values.
Computed by iml from a caret randomforest model using categorical predictors for examples in this package.
An example of a data frame for feature_exp
argument in
create_nomogram
function, must only include feature
explainability value per sample (i.e., SHAP value), where one column is
available for each feature.
nomogram_shaps4
nomogram_shaps4
A data frame with 80 rows and 4 columns:
A predictor with SHAP values.
A predictor with SHAP values.
A predictor with SHAP values.
A predictor with SHAP values.
Computed by iml from a caret randomforest model using categorical and 1 numerical predictors for examples in this package.