## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(MuTATE)
data(mutate_example)
head(mutate_example)

## -----------------------------------------------------------------------------
strsplit("OS_definition_time_status", "_")[[1]]
# [3] "time"   -> must match the time column name
# [4] "status" -> must match the event column name

## -----------------------------------------------------------------------------
features     <- c("age", "sex", "biomarker")
outcomes     <- c("response", "tumor_size", "ae_count", "OS_definition_time_status")
outcome_defs <- c("Cat", "Cont", "Count", "Surv")

tree <- MTPart(
  features, outcomes, outcome_defs, mutate_example,
  depth    = 2,   # maximum tree depth
  nodesize = 30   # minimum observations per node before it can be split
)

## -----------------------------------------------------------------------------
tree$partitions

## -----------------------------------------------------------------------------
summ <- MTPartSummary(tree)
summ$summary_table

## -----------------------------------------------------------------------------
targets <- list(Definitions = outcome_defs, Z = mutate_example[, outcomes])
MTSummary(targets, mutate_example)$response

## -----------------------------------------------------------------------------
pruned <- MTPrune(tree, cp = 0.02)
pruned$partitions

## -----------------------------------------------------------------------------
test_result <- MTTest(tree, features, outcomes, outcome_defs, mutate_example)

## ----fig.width=8, fig.height=6------------------------------------------------
PlotTree(tree)

## ----eval = FALSE-------------------------------------------------------------
# cv_results <- CV_Tune(
#   features, outcomes, outcome_defs, mutate_example,
#   kfolds = 2, Y = "response",
#   drange = 2, noderange = 30, splitmin_div = 2,
#   method = "avgIG", alpharange = 0.05, igrange = 0.95,
#   psplitrange = 1, pdepthrange = 1, cp_val = 0
# )

