Title: | Recursive Gradient Scanning Algorithm |
---|---|
Description: | Provides a recursive gradient scanning algorithm for discretizing continuous variables in Logistic and Cox regression models. This algorithm is especially effective in identifying optimal cut-points for variables with U-shaped relationships to 'lnOR' (the natural logarithm of the odds ratio) or 'lnHR' (the natural logarithm of the hazard ratio), thereby enhancing model fit, interpretability, and predictive power. By iteratively scanning and calculating gradient changes, the method accurately pinpoints critical cut-points within nonlinear relationships, transforming continuous variables into categorical ones. This approach improves risk classification and regression analysis performance, increasing interpretability and practical relevance in clinical and risk management settings. |
Authors: | Shuo Yang [aut, cre], Yi Fei [aut], Jinxin Zhang [ths] |
Maintainer: | Shuo Yang <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0 |
Built: | 2024-12-20 05:56:06 UTC |
Source: | https://github.com/cran/RGS |
Evaluate model with cutoffs Evaluates the model by creating exposure variables based on the cutoffs and fitting a Cox model.
evaluate_model_cox(my_data, cutoffs, formula)
evaluate_model_cox(my_data, cutoffs, formula)
my_data |
A dataframe containing the data. |
cutoffs |
A list of dataframes containing the cutoffs for each variable. |
formula |
An object of class "formula" describing the model structure. |
A dataframe summarizing the model evaluation metrics.
This function evaluates the logistic regression model by creating exposure variables based on the cutoffs and fitting the model.
evaluate_model_logistic(my_data, cutoffs, formula)
evaluate_model_logistic(my_data, cutoffs, formula)
my_data |
A dataframe containing the data. |
cutoffs |
A list of dataframes containing the cutoffs for each variable. |
formula |
An object of class "formula" describing the model structure. |
A dataframe summarizing the model evaluation metrics.
Find best combination of cutoffs Searches for the best combination of cutoffs that minimizes the Akaike Information Criterion (AIC).
find_best_combination_cox(my_data, cutoffs_list, formula)
find_best_combination_cox(my_data, cutoffs_list, formula)
my_data |
A dataframe containing the data. |
cutoffs_list |
A list of dataframes containing the cutoffs for each variable. |
formula |
An object of class "formula" describing the model structure. |
A dataframe containing the optimal cutoff values and the AIC value.
This function searches for the best combination of cutoffs that minimizes the Akaike Information Criterion (AIC).
find_best_combination_logistic(my_data, cutoffs_list, formula)
find_best_combination_logistic(my_data, cutoffs_list, formula)
my_data |
A dataframe containing the data. |
cutoffs_list |
A list of dataframes containing the cutoffs for each variable. |
formula |
An object of class "formula" describing the model structure. |
A dataframe containing the optimal cutoff values and the AIC value.
Find symmetric cutoffs This function finds symmetric cutoff points for a specified variable using Cox regression.
find_cutoffs_cox(my_data, variable_name)
find_cutoffs_cox(my_data, variable_name)
my_data |
A dataframe containing the data. |
variable_name |
A character string specifying the name of the variable for which to find cutoffs. |
A dataframe containing the symmetric cutoffs and their corresponding predicted log hazard ratios.
This function finds symmetric cutoff points for a specified predictor variable using logistic regression.
find_cutoffs_logistic(my_data, variable)
find_cutoffs_logistic(my_data, variable)
my_data |
A dataframe containing the data. |
variable |
A character string specifying the name of the predictor variable for which to find cutoffs. |
A dataframe containing the symmetric cutoffs and their corresponding predicted log odds ratios.
Main function for cox regression analysis Performs regression analysis to identify optimal cutoffs and evaluate the model. Users are required to create and set the datadist option globally before using this function.
rgs_for_cox(my_data, u_variables, covariates)
rgs_for_cox(my_data, u_variables, covariates)
my_data |
A dataframe containing the data. |
u_variables |
A character vector specifying the names of the U-shaped variables. |
covariates |
A character vector specifying the names of the covariates. |
A dataframe containing the best combination of cutoffs and associated AIC value.
library(rms) data_path <- system.file("extdata", "cox_data.csv", package = "RGS") my_data <- read.csv(data_path) # Define variables u_variables <- c("u1", "u2") covariates <- c("l1", "c1") # create and set the datadist option globally dd <- datadist(my_data) options(datadist = "dd") rgs_for_cox(my_data, u_variables, covariates)
library(rms) data_path <- system.file("extdata", "cox_data.csv", package = "RGS") my_data <- read.csv(data_path) # Define variables u_variables <- c("u1", "u2") covariates <- c("l1", "c1") # create and set the datadist option globally dd <- datadist(my_data) options(datadist = "dd") rgs_for_cox(my_data, u_variables, covariates)
This function performs logistic regression analysis to identify optimal cutoffs and evaluate the model. Users are required to create and set the datadist option globally before using this function.
rgs_for_logistic(my_data, u_variables, covariates)
rgs_for_logistic(my_data, u_variables, covariates)
my_data |
A dataframe containing the data. |
u_variables |
A character vector specifying the names of the U-shaped variables. |
covariates |
A character vector specifying the names of the covariates. |
A dataframe containing the best combination of cutoffs and associated AIC value.
library(rms) data_path <- system.file("extdata", "logistic_data.csv", package = "RGS") my_data <- read.csv(data_path) # Define variables u_variables <- c("u1", "u2") covariates <- c("l1", "c1") # create and set the datadist option globally dd <- datadist(my_data) options(datadist = "dd") rgs_for_logistic(my_data, u_variables, covariates)
library(rms) data_path <- system.file("extdata", "logistic_data.csv", package = "RGS") my_data <- read.csv(data_path) # Define variables u_variables <- c("u1", "u2") covariates <- c("l1", "c1") # create and set the datadist option globally dd <- datadist(my_data) options(datadist = "dd") rgs_for_logistic(my_data, u_variables, covariates)
Test U-shape relationship This function checks for a U-shaped relationship between survival time and a set of variables. Users are required to create and set the datadist option globally before using this function.
test_ushape_cox(my_data, variables)
test_ushape_cox(my_data, variables)
my_data |
A dataframe containing the data with survival times and event indicators. |
variables |
A character vector specifying the names of the variables to be tested. |
No return value, produces a plot as a side effect.
library(rms) data_path <- system.file("extdata", "cox_data.csv", package = "RGS") my_data <- read.csv(data_path) # create and set the datadist option globally dd <- datadist(my_data) options(datadist = "dd") test_ushape_cox(my_data, c("u1", "u2"))
library(rms) data_path <- system.file("extdata", "cox_data.csv", package = "RGS") my_data <- read.csv(data_path) # create and set the datadist option globally dd <- datadist(my_data) options(datadist = "dd") test_ushape_cox(my_data, c("u1", "u2"))
This function plots the estimated relationship between the response variable and a set of predictor variables to identify potential U-shaped patterns. Users are required to create and set the datadist option globally before using this function.
test_ushape_logistic(my_data, variables)
test_ushape_logistic(my_data, variables)
my_data |
A dataframe containing the data with response and predictor variables. |
variables |
A character vector specifying the names of the predictor variables to be tested. |
No return value, produces a plot as a side effect.
library(rms) data_path <- system.file("extdata", "logistic_data.csv", package = "RGS") my_data <- read.csv(data_path) # create and set the datadist option globally dd <- datadist(my_data) options(datadist = "dd") test_ushape_logistic(my_data, c("u1", "u2"))
library(rms) data_path <- system.file("extdata", "logistic_data.csv", package = "RGS") my_data <- read.csv(data_path) # create and set the datadist option globally dd <- datadist(my_data) options(datadist = "dd") test_ushape_logistic(my_data, c("u1", "u2"))