
> suppressWarnings(RNGversion("3.5.2"))

> options(width = 70, SweaveHooks = list(leftpar = function() par(mai = par("mai") * 
+     c(1, 1.1, 1, 1))))

> require("partykit")
Loading required package: partykit
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm

> require("coin")
Loading required package: coin
Loading required package: survival

> require("strucchange")
Loading required package: strucchange
Loading required package: zoo

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

    as.Date, as.Date.numeric

Loading required package: sandwich

> require("coin")

> require("Formula")
Loading required package: Formula

> require("survival")

> require("sandwich")

> set.seed(290875)

> ctree_control(teststat = "max")
$criterion
[1] "p.value"

$logmincriterion
[1] -0.05129329

$minsplit
[1] 20

$minbucket
[1] 7

$minprob
[1] 0.01

$maxvar
[1] Inf

$stump
[1] FALSE

$nmax
 yx   z 
Inf Inf 

$lookahead
[1] FALSE

$mtry
[1] Inf

$maxdepth
[1] Inf

$multiway
[1] FALSE

$splittry
[1] 2

$maxsurrogate
[1] 0

$numsurrogate
[1] FALSE

$majority
[1] FALSE

$caseweights
[1] TRUE

$applyfun
function (X, FUN, ...) 
{
    FUN <- match.fun(FUN)
    if (!is.vector(X) || is.object(X)) 
        X <- as.list(X)
    .Internal(lapply(X, FUN))
}
<bytecode: 0x55b623b88ac0>
<environment: namespace:base>

$saveinfo
[1] TRUE

$bonferroni
[1] TRUE

$update
NULL

$selectfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .select(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f595570>
<environment: 0x55b62f5949a0>

$splitfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .split(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f599e08>
<environment: 0x55b62f599238>

$svselectfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .select(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f595570>
<environment: 0x55b62f599158>

$svsplitfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .split(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f599e08>
<environment: 0x55b62f599008>

$teststat
[1] "maximum"

$splitstat
[1] "quadratic"

$splittest
[1] FALSE

$pargs
$maxpts
[1] 25000

$abseps
[1] 0.001

$releps
[1] 0

attr(,"class")
[1] "GenzBretz"

$testtype
[1] "Bonferroni"

$nresample
[1] 9999

$tol
[1] 1.490116e-08

$intersplit
[1] FALSE

$MIA
[1] FALSE


> ctree_control(teststat = "quad")
$criterion
[1] "p.value"

$logmincriterion
[1] -0.05129329

$minsplit
[1] 20

$minbucket
[1] 7

$minprob
[1] 0.01

$maxvar
[1] Inf

$stump
[1] FALSE

$nmax
 yx   z 
Inf Inf 

$lookahead
[1] FALSE

$mtry
[1] Inf

$maxdepth
[1] Inf

$multiway
[1] FALSE

$splittry
[1] 2

$maxsurrogate
[1] 0

$numsurrogate
[1] FALSE

$majority
[1] FALSE

$caseweights
[1] TRUE

$applyfun
function (X, FUN, ...) 
{
    FUN <- match.fun(FUN)
    if (!is.vector(X) || is.object(X)) 
        X <- as.list(X)
    .Internal(lapply(X, FUN))
}
<bytecode: 0x55b623b88ac0>
<environment: namespace:base>

$saveinfo
[1] TRUE

$bonferroni
[1] TRUE

$update
NULL

$selectfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .select(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f595570>
<environment: 0x55b62f5c6520>

$splitfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .split(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f599e08>
<environment: 0x55b62f5c6440>

$svselectfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .select(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f595570>
<environment: 0x55b62f5c6360>

$svsplitfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .split(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f599e08>
<environment: 0x55b62f5c6210>

$teststat
[1] "quadratic"

$splitstat
[1] "quadratic"

$splittest
[1] FALSE

$pargs
$maxpts
[1] 25000

$abseps
[1] 0.001

$releps
[1] 0

attr(,"class")
[1] "GenzBretz"

$testtype
[1] "Bonferroni"

$nresample
[1] 9999

$tol
[1] 1.490116e-08

$intersplit
[1] FALSE

$MIA
[1] FALSE


> ctree_control(testtype = "Bonferroni")
$criterion
[1] "p.value"

$logmincriterion
[1] -0.05129329

$minsplit
[1] 20

$minbucket
[1] 7

$minprob
[1] 0.01

$maxvar
[1] Inf

$stump
[1] FALSE

$nmax
 yx   z 
Inf Inf 

$lookahead
[1] FALSE

$mtry
[1] Inf

$maxdepth
[1] Inf

$multiway
[1] FALSE

$splittry
[1] 2

$maxsurrogate
[1] 0

$numsurrogate
[1] FALSE

$majority
[1] FALSE

$caseweights
[1] TRUE

$applyfun
function (X, FUN, ...) 
{
    FUN <- match.fun(FUN)
    if (!is.vector(X) || is.object(X)) 
        X <- as.list(X)
    .Internal(lapply(X, FUN))
}
<bytecode: 0x55b623b88ac0>
<environment: namespace:base>

$saveinfo
[1] TRUE

$bonferroni
[1] TRUE

$update
NULL

$selectfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .select(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f595570>
<environment: 0x55b62f5d99f8>

$splitfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .split(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f599e08>
<environment: 0x55b62f5d9918>

$svselectfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .select(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f595570>
<environment: 0x55b62f5d9838>

$svsplitfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .split(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f599e08>
<environment: 0x55b62f5d96e8>

$teststat
[1] "quadratic"

$splitstat
[1] "quadratic"

$splittest
[1] FALSE

$pargs
$maxpts
[1] 25000

$abseps
[1] 0.001

$releps
[1] 0

attr(,"class")
[1] "GenzBretz"

$testtype
[1] "Bonferroni"

$nresample
[1] 9999

$tol
[1] 1.490116e-08

$intersplit
[1] FALSE

$MIA
[1] FALSE


> ctree_control(minsplit = 20)
$criterion
[1] "p.value"

$logmincriterion
[1] -0.05129329

$minsplit
[1] 20

$minbucket
[1] 7

$minprob
[1] 0.01

$maxvar
[1] Inf

$stump
[1] FALSE

$nmax
 yx   z 
Inf Inf 

$lookahead
[1] FALSE

$mtry
[1] Inf

$maxdepth
[1] Inf

$multiway
[1] FALSE

$splittry
[1] 2

$maxsurrogate
[1] 0

$numsurrogate
[1] FALSE

$majority
[1] FALSE

$caseweights
[1] TRUE

$applyfun
function (X, FUN, ...) 
{
    FUN <- match.fun(FUN)
    if (!is.vector(X) || is.object(X)) 
        X <- as.list(X)
    .Internal(lapply(X, FUN))
}
<bytecode: 0x55b623b88ac0>
<environment: namespace:base>

$saveinfo
[1] TRUE

$bonferroni
[1] TRUE

$update
NULL

$selectfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .select(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f595570>
<environment: 0x55b62f5eec90>

$splitfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .split(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f599e08>
<environment: 0x55b62f5eebb0>

$svselectfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .select(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f595570>
<environment: 0x55b62f5eead0>

$svsplitfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .split(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f599e08>
<environment: 0x55b62f5ee980>

$teststat
[1] "quadratic"

$splitstat
[1] "quadratic"

$splittest
[1] FALSE

$pargs
$maxpts
[1] 25000

$abseps
[1] 0.001

$releps
[1] 0

attr(,"class")
[1] "GenzBretz"

$testtype
[1] "Bonferroni"

$nresample
[1] 9999

$tol
[1] 1.490116e-08

$intersplit
[1] FALSE

$MIA
[1] FALSE


> ctree_control(maxsurrogate = 3)
$criterion
[1] "p.value"

$logmincriterion
[1] -0.05129329

$minsplit
[1] 20

$minbucket
[1] 7

$minprob
[1] 0.01

$maxvar
[1] Inf

$stump
[1] FALSE

$nmax
 yx   z 
Inf Inf 

$lookahead
[1] FALSE

$mtry
[1] Inf

$maxdepth
[1] Inf

$multiway
[1] FALSE

$splittry
[1] 2

$maxsurrogate
[1] 3

$numsurrogate
[1] FALSE

$majority
[1] FALSE

$caseweights
[1] TRUE

$applyfun
function (X, FUN, ...) 
{
    FUN <- match.fun(FUN)
    if (!is.vector(X) || is.object(X)) 
        X <- as.list(X)
    .Internal(lapply(X, FUN))
}
<bytecode: 0x55b623b88ac0>
<environment: namespace:base>

$saveinfo
[1] TRUE

$bonferroni
[1] TRUE

$update
NULL

$selectfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .select(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f595570>
<environment: 0x55b62f600248>

$splitfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .split(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f599e08>
<environment: 0x55b62f600168>

$svselectfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .select(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f595570>
<environment: 0x55b62f600088>

$svsplitfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .split(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55b62f599e08>
<environment: 0x55b62f5fff38>

$teststat
[1] "quadratic"

$splitstat
[1] "quadratic"

$splittest
[1] FALSE

$pargs
$maxpts
[1] 25000

$abseps
[1] 0.001

$releps
[1] 0

attr(,"class")
[1] "GenzBretz"

$testtype
[1] "Bonferroni"

$nresample
[1] 9999

$tol
[1] 1.490116e-08

$intersplit
[1] FALSE

$MIA
[1] FALSE


> ls <- data.frame(y = gl(3, 50, labels = c("A", "B", 
+     "C")), x1 = rnorm(150) + rep(c(1, 0, 0), c(50, 50, 50)), 
+     x2 = runif(150))

> library("partykit")

> ctree(y ~ x1 + x2, data = ls)

Model formula:
y ~ x1 + x2

Fitted party:
[1] root
|   [2] x1 <= 0.82552: C (n = 96, err = 57.3%)
|   [3] x1 > 0.82552: A (n = 54, err = 42.6%)

Number of inner nodes:    1
Number of terminal nodes: 2

> ct <- ctree(y ~ x1 + x2, data = ls)

> ct

Model formula:
y ~ x1 + x2

Fitted party:
[1] root
|   [2] x1 <= 0.82552: C (n = 96, err = 57.3%)
|   [3] x1 > 0.82552: A (n = 54, err = 42.6%)

Number of inner nodes:    1
Number of terminal nodes: 2

> plot(ct)

> ct[1]

Model formula:
y ~ x1 + x2

Fitted party:
[1] root
|   [2] x1 <= 0.82552: C (n = 96, err = 57.3%)
|   [3] x1 > 0.82552: A (n = 54, err = 42.6%)

Number of inner nodes:    1
Number of terminal nodes: 2

> class(ct[1])
[1] "constparty" "party"     

> predict(ct, newdata = ls)
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17 
  A   A   A   A   C   A   C   A   C   C   A   A   C   A   A   A   A 
 18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34 
  C   A   C   A   A   A   C   A   A   A   C   C   A   A   C   A   A 
 35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51 
  C   A   A   C   C   C   A   A   C   C   C   C   A   A   A   A   A 
 52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68 
  A   C   C   C   C   A   C   C   A   C   C   C   C   C   C   A   A 
 69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85 
  A   A   A   C   C   A   C   A   C   C   C   C   C   C   C   C   C 
 86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 
  C   C   C   A   C   A   C   A   C   C   C   C   C   C   C   C   A 
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 
  C   C   C   A   C   C   A   C   C   C   C   C   C   C   A   C   C 
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 
  C   C   C   C   C   C   C   C   C   C   C   C   C   C   C   C   C 
137 138 139 140 141 142 143 144 145 146 147 148 149 150 
  C   A   C   C   C   C   A   C   C   A   C   A   C   A 
Levels: A B C

> predict(ct, newdata = ls[c(1, 51, 101), ], type = "prob")
            A         B         C
1   0.5740741 0.2592593 0.1666667
51  0.5740741 0.2592593 0.1666667
101 0.1979167 0.3750000 0.4270833

> predict(ct, newdata = ls[c(1, 51, 101), ], type = "node")
  1  51 101 
  3   3   2 

> library("strucchange")

> sctest(ct)
$`1`
                    x1        x2
statistic 2.299131e+01 4.0971294
p.value   2.034833e-05 0.2412193

$`2`
                 x1        x2
statistic 2.6647107 4.3628130
p.value   0.4580906 0.2130228

$`3`
                 x1        x2
statistic 2.1170497 2.8275567
p.value   0.5735483 0.4272879


> data("treepipit", package = "coin")

> tptree <- ctree(counts ~ ., data = treepipit)

> plot(tptree, terminal_panel = node_barplot)

> p <- info_node(node_party(tptree))$p.value

> n <- table(predict(tptree, type = "node"))

> data("GlaucomaM", package = "TH.data")

> gtree <- ctree(Class ~ ., data = GlaucomaM)

> sp <- split_node(node_party(gtree))$varID

> plot(gtree)

> plot(gtree, inner_panel = node_barplot, edge_panel = function(...) invisible(), 
+     tnex = 1)

> table(predict(gtree), GlaucomaM$Class)
          
           glaucoma normal
  glaucoma       74      5
  normal         24     93

> prob <- predict(gtree, type = "prob")[, 1] + runif(nrow(GlaucomaM), 
+     min = -0.01, max = 0.01)

> splitvar <- character_split(split_node(node_party(gtree)), 
+     data = data_party(gtree))$name

> plot(GlaucomaM[[splitvar]], prob, pch = as.numeric(GlaucomaM$Class), 
+     ylab = "Conditional Class Prob.", xlab = splitvar)

> abline(v = split_node(node_party(gtree))$breaks, lty = 2)

> legend(0.15, 0.7, pch = 1:2, legend = levels(GlaucomaM$Class), 
+     bty = "n")

> data("GBSG2", package = "TH.data")

> library("survival")

> (stree <- ctree(Surv(time, cens) ~ ., data = GBSG2))

Model formula:
Surv(time, cens) ~ horTh + age + menostat + tsize + tgrade + 
    pnodes + progrec + estrec

Fitted party:
[1] root
|   [2] pnodes <= 3
|   |   [3] horTh in no: 2093.000 (n = 248)
|   |   [4] horTh in yes: Inf (n = 128)
|   [5] pnodes > 3
|   |   [6] progrec <= 20: 624.000 (n = 144)
|   |   [7] progrec > 20: 1701.000 (n = 166)

Number of inner nodes:    3
Number of terminal nodes: 4

> plot(stree)

> pn <- predict(stree, newdata = GBSG2[1:2, ], type = "node")

> n <- predict(stree, type = "node")

> survfit(Surv(time, cens) ~ 1, data = GBSG2, subset = (n == 
+     pn[1]))
Call: survfit(formula = Surv(time, cens) ~ 1, data = GBSG2, subset = (n == 
    pn[1]))

       n events median 0.95LCL 0.95UCL
[1,] 248     88   2093    1814      NA

> survfit(Surv(time, cens) ~ 1, data = GBSG2, subset = (n == 
+     pn[2]))
Call: survfit(formula = Surv(time, cens) ~ 1, data = GBSG2, subset = (n == 
    pn[2]))

       n events median 0.95LCL 0.95UCL
[1,] 166     77   1701    1174    2018

> data("mammoexp", package = "TH.data")

> mtree <- ctree(ME ~ ., data = mammoexp)

> plot(mtree)

> data("HuntingSpiders", package = "partykit")

> sptree <- ctree(arct.lute + pard.lugu + zora.spin + 
+     pard.nigr + pard.pull + aulo.albi + troc.terr + alop.cune + 
+     pard.mont + alop.acce  .... [TRUNCATED] 

> plot(sptree, terminal_panel = node_barplot)

> plot(sptree)

> library("party")
Loading required package: modeltools
Loading required package: stats4

Attaching package: ‘party’

The following objects are masked from ‘package:partykit’:

    cforest, ctree, ctree_control, edge_simple, mob,
    mob_control, node_barplot, node_bivplot, node_boxplot,
    node_inner, node_surv, node_terminal, varimp


> set.seed(290875)

> data("airquality", package = "datasets")

> airq <- subset(airquality, !is.na(Ozone))

> (airct_party <- party::ctree(Ozone ~ ., data = airq, 
+     controls = party::ctree_control(maxsurrogate = 3)))

	 Conditional inference tree with 5 terminal nodes

Response:  Ozone 
Inputs:  Solar.R, Wind, Temp, Month, Day 
Number of observations:  116 

1) Temp <= 82; criterion = 1, statistic = 56.086
  2) Wind <= 6.9; criterion = 0.998, statistic = 12.969
    3)*  weights = 10 
  2) Wind > 6.9
    4) Temp <= 77; criterion = 0.997, statistic = 11.599
      5)*  weights = 48 
    4) Temp > 77
      6)*  weights = 21 
1) Temp > 82
  7) Wind <= 10.3; criterion = 0.997, statistic = 11.712
    8)*  weights = 30 
  7) Wind > 10.3
    9)*  weights = 7 

> mean((airq$Ozone - predict(airct_party))^2)
[1] 403.6668

> (airct_partykit <- partykit::ctree(Ozone ~ ., data = airq, 
+     control = partykit::ctree_control(maxsurrogate = 3, numsurrogate = TRUE)))

Model formula:
Ozone ~ Solar.R + Wind + Temp + Month + Day

Fitted party:
[1] root
|   [2] Temp <= 82
|   |   [3] Wind <= 6.9: 55.600 (n = 10, err = 21946.4)
|   |   [4] Wind > 6.9
|   |   |   [5] Temp <= 77: 18.479 (n = 48, err = 3956.0)
|   |   |   [6] Temp > 77: 31.143 (n = 21, err = 4620.6)
|   [7] Temp > 82
|   |   [8] Wind <= 10.3: 81.633 (n = 30, err = 15119.0)
|   |   [9] Wind > 10.3: 48.714 (n = 7, err = 1183.4)

Number of inner nodes:    4
Number of terminal nodes: 5

> mean((airq$Ozone - predict(airct_partykit))^2)
[1] 403.6668

> table(predict(airct_party, type = "node"), predict(airct_partykit, 
+     type = "node"))
   
     3  5  6  8  9
  3 10  0  0  0  0
  5  0 48  0  0  0
  6  0  0 21  0  0
  8  0  0  0 30  0
  9  0  0  0  0  7

> max(abs(predict(airct_party) - predict(airct_partykit)))
[1] 0

> airct_party@tree$criterion
$statistic
    Solar.R        Wind        Temp       Month         Day 
13.34761286 41.61369618 56.08632426  3.11265955  0.02011554 

$criterion
     Solar.R         Wind         Temp        Month          Day 
9.987069e-01 1.000000e+00 1.000000e+00 6.674119e-01 1.824984e-05 

$maxcriterion
[1] 1


> info_node(node_party(airct_partykit))
$criterion
               Solar.R          Wind          Temp      Month
statistic 13.347612859  4.161370e+01  5.608632e+01  3.1126596
p.value    0.001293090  5.560572e-10  3.467894e-13  0.3325881
criterion -0.001293926 -5.560572e-10 -3.467894e-13 -0.4043478
                   Day
statistic   0.02011554
p.value     0.99998175
criterion -10.91135399

$p.value
        Temp 
3.467894e-13 

$unweighted
[1] TRUE

$nobs
[1] 116


> (irisct_party <- party::ctree(Species ~ ., data = iris))

	 Conditional inference tree with 4 terminal nodes

Response:  Species 
Inputs:  Sepal.Length, Sepal.Width, Petal.Length, Petal.Width 
Number of observations:  150 

1) Petal.Length <= 1.9; criterion = 1, statistic = 140.264
  2)*  weights = 50 
1) Petal.Length > 1.9
  3) Petal.Width <= 1.7; criterion = 1, statistic = 67.894
    4) Petal.Length <= 4.8; criterion = 0.999, statistic = 13.865
      5)*  weights = 46 
    4) Petal.Length > 4.8
      6)*  weights = 8 
  3) Petal.Width > 1.7
    7)*  weights = 46 

> (irisct_partykit <- partykit::ctree(Species ~ ., data = iris, 
+     control = partykit::ctree_control(splitstat = "maximum")))

Model formula:
Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width

Fitted party:
[1] root
|   [2] Petal.Length <= 1.9: setosa (n = 50, err = 0.0%)
|   [3] Petal.Length > 1.9
|   |   [4] Petal.Width <= 1.7
|   |   |   [5] Petal.Length <= 4.8: versicolor (n = 46, err = 2.2%)
|   |   |   [6] Petal.Length > 4.8: versicolor (n = 8, err = 50.0%)
|   |   [7] Petal.Width > 1.7: virginica (n = 46, err = 2.2%)

Number of inner nodes:    3
Number of terminal nodes: 4

> table(predict(irisct_party, type = "node"), predict(irisct_partykit, 
+     type = "node"))
   
     2  5  6  7
  2 50  0  0  0
  5  0 46  0  0
  6  0  0  8  0
  7  0  0  0 46

> tr_party <- treeresponse(irisct_party, newdata = iris)

> tr_partykit <- predict(irisct_partykit, type = "prob", 
+     newdata = iris)

> max(abs(do.call("rbind", tr_party) - tr_partykit))
[1] 0

> data("mammoexp", package = "TH.data")

> (mammoct_party <- party::ctree(ME ~ ., data = mammoexp))

	 Conditional inference tree with 3 terminal nodes

Response:  ME 
Inputs:  SYMPT, PB, HIST, BSE, DECT 
Number of observations:  412 

1) SYMPT <= Agree; criterion = 1, statistic = 29.933
  2)*  weights = 113 
1) SYMPT > Agree
  3) PB <= 8; criterion = 0.988, statistic = 9.17
    4)*  weights = 208 
  3) PB > 8
    5)*  weights = 91 

> tr_party <- treeresponse(mammoct_party, newdata = mammoexp)

> (mammoct_partykit <- partykit::ctree(ME ~ ., data = mammoexp))

Model formula:
ME ~ SYMPT + PB + HIST + BSE + DECT

Fitted party:
[1] root
|   [2] SYMPT <= Agree: Never (n = 113, err = 15.9%)
|   [3] SYMPT > Agree
|   |   [4] PB <= 8: Never (n = 208, err = 60.1%)
|   |   [5] PB > 8: Never (n = 91, err = 38.5%)

Number of inner nodes:    2
Number of terminal nodes: 3

> tr_partykit <- predict(mammoct_partykit, newdata = mammoexp, 
+     type = "prob")

> max(abs(do.call("rbind", tr_party) - tr_partykit))
[1] 0

> data("GBSG2", package = "TH.data")

> (GBSG2ct_party <- party::ctree(Surv(time, cens) ~ 
+     ., data = GBSG2))

	 Conditional inference tree with 4 terminal nodes

Response:  Surv(time, cens) 
Inputs:  horTh, age, menostat, tsize, tgrade, pnodes, progrec, estrec 
Number of observations:  686 

1) pnodes <= 3; criterion = 1, statistic = 56.156
  2) horTh == {yes}; criterion = 0.965, statistic = 8.113
    3)*  weights = 128 
  2) horTh == {no}
    4)*  weights = 248 
1) pnodes > 3
  5) progrec <= 20; criterion = 0.999, statistic = 14.941
    6)*  weights = 144 
  5) progrec > 20
    7)*  weights = 166 

> (GBSG2ct_partykit <- partykit::ctree(Surv(time, cens) ~ 
+     ., data = GBSG2))

Model formula:
Surv(time, cens) ~ horTh + age + menostat + tsize + tgrade + 
    pnodes + progrec + estrec

Fitted party:
[1] root
|   [2] pnodes <= 3
|   |   [3] horTh in no: 2093.000 (n = 248)
|   |   [4] horTh in yes: Inf (n = 128)
|   [5] pnodes > 3
|   |   [6] progrec <= 20: 624.000 (n = 144)
|   |   [7] progrec > 20: 1701.000 (n = 166)

Number of inner nodes:    3
Number of terminal nodes: 4

> tr_party <- treeresponse(GBSG2ct_party, newdata = GBSG2)

> tr_partykit <- predict(GBSG2ct_partykit, newdata = GBSG2, 
+     type = "prob")

> all.equal(lapply(tr_party, function(x) unclass(x)[!(names(x) %in% 
+     "call")]), lapply(tr_partykit, function(x) unclass(x)[!(names(x) %in% 
+    .... [TRUNCATED] 
[1] TRUE

> (airct_partykit_1 <- partykit::ctree(Ozone ~ ., data = airq, 
+     control = partykit::ctree_control(maxsurrogate = 3, alpha = 0.001, 
+         nu .... [TRUNCATED] 

Model formula:
Ozone ~ Solar.R + Wind + Temp + Month + Day

Fitted party:
[1] root
|   [2] Temp <= 82: 26.544 (n = 79, err = 42531.6)
|   [3] Temp > 82: 75.405 (n = 37, err = 22452.9)

Number of inner nodes:    1
Number of terminal nodes: 2

> depth(airct_partykit_1)
[1] 1

> mean((airq$Ozone - predict(airct_partykit_1))^2)
[1] 560.2113

> (airct_partykit <- partykit::ctree(Ozone ~ ., data = airq, 
+     control = partykit::ctree_control(maxsurrogate = 3, splittest = TRUE, 
+         t .... [TRUNCATED] 

Model formula:
Ozone ~ Solar.R + Wind + Temp + Month + Day

Fitted party:
[1] root
|   [2] Temp <= 82
|   |   [3] Wind <= 6.9: 55.600 (n = 10, err = 21946.4)
|   |   [4] Wind > 6.9
|   |   |   [5] Temp <= 77
|   |   |   |   [6] Solar.R <= 78: 12.533 (n = 15, err = 723.7)
|   |   |   |   [7] Solar.R > 78: 21.182 (n = 33, err = 2460.9)
|   |   |   [8] Temp > 77
|   |   |   |   [9] Solar.R <= 148: 20.000 (n = 7, err = 652.0)
|   |   |   |   [10] Solar.R > 148: 36.714 (n = 14, err = 2664.9)
|   [11] Temp > 82
|   |   [12] Temp <= 87
|   |   |   [13] Wind <= 8.6: 72.308 (n = 13, err = 8176.8)
|   |   |   [14] Wind > 8.6: 45.571 (n = 7, err = 617.7)
|   |   [15] Temp > 87: 90.059 (n = 17, err = 3652.9)

Number of inner nodes:    7
Number of terminal nodes: 8

> (irisct_partykit_1 <- partykit::ctree(Species ~ ., 
+     data = iris, control = partykit::ctree_control(splitstat = "maximum", 
+         nmax = 25 .... [TRUNCATED] 

Model formula:
Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width

Fitted party:
[1] root
|   [2] Petal.Width <= 0.6: setosa (n = 50, err = 0.0%)
|   [3] Petal.Width > 0.6
|   |   [4] Petal.Width <= 1.7
|   |   |   [5] Petal.Length <= 4.8: versicolor (n = 46, err = 2.2%)
|   |   |   [6] Petal.Length > 4.8: versicolor (n = 8, err = 50.0%)
|   |   [7] Petal.Width > 1.7: virginica (n = 46, err = 2.2%)

Number of inner nodes:    3
Number of terminal nodes: 4

> table(predict(irisct_partykit), predict(irisct_partykit_1))
            
             setosa versicolor virginica
  setosa         50          0         0
  versicolor      0         54         0
  virginica       0          0        46

> GBSG2$tgrade <- factor(GBSG2$tgrade, ordered = FALSE)

> (GBSG2ct_partykit <- partykit::ctree(Surv(time, cens) ~ 
+     tgrade, data = GBSG2, control = partykit::ctree_control(multiway = TRUE, 
+     alpha .... [TRUNCATED] 

Model formula:
Surv(time, cens) ~ tgrade

Fitted party:
[1] root
|   [2] tgrade in I: Inf (n = 81)
|   [3] tgrade in II: 1730.000 (n = 444)
|   [4] tgrade in III: 1337.000 (n = 161)

Number of inner nodes:    1
Number of terminal nodes: 3

> airq$month <- factor(airq$Month)

> (airct_partykit_3 <- partykit::ctree(Ozone ~ Solar.R + 
+     Wind + Temp, data = airq, cluster = month, control = partykit::ctree_control(maxsurrog .... [TRUNCATED] 

Model formula:
Ozone ~ Solar.R + Wind + Temp

Fitted party:
[1] root
|   [2] Temp <= 82
|   |   [3] Temp <= 76: 18.250 (n = 48, err = 4199.0)
|   |   [4] Temp > 76
|   |   |   [5] Wind <= 6.9: 71.857 (n = 7, err = 15510.9)
|   |   |   [6] Wind > 6.9
|   |   |   |   [7] Temp <= 81: 32.412 (n = 17, err = 4204.1)
|   |   |   |   [8] Temp > 81: 23.857 (n = 7, err = 306.9)
|   [9] Temp > 82
|   |   [10] Wind <= 10.3: 81.633 (n = 30, err = 15119.0)
|   |   [11] Wind > 10.3: 48.714 (n = 7, err = 1183.4)

Number of inner nodes:    5
Number of terminal nodes: 6

> info_node(node_party(airct_partykit_3))
$criterion
                Solar.R          Wind          Temp
statistic 14.4805065501  3.299881e+01  4.783766e+01
p.value    0.0004247923  2.766464e-08  1.389038e-11
criterion -0.0004248826 -2.766464e-08 -1.389038e-11

$p.value
        Temp 
1.389038e-11 

$unweighted
[1] TRUE

$nobs
[1] 116


> mean((airq$Ozone - predict(airct_partykit_3))^2)
[1] 349.3382

> h <- function(y, x, start = NULL, weights, offset, 
+     estfun = TRUE, object = FALSE, ...) {
+     if (is.null(weights)) 
+         weights <- re .... [TRUNCATED] 

> partykit::ctree(Surv(time, cens) ~ ., data = GBSG2, 
+     ytrafo = h)

Model formula:
Surv(time, cens) ~ horTh + age + menostat + tsize + tgrade + 
    pnodes + progrec + estrec

Fitted party:
[1] root
|   [2] pnodes <= 3
|   |   [3] horTh in no: 2093.000 (n = 248)
|   |   [4] horTh in yes: Inf (n = 128)
|   [5] pnodes > 3
|   |   [6] progrec <= 20: 624.000 (n = 144)
|   |   [7] progrec > 20: 1701.000 (n = 166)

Number of inner nodes:    3
Number of terminal nodes: 4

> h <- function(y, x, start = NULL, weights = NULL, 
+     offset = NULL, cluster = NULL, ...) glm(y ~ 0 + x, family = gaussian(), 
+     start = star .... [TRUNCATED] 

> (airct_partykit_4 <- partykit::ctree(Ozone ~ Temp | 
+     Solar.R + Wind, data = airq, cluster = month, ytrafo = h, 
+     control = partykit::ctre .... [TRUNCATED] 

Model formula:
Ozone ~ Temp + (Solar.R + Wind)

Fitted party:
[1] root
|   [2] Wind <= 5.7: 98.692 (n = 13, err = 11584.8)
|   [3] Wind > 5.7
|   |   [4] Wind <= 8
|   |   |   [5] Wind <= 6.9: 55.286 (n = 14, err = 11330.9)
|   |   |   [6] Wind > 6.9: 50.824 (n = 17, err = 15400.5)
|   |   [7] Wind > 8: 27.306 (n = 72, err = 25705.3)

Number of inner nodes:    3
Number of terminal nodes: 4

> airq$node <- factor(predict(airct_partykit_4, type = "node"))

> summary(m <- glm(Ozone ~ node + node:Temp - 1, data = airq))

Call:
glm(formula = Ozone ~ node + node:Temp - 1, data = airq)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-45.801  -11.208   -1.049   10.903   53.615  

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
node2       300.0527    93.4828   3.210 0.001750 ** 
node5      -217.3416    51.3970  -4.229 4.94e-05 ***
node6      -178.9333    58.1093  -3.079 0.002632 ** 
node7       -82.2722    17.9951  -4.572 1.29e-05 ***
node2:Temp   -2.2922     1.0626  -2.157 0.033214 *  
node5:Temp    3.2989     0.6191   5.328 5.47e-07 ***
node6:Temp    2.8059     0.7076   3.965 0.000132 ***
node7:Temp    1.4769     0.2408   6.133 1.45e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 329.3685)

    Null deviance: 331029  on 116  degrees of freedom
Residual deviance:  35572  on 108  degrees of freedom
AIC: 1011.4

Number of Fisher Scoring iterations: 2


> mean((predict(m) - airq$Ozone)^2)
[1] 306.6534

> airq_lmtree <- partykit::lmtree(Ozone ~ Temp | Solar.R + 
+     Wind, data = airq, cluster = month)

> info_node(node_party(airq_lmtree))
$coefficients
(Intercept)        Temp 
 -147.64607     2.43911 

$objfun
[1] 62367.44

$object

Call:
lm(formula = Ozone ~ Temp)

Coefficients:
(Intercept)         Temp  
   -147.646        2.439  


$nobs
[1] 111

$p.value
[1] 0.003498545

$test
            Solar.R         Wind
statistic 8.5761635 18.881769795
p.value   0.2771841  0.003498545


> mean((predict(airq_lmtree, newdata = airq) - airq$Ozone)^2)
[1] 371.5366

> detach(package:party)

 *** Run successfully completed ***
> proc.time()
   user  system elapsed 
  6.301   0.112   6.440 
