normModelCoeffs: Normalize Model Coefficients

View source: R/global.visu.R

normModelCoeffsR Documentation

Normalize Model Coefficients

Description

This function normalizes the model coefficients to a common scale. It is designed to handle different types of models and normalizes their coefficients for comparison purposes. The function also offers the ability to sort the features based on their importance or discriminatory power relative to the target variable.

Usage

normModelCoeffs(mod, X, y, sort.features = FALSE, sort.ind = NULL)

Arguments

mod

A model object that includes the attribute 'coeffs_' (the model coefficients). The model should also include an associated 'language' attribute specifying the type of model (e.g., 'bin', 'glmnet', 'svm').

X

A matrix or data frame of feature values used in the model.

y

A vector of true labels or target values corresponding to 'X'.

sort.features

A logical value indicating whether to sort the features based on their importance in relation to the target variable (default is 'FALSE').

sort.ind

A vector of indices for sorting the features. If 'NULL', the function will determine the sorting based on feature discriminance (default is 'NULL').

Details

The function normalizes the coefficients of a model based on the type of model. It handles models such as logistic regression ('logreg'), SVM ('svm'), GLM ('glmnet'), and others. If 'sort.features' is set to 'TRUE', the features will be sorted based on their discriminatory power, as calculated by a feature selection method (e.g., filtering based on statistical significance).

The normalized coefficients are scaled to lie between -1 and 1, which allows for a fair comparison of feature importance across different models.

Value

A numeric vector containing the normalized coefficients of the model, or 'NULL' if the model does not have valid coefficients.

Author(s)

Edi Prifti (IRD)

Examples

# Example usage for a logistic regression model
model <- train(logistic_regression_model)  # Assume this is a pre-trained model
X <- data.frame(feature1 = rnorm(100), feature2 = rnorm(100))
y <- sample(c(1, -1), 100, replace = TRUE)

# Normalize the model coefficients
normalized_coeffs <- normModelCoeffs(model, X, y)


predomics/predomicspkg documentation built on Dec. 11, 2024, 11:06 a.m.