R Under development (unstable) (2024-07-17 r86903 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > suppressWarnings(RNGversion("3.5.2")) > > library("partykit") Loading required package: grid Loading required package: libcoin Loading required package: mvtnorm > set.seed(29) > > n <- 100 > x <- 1:n/n > y <- rnorm(n, mean = (x < .5) + 1) > xna <- x > xna[xna < .2] <- NA > d <- data.frame(x = x, y = y) > dna <- data.frame(x = xna, y = y) > > (t1 <- ctree(y ~ x, data = d)) Model formula: y ~ x Fitted party: [1] root | [2] x <= 0.5: 1.998 (n = 50, err = 52.5) | [3] x > 0.5: 0.743 (n = 50, err = 45.6) Number of inner nodes: 1 Number of terminal nodes: 2 > (t2 <- ctree(y ~ x, data = dna)) Model formula: y ~ x Fitted party: [1] root | [2] x <= 0.5: 2.070 (n = 37, err = 40.2) | [3] x > 0.5: 0.960 (n = 63, err = 68.5) Number of inner nodes: 1 Number of terminal nodes: 2 > (t3 <- ctree(y ~ x, data = dna, control = ctree_control(MIA = TRUE))) Model formula: y ~ x Fitted party: [1] root | [2] x <= 0.5: 1.998 (n = 50, err = 52.5) | [3] x > 0.5: 0.743 (n = 50, err = 45.6) Number of inner nodes: 1 Number of terminal nodes: 2 > > predict(t1, type = "node")[is.na(xna)] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 > predict(t2, type = "node")[is.na(xna)] 3 3 3 2 3 2 2 3 3 2 3 3 3 2 3 3 3 3 2 3 3 3 2 3 2 2 3 3 2 3 3 3 2 3 3 3 3 2 > predict(t3, type = "node")[is.na(xna)] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 > > xna <- x > xna[xna > .8] <- NA > d <- data.frame(x = x, y = y) > dna <- data.frame(x = xna, y = y) > > (t1 <- ctree(y ~ x, data = d)) Model formula: y ~ x Fitted party: [1] root | [2] x <= 0.5: 1.998 (n = 50, err = 52.5) | [3] x > 0.5: 0.743 (n = 50, err = 45.6) Number of inner nodes: 1 Number of terminal nodes: 2 > (t2 <- ctree(y ~ x, data = dna)) Model formula: y ~ x Fitted party: [1] root | [2] x <= 0.5: 1.864 (n = 61, err = 65.5) | [3] x > 0.5 | | [4] x <= 0.73: 0.755 (n = 29, err = 18.9) | | [5] x > 0.73: 0.150 (n = 10, err = 12.4) Number of inner nodes: 2 Number of terminal nodes: 3 > (t3 <- ctree(y ~ x, data = dna, control = ctree_control(MIA = TRUE))) Model formula: y ~ x Fitted party: [1] root | [2] x <= 0.5: 1.998 (n = 50, err = 52.5) | [3] x > 0.5 | | [4] x <= 0.73: 0.928 (n = 43, err = 31.9) | | [5] x > 0.73: -0.396 (n = 7, err = 3.1) Number of inner nodes: 2 Number of terminal nodes: 3 > > (n1 <- predict(t1, type = "node")) 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3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data = d)) Model formula: y ~ x Fitted party: [1] root | [2] x in (0,0.2], (0.2,0.4], (0.4,0.6]: 1.808 (n = 60, err = 68.1) | [3] x in (0.6,0.8], (0.8,1]: 0.714 (n = 40, err = 40.6) Number of inner nodes: 1 Number of terminal nodes: 2 > (t2 <- ctree(y ~ x, data = dna)) Model formula: y ~ x Fitted party: [1] root | [2] x in (0,0.2], (0.2,0.4], (0.4,0.6]: 1.651 (n = 75, err = 89.0) | [3] x in (0.6,0.8]: 0.529 (n = 25, err = 24.8) Number of inner nodes: 1 Number of terminal nodes: 2 > (t3 <- ctree(y ~ x, data = dna, control = ctree_control(MIA = TRUE))) Model formula: y ~ x Fitted party: [1] root | [2] x in (0.6,0.8]: 0.714 (n = 40, err = 40.6) | [3] x in (0,0.2], (0.2,0.4], (0.4,0.6]: 1.808 (n = 60, err = 68.1) Number of inner nodes: 1 Number of terminal nodes: 2 > > (n1 <- predict(t1, type = "node")) 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 > (n2 <- predict(t2, type = "node")) 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2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