subscreencalc: (i) Calculation of the results for the subgroups

View source: R/subscreencalc.R

subscreencalcR Documentation

(i) Calculation of the results for the subgroups


This function systematically calculates the defined outcome for every combination of subgroups up to the given level (max_comb), i.e. the number of maximum combinations of subgroup defining factors. If, e.g., in a study sex, age group (<=60, >60), BMI group (<=25, >25) are of interest, subgroups of level 2 would be, e.g, male subjects with BMI>25 or young females, while subgroups of level 3 would be any combination of all three variables.


  treat = "trtp",
  subjectid = "subjid",
  factors = NULL,
  min_comb = 1,
  max_comb = 3,
  nkernel = 1,
  par_functions = "",
  verbose = TRUE,
  factorial = FALSE,
  use_complement = FALSE



dataframe with study data


name of the function for data analysis


vector containing the names of the endpoint variables in data


name of variable in data that contains the treatment identfier, defaults to trtp


name of variable in data that contains the subject identifier, defaults to subjid


vector containg the names of variables that define the subgroups, defaults to NULL. If set to NULL, all variables in data are used that are not included in subjectid, treat, and endpoints


minimum number of factor combination levels to define subgroups, defaults to 1


maximum number of factor combination levels to define subgruops, defaults to 3


number of kernels for parallelization (defaults to 1)


vector of names of functions used in eval_function to be exported to cluster (needed only if nkernel > 1)


switch on/off output of computational information


switch on/off calculation of factorial contexts


switch on/off calculation of complement subgroups


The evaluation function (eval_function) has to defined by the user. The result needs to be a vector of numerical values, e.g., outcome variable(s) and number of observations/subjects. The input of eval_function is a data frame with the same structure as the input data frame (data) used in the subsreencalc call. See example below. Potential errors occurring due to small subgroups should be caught and handled within eval_function. As the eval_function will be called with every subgroup it may happen that there is only one observation or only one treatment arm or only observations with missing data going into the eval_function. There should always be valid result vector be returned (NAs allowed) and no error causing program abort. For a better display the results may be cut-off to a reasonable range. For example: If my endpoint is a hazard ratio that is expected to be between 0.5 and 2 I would set all values smaller than 0.01 to 0.01 and values above 100 to 100.


an object of type SubScreenResult of the form list(sge=H, max_comb=max_comb, min_comb=min_comb, subjectid=subjectid, endpoints=endpoints, treat=treat, factors=factors, results_total=eval_function(cbind(F,T)))


# get the pbc data from the survival package
data(pbc, package="survival")
# generate categorical versions of some of the baseline covariates
pbc$ageg[!$age)]        <-
   ifelse(pbc$age[!$age)]          <= median(pbc$age,     na.rm=TRUE), "Low", "High")
   ifelse(pbc$albumin[!$albumin)]  <= median(pbc$albumin, na.rm=TRUE), "Low", "High")
pbc$phosg[!$alk.phos)]  <-
   ifelse(pbc$alk.phos[!$alk.phos)]<= median(pbc$alk.phos,na.rm=TRUE), "Low", "High")
pbc$astg[!$ast)]        <-
   ifelse(pbc$ast[!$ast)]          <= median(pbc$ast,     na.rm=TRUE), "Low", "High")
pbc$bilig[!$bili)]      <-
   ifelse(pbc$bili[!$bili)]        <= median(pbc$bili,    na.rm=TRUE), "Low", "High")
pbc$cholg[!$chol)]      <-
   ifelse(pbc$chol[!$chol)]        <= median(pbc$chol,    na.rm=TRUE), "Low", "High")
pbc$copperg[!$copper)]  <-
   ifelse(pbc$copper[!$copper)]    <= median(pbc$copper,  na.rm=TRUE), "Low", "High")
pbc$ageg[$age)]         <- "No Data"
pbc$albuming[$albumin)] <- "No Data"
pbc$phosg[$alk.phos)]   <- "No Data"
pbc$astg[$ast)]         <- "No Data"
pbc$bilig[$bili)]       <- "No Data"
pbc$cholg[$chol)]       <- "No Data"
pbc$copperg[$copper)]   <- "No Data"
#eliminate treatment NAs
pbcdat <- pbc[!$trt), ]
# PFS and OS endpoints
pbcdat$'event.pfs' <- sample(c(0,1),dim(pbcdat)[1],replace=TRUE)
pbcdat$'timepfs' <- sample(1:5000,dim(pbcdat)[1],replace=TRUE)
pbcdat$'event.os' <- pbcdat$event
pbcdat$'timeos' <- pbcdat$time
#variable importance for OS for the created categorical variables
#(higher is more important, also works for numeric variables)
varnames <- c('ageg', 'sex', 'bilig', 'cholg', 'astg', 'albuming', 'phosg')
# define function the eval_function()
# Attention: The eval_function ALWAYS needs to return a dataframe with one row.
#            Include exception handling, like if(N1>0 && N2>0) hr <- exp(coxph(...) )
#            to avoid program abort due to errors
hazardratio <- function(D) {

 HRpfs <- tryCatch(exp(coxph(Surv(D$timepfs, D$event.pfs) ~ D$trt )$coefficients[[1]]),
  warning=function(w) {NA})
 HRpfs <- 1/HRpfs
 HR.pfs <- round(HRpfs, 2)
 HR.pfs[HR.pfs > 10]      <- 10
 HR.pfs[HR.pfs < 0.00001] <- 0.00001
 HRos <- tryCatch(exp(coxph(Surv(D$timeos, D$event.os) ~ D$trt )$coefficients[[1]]),
  warning=function(w) {NA})
 HRos <- 1/HRos
 HR.os <- round(HRos, 2)
 HR.os[HR.os > 10]      <- 10
 HR.os[HR.os < 0.00001] <- 0.00001
 data.frame( HR.pfs, HR.os#, N.of.subjects,N1 ,N2

 # run subscreen

## Not run: 
results <- subscreencalc(data=pbcdat,
                     endpoints = c("timepfs" , "event.pfs", "timeos", "event.os"),
                     subjectid = "id",
                     factors=c("ageg", "sex", "bilig", "cholg", "copperg"),
                     use_complement = FALSE,
                     factorial = FALSE)

# visualize the results of the subgroup screening with a Shiny app
## End(Not run)

subscreen documentation built on May 13, 2022, 1:06 a.m.