-
0
Duplication
-
7
Churn
-
612
Lines
-
530
Lines of Code
# This file is automatically generated, you probably don't want to edit this
lassocoxOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"lassocoxOptions",
inherit = jmvcore::Options,
public = list(
initialize = function(
elapsedtime = NULL,
outcome = NULL,
outcomeLevel = NULL,
explanatory = NULL,
lambda = "lambda.1se",
nfolds = 10,
standardize = TRUE,
cv_plot = TRUE,
coef_plot = TRUE,
survival_plot = TRUE,
showExplanations = FALSE,
showMethodologyNotes = FALSE,
includeClinicalGuidance = FALSE,
showVariableImportance = FALSE,
showModelComparison = FALSE, ...) {
super$initialize(
package="ClinicoPath",
name="lassocox",
requiresData=TRUE,
...)
private$..elapsedtime <- jmvcore::OptionVariable$new(
"elapsedtime",
elapsedtime,
suggested=list(
"continuous"),
permitted=list(
"numeric"))
private$..outcome <- jmvcore::OptionVariable$new(
"outcome",
outcome,
suggested=list(
"ordinal",
"nominal",
"continuous"),
permitted=list(
"factor",
"numeric"))
private$..outcomeLevel <- jmvcore::OptionLevel$new(
"outcomeLevel",
outcomeLevel,
variable="(outcome)")
private$..explanatory <- jmvcore::OptionVariables$new(
"explanatory",
explanatory,
suggested=list(
"nominal",
"ordinal",
"continuous"),
permitted=list(
"factor",
"numeric"))
private$..lambda <- jmvcore::OptionList$new(
"lambda",
lambda,
options=list(
"lambda.min",
"lambda.1se"),
default="lambda.1se")
private$..nfolds <- jmvcore::OptionInteger$new(
"nfolds",
nfolds,
default=10,
min=3)
private$..standardize <- jmvcore::OptionBool$new(
"standardize",
standardize,
default=TRUE)
private$..cv_plot <- jmvcore::OptionBool$new(
"cv_plot",
cv_plot,
default=TRUE)
private$..coef_plot <- jmvcore::OptionBool$new(
"coef_plot",
coef_plot,
default=TRUE)
private$..survival_plot <- jmvcore::OptionBool$new(
"survival_plot",
survival_plot,
default=TRUE)
private$..riskScore <- jmvcore::OptionOutput$new(
"riskScore")
private$..showExplanations <- jmvcore::OptionBool$new(
"showExplanations",
showExplanations,
default=FALSE)
private$..showMethodologyNotes <- jmvcore::OptionBool$new(
"showMethodologyNotes",
showMethodologyNotes,
default=FALSE)
private$..includeClinicalGuidance <- jmvcore::OptionBool$new(
"includeClinicalGuidance",
includeClinicalGuidance,
default=FALSE)
private$..showVariableImportance <- jmvcore::OptionBool$new(
"showVariableImportance",
showVariableImportance,
default=FALSE)
private$..showModelComparison <- jmvcore::OptionBool$new(
"showModelComparison",
showModelComparison,
default=FALSE)
self$.addOption(private$..elapsedtime)
self$.addOption(private$..outcome)
self$.addOption(private$..outcomeLevel)
self$.addOption(private$..explanatory)
self$.addOption(private$..lambda)
self$.addOption(private$..nfolds)
self$.addOption(private$..standardize)
self$.addOption(private$..cv_plot)
self$.addOption(private$..coef_plot)
self$.addOption(private$..survival_plot)
self$.addOption(private$..riskScore)
self$.addOption(private$..showExplanations)
self$.addOption(private$..showMethodologyNotes)
self$.addOption(private$..includeClinicalGuidance)
self$.addOption(private$..showVariableImportance)
self$.addOption(private$..showModelComparison)
}),
active = list(
elapsedtime = function() private$..elapsedtime$value,
outcome = function() private$..outcome$value,
outcomeLevel = function() private$..outcomeLevel$value,
explanatory = function() private$..explanatory$value,
lambda = function() private$..lambda$value,
nfolds = function() private$..nfolds$value,
standardize = function() private$..standardize$value,
cv_plot = function() private$..cv_plot$value,
coef_plot = function() private$..coef_plot$value,
survival_plot = function() private$..survival_plot$value,
riskScore = function() private$..riskScore$value,
showExplanations = function() private$..showExplanations$value,
showMethodologyNotes = function() private$..showMethodologyNotes$value,
includeClinicalGuidance = function() private$..includeClinicalGuidance$value,
showVariableImportance = function() private$..showVariableImportance$value,
showModelComparison = function() private$..showModelComparison$value),
private = list(
..elapsedtime = NA,
..outcome = NA,
..outcomeLevel = NA,
..explanatory = NA,
..lambda = NA,
..nfolds = NA,
..standardize = NA,
..cv_plot = NA,
..coef_plot = NA,
..survival_plot = NA,
..riskScore = NA,
..showExplanations = NA,
..showMethodologyNotes = NA,
..includeClinicalGuidance = NA,
..showVariableImportance = NA,
..showModelComparison = NA)
)
lassocoxResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"lassocoxResults",
inherit = jmvcore::Group,
active = list(
todo = function() private$.items[["todo"]],
modelSummary = function() private$.items[["modelSummary"]],
coefficients = function() private$.items[["coefficients"]],
performance = function() private$.items[["performance"]],
cv_plot = function() private$.items[["cv_plot"]],
coef_plot = function() private$.items[["coef_plot"]],
survival_plot = function() private$.items[["survival_plot"]],
riskScore = function() private$.items[["riskScore"]],
lassoExplanation = function() private$.items[["lassoExplanation"]],
methodologyNotes = function() private$.items[["methodologyNotes"]],
clinicalGuidance = function() private$.items[["clinicalGuidance"]],
variableImportance = function() private$.items[["variableImportance"]],
modelComparison = function() private$.items[["modelComparison"]],
regularizationPathExplanation = function() private$.items[["regularizationPathExplanation"]],
crossValidationExplanation = function() private$.items[["crossValidationExplanation"]],
riskScoreExplanation = function() private$.items[["riskScoreExplanation"]]),
private = list(),
public=list(
initialize=function(options) {
super$initialize(
options=options,
name="",
title="Lasso-Cox Regression",
refs=list(
"ClinicoPathJamoviModule",
"glmnet",
"survival",
"survminer"))
self$add(jmvcore::Html$new(
options=options,
name="todo",
title="To Do",
clearWith=list(
"outcome",
"outcomeLevel",
"elapsedtime",
"explanatory")))
self$add(jmvcore::Table$new(
options=options,
name="modelSummary",
title="Model Summary",
rows=0,
columns=list(
list(
`name`="statistic",
`title`="",
`type`="text"),
list(
`name`="value",
`title`="Value",
`type`="number")),
clearWith=list(
"outcome",
"outcomeLevel",
"elapsedtime",
"explanatory",
"lambda",
"nfolds",
"standardize")))
self$add(jmvcore::Table$new(
options=options,
name="coefficients",
title="Selected Variables",
rows=0,
columns=list(
list(
`name`="variable",
`title`="Variable",
`type`="text"),
list(
`name`="coefficient",
`title`="Coefficient",
`type`="number"),
list(
`name`="hazardRatio",
`title`="Hazard Ratio",
`type`="number"),
list(
`name`="importance",
`title`="Importance",
`type`="number")),
clearWith=list(
"outcome",
"outcomeLevel",
"elapsedtime",
"explanatory",
"lambda",
"nfolds",
"standardize")))
self$add(jmvcore::Table$new(
options=options,
name="performance",
title="Model Performance",
rows=0,
columns=list(
list(
`name`="metric",
`title`="Metric",
`type`="text"),
list(
`name`="value",
`title`="Value",
`type`="text"),
list(
`name`="interpretation",
`title`="Interpretation",
`type`="text")),
clearWith=list(
"outcome",
"outcomeLevel",
"elapsedtime",
"explanatory",
"lambda",
"nfolds",
"standardize")))
self$add(jmvcore::Image$new(
options=options,
name="cv_plot",
title="Cross-validation Plot",
renderFun=".cvPlot",
width=600,
height=400,
requiresData=TRUE,
visible="(cv_plot)",
refs="glmnet",
clearWith=list(
"cv_plot",
"outcome",
"outcomeLevel",
"elapsedtime",
"explanatory",
"lambda",
"nfolds",
"standardize")))
self$add(jmvcore::Image$new(
options=options,
name="coef_plot",
title="Coefficient Plot",
renderFun=".coefPlot",
width=600,
height=400,
requiresData=TRUE,
visible="(coef_plot)",
refs="glmnet",
clearWith=list(
"coef_plot",
"outcome",
"outcomeLevel",
"elapsedtime",
"explanatory",
"lambda",
"nfolds",
"standardize")))
self$add(jmvcore::Image$new(
options=options,
name="survival_plot",
title="Risk Group Survival Plot",
renderFun=".survivalPlot",
width=600,
height=400,
requiresData=TRUE,
visible="(survival_plot)",
refs="survminer",
clearWith=list(
"survival_plot",
"outcome",
"outcomeLevel",
"elapsedtime",
"explanatory",
"lambda",
"nfolds",
"standardize")))
self$add(jmvcore::Output$new(
options=options,
name="riskScore",
title="Add Risk Score to Data",
varTitle="Calculated Risk Score from Lasso-Cox Regression",
varDescription="Risk Score Based on Lasso-Cox Model",
clearWith=list(
"outcome",
"outcomeLevel",
"elapsedtime",
"explanatory",
"lambda",
"nfolds",
"standardize")))
self$add(jmvcore::Html$new(
options=options,
name="lassoExplanation",
title="Understanding LASSO Cox Regression",
visible="(showExplanations)",
clearWith=list(
"showExplanations")))
self$add(jmvcore::Html$new(
options=options,
name="methodologyNotes",
title="LASSO Cox Methodology Notes",
visible="(showMethodologyNotes)",
clearWith=list(
"showMethodologyNotes")))
self$add(jmvcore::Html$new(
options=options,
name="clinicalGuidance",
title="Clinical Interpretation Guidance",
visible="(includeClinicalGuidance)",
clearWith=list(
"includeClinicalGuidance")))
self$add(jmvcore::Table$new(
options=options,
name="variableImportance",
title="Variable Importance Analysis",
visible="(showVariableImportance)",
rows=0,
columns=list(
list(
`name`="variable",
`title`="Variable",
`type`="text"),
list(
`name`="importance_score",
`title`="Importance Score",
`type`="number",
`format`="zto"),
list(
`name`="selection_frequency",
`title`="Selection Frequency",
`type`="number",
`format`="pc"),
list(
`name`="stability_rank",
`title`="Stability Rank",
`type`="integer")),
clearWith=list(
"showVariableImportance",
"outcome",
"outcomeLevel",
"elapsedtime",
"explanatory")))
self$add(jmvcore::Table$new(
options=options,
name="modelComparison",
title="LASSO vs Standard Cox Regression",
visible="(showModelComparison)",
rows=0,
columns=list(
list(
`name`="model_type",
`title`="Model Type",
`type`="text"),
list(
`name`="n_variables",
`title`="N Variables",
`type`="integer"),
list(
`name`="cindex",
`title`="C-index",
`type`="number",
`format`="zto"),
list(
`name`="aic",
`title`="AIC",
`type`="number",
`format`="zto"),
list(
`name`="log_likelihood",
`title`="Log-Likelihood",
`type`="number",
`format`="zto")),
clearWith=list(
"showModelComparison",
"outcome",
"outcomeLevel",
"elapsedtime",
"explanatory")))
self$add(jmvcore::Html$new(
options=options,
name="regularizationPathExplanation",
title="Understanding Regularization Path",
visible="(showExplanations && coef_plot)",
clearWith=list(
"showExplanations",
"coef_plot")))
self$add(jmvcore::Html$new(
options=options,
name="crossValidationExplanation",
title="Understanding Cross-Validation Plot",
visible="(showExplanations && cv_plot)",
clearWith=list(
"showExplanations",
"cv_plot")))
self$add(jmvcore::Html$new(
options=options,
name="riskScoreExplanation",
title="Understanding Risk Scores and Survival Curves",
visible="(showExplanations && survival_plot)",
clearWith=list(
"showExplanations",
"survival_plot")))}))
lassocoxBase <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"lassocoxBase",
inherit = jmvcore::Analysis,
public = list(
initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) {
super$initialize(
package = "ClinicoPath",
name = "lassocox",
version = c(0,0,3),
options = options,
results = lassocoxResults$new(options=options),
data = data,
datasetId = datasetId,
analysisId = analysisId,
revision = revision,
pause = NULL,
completeWhenFilled = FALSE,
requiresMissings = FALSE,
weightsSupport = 'none')
}))
#' Lasso-Cox Regression
#'
#' Performs Lasso-penalized Cox regression for variable selection in survival
#' analysis.
#'
#' @examples
#' \donttest{
#' # example will be added
#'}
#' @param data The data as a data frame.
#' @param elapsedtime The numeric variable representing follow-up time until
#' the event or last observation.
#' @param outcome The outcome variable. Typically indicates event status
#' (e.g., death, recurrence).
#' @param outcomeLevel The level of \code{outcome} considered as the event.
#' @param explanatory Variables to be considered for selection in the
#' Lasso-Cox regression.
#' @param lambda Method for selecting the optimal lambda parameter from
#' cross-validation.
#' @param nfolds Number of folds for cross-validation.
#' @param standardize Whether to standardize predictor variables before
#' fitting.
#' @param cv_plot Whether to show the cross-validation plot.
#' @param coef_plot Whether to show the coefficient path plot.
#' @param survival_plot Whether to show survival curves by risk groups.
#' @param showExplanations Display detailed explanations of LASSO Cox
#' regression methodology, including regularization concepts and
#' interpretation guidance.
#' @param showMethodologyNotes Show comprehensive technical notes about LASSO
#' regularization, cross-validation, and variable selection process.
#' @param includeClinicalGuidance Include guidance for clinical interpretation
#' of LASSO Cox regression results, risk scores, and variable selection
#' outcomes.
#' @param showVariableImportance Display analysis of variable importance
#' rankings and selection patterns across different lambda values.
#' @param showModelComparison Compare LASSO Cox results with standard Cox
#' regression to demonstrate the benefits of regularization and variable
#' selection.
#' @return A results object containing:
#' \tabular{llllll}{
#' \code{results$todo} \tab \tab \tab \tab \tab a html \cr
#' \code{results$modelSummary} \tab \tab \tab \tab \tab a table \cr
#' \code{results$coefficients} \tab \tab \tab \tab \tab a table \cr
#' \code{results$performance} \tab \tab \tab \tab \tab a table \cr
#' \code{results$cv_plot} \tab \tab \tab \tab \tab an image \cr
#' \code{results$coef_plot} \tab \tab \tab \tab \tab an image \cr
#' \code{results$survival_plot} \tab \tab \tab \tab \tab an image \cr
#' \code{results$riskScore} \tab \tab \tab \tab \tab an output \cr
#' \code{results$lassoExplanation} \tab \tab \tab \tab \tab a html \cr
#' \code{results$methodologyNotes} \tab \tab \tab \tab \tab a html \cr
#' \code{results$clinicalGuidance} \tab \tab \tab \tab \tab a html \cr
#' \code{results$variableImportance} \tab \tab \tab \tab \tab a table \cr
#' \code{results$modelComparison} \tab \tab \tab \tab \tab a table \cr
#' \code{results$regularizationPathExplanation} \tab \tab \tab \tab \tab a html \cr
#' \code{results$crossValidationExplanation} \tab \tab \tab \tab \tab a html \cr
#' \code{results$riskScoreExplanation} \tab \tab \tab \tab \tab a html \cr
#' }
#'
#' Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.frame}}. For example:
#'
#' \code{results$modelSummary$asDF}
#'
#' \code{as.data.frame(results$modelSummary)}
#'
#' @export
lassocox <- function(
data,
elapsedtime,
outcome,
outcomeLevel,
explanatory,
lambda = "lambda.1se",
nfolds = 10,
standardize = TRUE,
cv_plot = TRUE,
coef_plot = TRUE,
survival_plot = TRUE,
showExplanations = FALSE,
showMethodologyNotes = FALSE,
includeClinicalGuidance = FALSE,
showVariableImportance = FALSE,
showModelComparison = FALSE) {
if ( ! requireNamespace("jmvcore", quietly=TRUE))
stop("lassocox requires jmvcore to be installed (restart may be required)")
if ( ! missing(elapsedtime)) elapsedtime <- jmvcore::resolveQuo(jmvcore::enquo(elapsedtime))
if ( ! missing(outcome)) outcome <- jmvcore::resolveQuo(jmvcore::enquo(outcome))
if ( ! missing(explanatory)) explanatory <- jmvcore::resolveQuo(jmvcore::enquo(explanatory))
if (missing(data))
data <- jmvcore::marshalData(
parent.frame(),
`if`( ! missing(elapsedtime), elapsedtime, NULL),
`if`( ! missing(outcome), outcome, NULL),
`if`( ! missing(explanatory), explanatory, NULL))
options <- lassocoxOptions$new(
elapsedtime = elapsedtime,
outcome = outcome,
outcomeLevel = outcomeLevel,
explanatory = explanatory,
lambda = lambda,
nfolds = nfolds,
standardize = standardize,
cv_plot = cv_plot,
coef_plot = coef_plot,
survival_plot = survival_plot,
showExplanations = showExplanations,
showMethodologyNotes = showMethodologyNotes,
includeClinicalGuidance = includeClinicalGuidance,
showVariableImportance = showVariableImportance,
showModelComparison = showModelComparison)
analysis <- lassocoxClass$new(
options = options,
data = data)
analysis$run()
analysis$results
}