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

## ----data---------------------------------------------------------------------
library(ctreeMI)
n <- 600
d <- data.frame(x1 = rnorm(n), x2 = rnorm(n), x3 = rnorm(n))
d$y <- rnorm(n) + 1.2 * (d$x1 > 0) + 0.9 * (d$x1 > 0) * (d$x2 > 0.5)
d$x1[sample(n, 90)] <- NA
d$x2[sample(n, 60)] <- NA

## ----run----------------------------------------------------------------------
res <- discover_confirm(y ~ x1 + x2 + x3, data = d, m = 5, seed = 11)
res

## ----splits-------------------------------------------------------------------
res$confirmation$splits[, c("node_id", "depth", "rule", "contrast", "lower", "upper", "p_adj")]

## ----prune--------------------------------------------------------------------
pruned <- prune_unconfirmed(res$tree, res$confirmation)
pruned

## ----report-------------------------------------------------------------------
report_confirm(res)

## ----ordinal------------------------------------------------------------------
d$y_ord <- cut(d$y, c(-Inf, 0, 1.5, Inf), labels = c("low", "mid", "high"),
               ordered_result = TRUE)
res_ord <- discover_confirm(y_ord ~ x1 + x2 + x3, data = d, m = 5, seed = 12)
res_ord$confirmation$splits[, c("node_id", "rule", "contrast", "p_adj")]
head(res_ord$confirmation$nodes)

## ----cluster, eval = FALSE----------------------------------------------------
# res <- discover_confirm(y ~ x1 + x2 + x3, data = d, cluster = "cohort",
#                         m = 30, seed = 1)

