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 <- 1000 > z <- runif(n) > y <- rnorm(n, mean = c(-1, 1)[(z > 0.5) + 1], sd = 3) > d <- data.frame(y = y, y2 = factor(y > median(y)), + z = z) > > c1 <- ctree(y2 ~ z, data = d, control = ctree_control(nmax = Inf, alpha = .5)) > c2 <- ctree(y2 ~ z, data = d, control = ctree_control(nmax = 25, alpha = .5)) > c3 <- ctree(y2 ~ z, data = d, control = ctree_control(nmax = nrow(d), alpha = .5)) > c4 <- ctree(y2 ~ z, data = d, control = ctree_control(nmax = 100, alpha = .5)) > > all.equal(predict(c1, type = "node"), predict(c3, type = "node")) [1] TRUE > > p1 <- predict(c1, type = "prob") > p2 <- predict(c2, type = "prob") > p3 <- predict(c3, type = "prob") > p4 <- predict(c4, type = "prob") > > ### binomial log-lik > sum(log(p1[cbind(1:nrow(d), unclass(d$y2))])) [1] -675.3508 > sum(log(p2[cbind(1:nrow(d), unclass(d$y2))])) [1] -676.0943 > sum(log(p3[cbind(1:nrow(d), unclass(d$y2))])) [1] -675.3508 > sum(log(p4[cbind(1:nrow(d), unclass(d$y2))])) [1] -676.0943 > > c1 <- ctree(y ~ z, data = d, control = ctree_control(nmax = c("yx" = Inf, "z" = 25), alpha = .5)) > > proc.time() user system elapsed 1.29 0.26 1.54