knitr::opts_chunk$set(echo = TRUE)

Instalation

if (!require("BiocManager")) {
    install.packages("BiocManager")
}
BiocManager::install("glmSparseNet")

Required Packages

library(futile.logger)
library(ggplot2)
library(glmSparseNet)
library(survival)

# Some general options for futile.logger the debugging package
flog.layout(layout.format("[~l] ~m"))
options("glmSparseNet.show_message" = FALSE)
# Setting ggplot2 default theme as minimal
theme_set(ggplot2::theme_minimal())

Prepare data

data("cancer", package = "survival")
xdata <- survival::ovarian[, c("age", "resid.ds")]
ydata <- data.frame(
    time = survival::ovarian$futime,
    status = survival::ovarian$fustat
)

Separate using age as co-variate

(group cutoff is median calculated relative risk)

resAge <- separate2GroupsCox(c(age = 1, 0), xdata, ydata)

Kaplan-Meier survival results

resAge$km

Plot

A individual is attributed to low-risk group if its calculated relative risk (using Cox Proportional model) is below or equal the median risk.

The opposite for the high-risk groups, populated with individuals above the median relative-risk.

resAge$plot

Separate using age as co-variate (group cutoff is 40% - 60%)

resAge4060 <-
    separate2GroupsCox(c(age = 1, 0),
        xdata,
        ydata,
        probs = c(.4, .6)
    )

Kaplan-Meier survival results

resAge4060$km

Plot

A individual is attributed to low-risk group if its calculated relative risk (using Cox Proportional model) is below the median risk.

The opposite for the high-risk groups, populated with individuals above the median relative-risk.

resAge4060$plot

Separate using age as co-variate (group cutoff is 60% - 40%)

This is a special case where you want to use a cutoff that includes some sample on both high and low risks groups.

resAge6040 <- separate2GroupsCox(
    chosenBetas = c(age = 1, 0),
    xdata,
    ydata,
    probs = c(.6, .4),
    stopWhenOverlap = FALSE
)

Kaplan-Meier survival results

cat("Kaplan-Meier results", "\n")
resAge6040$km

Plot

A individual is attributed to low-risk group if its calculated relative risk (using Cox Proportional model) is below the median risk.

The opposite for the high-risk groups, populated with individuals above the median relative-risk.

resAge6040$plot

Session Info

sessionInfo()


sysbiomed/glmSparseNet documentation built on Feb. 17, 2024, 1:38 p.m.