Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch for vignettes proposed by FM #300

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions R/brier_score.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#' Test

#' Re-used documentation for Brier Score components
#'
Expand Down
35 changes: 35 additions & 0 deletions design/examples/mCRCpub/00- Load.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#' ####################################################
#'
#' 2stgTGIOS
#' Loading the required R libraries
#'
#' Q1-2022
#' Francois Mercier
#'
#' ####################################################


#' if (!require("remotes")) {
#' install.packages("remotes")
#' }
#' remotes::install_github("genentech/jmpost")
#' install.packages("ghibli")

#' General purpose
#' =================
library(tidyverse)
library(tidyselect)
library(ghibli)

#' Data import/export
#' =================
library(haven)

#' Survival
#' =================
library(survival)
library(survminer)

#' Joint models
#' =================
library(jmpost)
101 changes: 101 additions & 0 deletions design/examples/mCRCpub/01- ImportHORIZON.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#' ####################################################
#'
#' Data preparation
#' HORIZONIII study (from PDS)
#'
#' Q3-2024
#' Francois Mercier
#'
#' ####################################################


#' sessionInfo()

#' ----------------------------------
#' Structure analysis data set:
#' ----------------------------------
#' For time to event sub-model (event.df):
#' ***************************
#' SUBJID (chr)
#' STUDY (chr)
#' ATRT (chr)
#'
#' EVENTYR (num) - Time to event (in years)
#' EVENTFL (0/1) - Flag =1 if the ind died, 0 if censored
#'
#' For longi (TGI) sub-model (biom.df):
#' ***************************
#' SUBJID (chr)
#' STUDY (chr)
#' ATRT (chr)
#'
#' BIOMVAL (num) - Biomarker (here, SLD in mm) value
#' BIOMYR (num) - Biomarker measurement time (in years)
#' ----------------------------------


#' ===============================================
#' Import and Select
#' ===============================================================

#' Event data frame
#' -----------------
subj<-haven::read_sas("./design/examples/mCRCpub/data/HORIZONIII/rdpsubj.sas7bdat")
rcist<-haven::read_sas("./design/examples/mCRCpub/data/HORIZONIII/rdprcist.sas7bdat")

#' Only keep patients in PerProtocol set (PP_SET==1)
#' and exposed to BEV for at least 3 weeks (i.e. at least 1st TA visit)
subj0<-subj |>
filter(PP_SET==1, !is.na(BEV_SDY), !is.na(BEV_EDY), BEV_EDY>3*7) |>
mutate(SUBJID=as.character(RANDCODE)) |>
select(SUBJID, LDH1_5)
#' length(unique(subj0$SUBJID))
#' 645

event.df0<-rcist |>
mutate(SUBJID=as.character(RANDCODE)) |>
filter(SUBJID %in% subj0$SUBJID) |>
group_by(SUBJID) %>% slice(1) %>% ungroup() |>
mutate(EVENTYR=OSTIM/365.25, EVENTFL=ifelse(DEATFLAG==1, 0, 1),
ATRT="FOLFOX alone", STUDY="2") |>
select(SUBJID, STUDY, ATRT, EVENTYR, EVENTFL)

UID.event0<-unique(event.df0$SUBJID)
#' length(UID.event0)
#' 645

#' Biomarker (SLD) data frame
#' -----------------
#' - remove rows where SLD is NA
#' - remove rows where patients have PBLCNT=NA i.e. remove patient with at least one post-baseline TA
biom.df0<-rcist |>
filter(!is.na(PBLCNT), !is.na(STLDI)) |>
mutate(SUBJID=as.character(RANDCODE), STUDY="2", ATRT="FOLFOX alone",
BIOMVAL=ifelse(STLDI==0, 2.5, STLDI*10),
BIOMYR=ORDYTRT/365.25) |>
select(SUBJID, STUDY, ATRT, BIOMVAL, BIOMYR)

UID.biom0<-unique(biom.df0$SUBJID)
#' length(UID.biom0)
#' 660

#' Retain matching patients
#' -----------------

retainID<-intersect(UID.event0, UID.biom0)
#' 640

event.df<-event.df0 |> filter(SUBJID %in% retainID)
#' length(unique(event.df$SUBJID))
#' 640
#' saveRDS(event.df, file="./design/examples/mCRCpub/data/HORIZONIII/HorizOSads.rds")


biom.df<-biom.df0 |> filter(SUBJID %in% retainID)
#' length(unique(biom.df$SUBJID))
#' 640
#' saveRDS(biom.df, file="./design/examples/mCRCpub/data/HORIZONIII/HorizTGIads.rds")




96 changes: 96 additions & 0 deletions design/examples/mCRCpub/01- ImportPRIME.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#' ####################################################
#'
#' Data preparation
#' PRIME study (from PDS)
#'
#' Q3-2024
#' Francois Mercier
#'
#' ####################################################


#' sessionInfo()

#' ----------------------------------
#' Structure analysis data set:
#' ----------------------------------
#' For time to event sub-model (event.df):
#' ***************************
#' SUBJID (chr)
#' STUDY (chr)
#' ATRT (chr)
#'
#' EVENTYR (num) - Time to event (in years)
#' EVENTFL (0/1) - Flag =1 if the ind died, 0 if censored
#'
#' For longi (TGI) sub-model (biom.df):
#' ***************************
#' SUBJID (chr)
#' STUDY (chr)
#' ATRT (chr)
#'
#' BIOMVAL (num) - Biomarker (here, SLD in mm) value
#' BIOMYR (num) - Biomarker measurement time (in years)
#' ----------------------------------


#' ===============================================
#' Import and Select
#' ===============================================================

#' Event data frame
#' -----------------
kras<-haven::read_sas("./design/examples/mCRCpub/data/PRIME/biomark_pds2019.sas7bdat")
kras0<-kras |> select("SUBJID", "BMMTR1")

adsl<-haven::read_sas("./design/examples/mCRCpub/data/PRIME/adsl_pds2019.sas7bdat")
event.df0<-adsl |>
left_join(kras0, by="SUBJID") |>
filter(BMMTR1=="Wild-type") |>
mutate(STUDY="1", EVENTYR=DTHDY/365.25, EVENTFL=DTH) |>
select("SUBJID", "STUDY", "ATRT", "EVENTYR", "EVENTFL")

UID.event0<-unique(event.df0$SUBJID)
#' length(UID.event0)
#' 514


#' Biomarker (SLD) data frame
#' -----------------
adtr<-haven::read_sas("./design/examples/mCRCpub/data/PRIME/adls_pds2019.sas7bdat")
biom.df0<-adtr |>
filter(LSCAT=="Target lesion", !is.na(LSSLD)) |>
mutate(STUDY="1", BIOMYR=VISITDY/365.25, BIOMVAL=LSSLD) |>
group_by(SUBJID, VISITDY) |> slice(1) |> ungroup() |>
select("SUBJID", "BIOMYR", "BIOMVAL")

UID.biom0<-unique(biom.df0$SUBJID)
#' length(UID.biom0)
#' 488


#' Retain matching patients
#' -----------------
retainID<-intersect(UID.event0, UID.biom0)
#' 263

event.df<-event.df0 |> filter(SUBJID %in% retainID)
#' length(unique(event.df$SUBJID))
#' 263
#' saveRDS(event.df, file="./design/examples/mCRCpub/data/PRIME/PRIMEOSads.rds")

desn0<-event.df0 |>
filter(SUBJID %in% retainID) |>
select(SUBJID, STUDY, ATRT)

biom.df<-biom.df0 |>
filter(SUBJID %in% retainID) |>
left_join(desn0, by="SUBJID")
#' length(unique(biom.df$SUBJID))
#' 263
#' saveRDS(biom.df, file="./design/examples/mCRCpub/data/PRIME/PRIMETGIads.rds")





65 changes: 65 additions & 0 deletions design/examples/mCRCpub/02- DescHORIZON.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#' ####################################################
#'
#' Descriptive plots
#' HORIZONIII study (from PDS)
#'
#' Q3-2024
#' Francois Mercier
#'
#' ####################################################


#' sessionInfo()

#' ===============================================
#' Visualize SLD
#' ===============================================

#' biom.df<-readRDS("./design/examples/mCRCpub/data/HORIZONIII/HorizTGIads.rds")
#' summary(biom.df)

ybreaks<-c(3, 30, 100, 300)
g0<-ggplot(biom.df, aes(x=BIOMYR, y=BIOMVAL))+
geom_line(aes(group=SUBJID), colour="grey", alpha=0.2)+
geom_point(colour="orange4", alpha=0.6, size=0.9)+
scale_x_continuous("Year", breaks=0.5*(0:5))+
scale_y_continuous("SLD (mm)", breaks=ybreaks)+
theme_minimal()+
theme(panel.grid.minor=element_blank())
g0

set.seed(130)
retainIDsub<-sample(retainID, size=60)

g0sub<-biom.df |> filter(SUBJID %in% retainIDsub) |>
ggplot(aes(x=BIOMYR, y=BIOMVAL))+
geom_line(aes(group=SUBJID), colour="grey", alpha=0.2)+
geom_point(colour="orange4", alpha=0.6, size=0.9)+
facet_wrap(~as.factor(SUBJID))+
scale_x_continuous("Year", breaks=0.5*(0:5))+
scale_y_continuous("SLD (mm)", breaks=ybreaks)+
theme_minimal()+
theme(panel.grid.minor=element_blank())
g0sub


#' ===============================================
#' Visualize OS
#' ===============================================

#' event.df<-readRDS("./design/examples/mCRCpub/data/HORIZONIII/HorizOSads.rds")
#' summary(event.df)

cox<-coxph(Surv(EVENTYR, EVENTFL)~1, data=event.df)
summary(cox)

os.kmest<-survfit(Surv(EVENTYR, EVENTFL)~1, data=event.df)
mycols<-c(rev(ghibli::ghibli_palettes$YesterdayMedium)[c(2,4)])
g1<-survminer::ggsurvplot(os.kmest, data=event.df,
risk.table=T, break.x.by=0.5, legend.title="",
xlab="Time (year)", ylab="Overall survival",
risk.table.fontsize=4, legend=c(0.8, 0.8), palette = mycols)
g1



56 changes: 56 additions & 0 deletions design/examples/mCRCpub/02- DescPRIME.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#' ####################################################
#'
#' Descriptive plots
#' PRIME study (from PDS)
#'
#' Q3-2024
#' Francois Mercier
#'
#' ####################################################


#' sessionInfo()

#' ===============================================
#' Visualize SLD
#' ===============================================

#' biom.df<-readRDS("./design/examples/mCRCpub/data/PRIME/PRIMETGIads.rds")
#' summary(biom.df)

#' Display SLD spaghetti
ybreaks<-c(3, 30, 100, 300)
mycols<-c(rev(ghibli::ghibli_palettes$YesterdayMedium)[c(2,4)])
g0<-ggplot(data=biom.df, aes(x=BIOMYR, y=BIOMVAL))+
geom_point(colour="grey33", alpha=0.3, size=0.9)+
geom_line(aes(group=SUBJID, colour=as.factor(ATRT)), alpha=0.6)+
facet_wrap(~ATRT)+
scale_x_continuous("Year", breaks=0.5*(0:5))+
scale_y_continuous("SLD (mm)", breaks=ybreaks)+
scale_colour_manual(values=mycols, guide="none")+
theme_minimal()+
theme(panel.grid.minor=element_blank())
g0

#' ===============================================
#' Visualize OS
#' ===============================================

#' event.df<-readRDS("./design/examples/mCRCpub/data/PRIME/PRIMEOSads.rds")
#' summary(event.df)

cox<-coxph(Surv(EVENTYR, EVENTFL)~ATRT, data=event.df)
summary(cox)

os.kmest<-survfit(Surv(EVENTYR, EVENTFL)~ATRT, data=event.df)

#' Display OS KM
g1<-survminer::ggsurvplot(os.kmest,
data=event.df, risk.table=T, break.x.by=.5, legend.title="",
xlab="Year", ylab="Overall survival", palette = mycols,
risk.table.fontsize=4, legend=c(0.8, 0.8))
g1




Loading
Loading