R Under development (unstable) (2019-12-29 r77627) -- "Unsuffered Consequences" Copyright (C) 2019 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) 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. Natural language support but running in an English locale 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. > pkgname <- "itree" > source(file.path(R.home("share"), "R", "examples-header.R")) > options(warn = 1) > library('itree') itree is based on the code of rpart. Bug reports should be directed to this package's maintainer, not rparts'. > > base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') > cleanEx() > nameEx("car.test.frame") > ### * car.test.frame > > flush(stderr()); flush(stdout()) > > ### Name: car.test.frame > ### Title: Automobile Data from 'Consumer Reports' 1990 > ### Aliases: car.test.frame > ### Keywords: datasets > > ### ** Examples > > #just as in rpart > z.auto <- itree(Mileage ~ Weight, car.test.frame) > summary(z.auto) Call: itree(formula = Mileage ~ Weight, data = car.test.frame) n= 60 CP nsplit rel error xerror xstd 1 0.59534912 0 1.0000000 1.0337818 0.18046532 2 0.13452819 1 0.4046509 0.5836606 0.10900973 3 0.01282843 2 0.2701227 0.4409221 0.08652804 4 0.01000000 3 0.2572943 0.4415805 0.08663003 Node number 1: 60 observations, complexity param=0.5953491 mean=24.58333, MSE=22.57639 left son=2 (45 obs) right son=3 (15 obs) Primary splits: Weight < 2567.5 to the right, improve=0.5953491, (0 missing) Node number 2: 45 observations, complexity param=0.1345282 mean=22.46667, MSE=8.026667 left son=4 (22 obs) right son=5 (23 obs) Primary splits: Weight < 3087.5 to the right, improve=0.5045118, (0 missing) Node number 3: 15 observations mean=30.93333, MSE=12.46222 Node number 4: 22 observations mean=20.40909, MSE=2.78719 Node number 5: 23 observations, complexity param=0.01282843 mean=24.43478, MSE=5.115312 left son=10 (15 obs) right son=11 (8 obs) Primary splits: Weight < 2747.5 to the right, improve=0.1476996, (0 missing) Node number 10: 15 observations mean=23.8, MSE=4.026667 Node number 11: 8 observations mean=25.625, MSE=4.984375 > > > > cleanEx() > nameEx("cu.summary") > ### * cu.summary > > flush(stderr()); flush(stdout()) > > ### Name: cu.summary > ### Title: Automobile Data from 'Consumer Reports' 1990 > ### Aliases: cu.summary > ### Keywords: datasets > > ### ** Examples > > #same example as in rpart: > fit <- itree(Price ~ Mileage + Type + Country, cu.summary) bsplit.c:125:31: runtime error: index 2 out of bounds for type 'int [2]' #0 0x7f182c98b573 in bsplit /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/bsplit.c:125:49 #1 0x7f182c9af509 in partition /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/partition.c:71:5 #2 0x7f182c9cefa3 in rpart /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/rpart.c:243:5 #3 0x7f182c9d8ec9 in s_to_rp /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/s_to_rp.c:32:12 #4 0x74ba49 in do_dotCode /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c #5 0x85054e in bcEval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:7054:14 #6 0x83a685 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:688:8 #7 0x89d833 in R_execClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c #8 0x89a79a in Rf_applyClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:1779:16 #9 0x83b4eb in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:811:12 #10 0x8ab39b in do_set /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:2920:8 #11 0x83acc3 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:763:12 #12 0x971876 in Rf_ReplIteration /data/gannet/ripley/R/svn/R-devel/src/main/main.c:264:2 #13 0x975df0 in R_ReplConsole /data/gannet/ripley/R/svn/R-devel/src/main/main.c:314:11 #14 0x975bd5 in run_Rmainloop /data/gannet/ripley/R/svn/R-devel/src/main/main.c:1113:5 #15 0x4da35a in main /data/gannet/ripley/R/svn/R-devel/src/main/Rmain.c:29:5 #16 0x7f183d4fdf42 in __libc_start_main (/lib64/libc.so.6+0x23f42) #17 0x43036d in _start (/data/gannet/ripley/R/R-clang-SAN/bin/exec/R+0x43036d) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior bsplit.c:125:31 in surrogate.c:109:42: runtime error: index 2 out of bounds for type 'int [2]' #0 0x7f182c9e2145 in surrogate /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/surrogate.c:109:56 #1 0x7f182c9af566 in partition /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/partition.c:84:28 #2 0x7f182c9cefa3 in rpart /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/rpart.c:243:5 #3 0x7f182c9d8ec9 in s_to_rp /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/s_to_rp.c:32:12 #4 0x74ba49 in do_dotCode /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c #5 0x85054e in bcEval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:7054:14 #6 0x83a685 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:688:8 #7 0x89d833 in R_execClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c #8 0x89a79a in Rf_applyClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:1779:16 #9 0x83b4eb in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:811:12 #10 0x8ab39b in do_set /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:2920:8 #11 0x83acc3 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:763:12 #12 0x971876 in Rf_ReplIteration /data/gannet/ripley/R/svn/R-devel/src/main/main.c:264:2 #13 0x975df0 in R_ReplConsole /data/gannet/ripley/R/svn/R-devel/src/main/main.c:314:11 #14 0x975bd5 in run_Rmainloop /data/gannet/ripley/R/svn/R-devel/src/main/main.c:1113:5 #15 0x4da35a in main /data/gannet/ripley/R/svn/R-devel/src/main/Rmain.c:29:5 #16 0x7f183d4fdf42 in __libc_start_main (/lib64/libc.so.6+0x23f42) #17 0x43036d in _start (/data/gannet/ripley/R/R-clang-SAN/bin/exec/R+0x43036d) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior surrogate.c:109:42 in branch.c:41:8: runtime error: index 3 out of bounds for type 'int [2]' #0 0x7f182c989f92 in branch /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/branch.c:41:8 #1 0x7f182c9d7d9a in rundown /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/rundown.c:26:13 #2 0x7f182c9e6239 in xval /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/xval.c:129:3 #3 0x7f182c9cf2b1 in rpart /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/rpart.c:261:6 #4 0x7f182c9d8ec9 in s_to_rp /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/s_to_rp.c:32:12 #5 0x74ba49 in do_dotCode /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c #6 0x85054e in bcEval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:7054:14 #7 0x83a685 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:688:8 #8 0x89d833 in R_execClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c #9 0x89a79a in Rf_applyClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:1779:16 #10 0x83b4eb in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:811:12 #11 0x8ab39b in do_set /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:2920:8 #12 0x83acc3 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:763:12 #13 0x971876 in Rf_ReplIteration /data/gannet/ripley/R/svn/R-devel/src/main/main.c:264:2 #14 0x975df0 in R_ReplConsole /data/gannet/ripley/R/svn/R-devel/src/main/main.c:314:11 #15 0x975bd5 in run_Rmainloop /data/gannet/ripley/R/svn/R-devel/src/main/main.c:1113:5 #16 0x4da35a in main /data/gannet/ripley/R/svn/R-devel/src/main/Rmain.c:29:5 #17 0x7f183d4fdf42 in __libc_start_main (/lib64/libc.so.6+0x23f42) #18 0x43036d in _start (/data/gannet/ripley/R/R-clang-SAN/bin/exec/R+0x43036d) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior branch.c:41:8 in branch.c:62:12: runtime error: index 4 out of bounds for type 'int [2]' #0 0x7f182c98980b in branch /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/branch.c:62:12 #1 0x7f182c9d7d9a in rundown /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/rundown.c:26:13 #2 0x7f182c9e6239 in xval /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/xval.c:129:3 #3 0x7f182c9cf2b1 in rpart /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/rpart.c:261:6 #4 0x7f182c9d8ec9 in s_to_rp /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/s_to_rp.c:32:12 #5 0x74ba49 in do_dotCode /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c #6 0x85054e in bcEval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:7054:14 #7 0x83a685 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:688:8 #8 0x89d833 in R_execClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c #9 0x89a79a in Rf_applyClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:1779:16 #10 0x83b4eb in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:811:12 #11 0x8ab39b in do_set /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:2920:8 #12 0x83acc3 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:763:12 #13 0x971876 in Rf_ReplIteration /data/gannet/ripley/R/svn/R-devel/src/main/main.c:264:2 #14 0x975df0 in R_ReplConsole /data/gannet/ripley/R/svn/R-devel/src/main/main.c:314:11 #15 0x975bd5 in run_Rmainloop /data/gannet/ripley/R/svn/R-devel/src/main/main.c:1113:5 #16 0x4da35a in main /data/gannet/ripley/R/svn/R-devel/src/main/Rmain.c:29:5 #17 0x7f183d4fdf42 in __libc_start_main (/lib64/libc.so.6+0x23f42) #18 0x43036d in _start (/data/gannet/ripley/R/R-clang-SAN/bin/exec/R+0x43036d) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior branch.c:62:12 in rpmatrix.c:75:49: runtime error: index 2 out of bounds for type 'int [2]' #0 0x7f182c9d416f in rpmatrix /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/rpmatrix.c:75:49 #1 0x7f182c9daf85 in s_to_rp2 /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/s_to_rp.c:106:5 #2 0x74dfe8 in do_dotCode /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c #3 0x85054e in bcEval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:7054:14 #4 0x83a685 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:688:8 #5 0x89d833 in R_execClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c #6 0x89a79a in Rf_applyClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:1779:16 #7 0x83b4eb in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:811:12 #8 0x8ab39b in do_set /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:2920:8 #9 0x83acc3 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:763:12 #10 0x971876 in Rf_ReplIteration /data/gannet/ripley/R/svn/R-devel/src/main/main.c:264:2 #11 0x975df0 in R_ReplConsole /data/gannet/ripley/R/svn/R-devel/src/main/main.c:314:11 #12 0x975bd5 in run_Rmainloop /data/gannet/ripley/R/svn/R-devel/src/main/main.c:1113:5 #13 0x4da35a in main /data/gannet/ripley/R/svn/R-devel/src/main/Rmain.c:29:5 #14 0x7f183d4fdf42 in __libc_start_main (/lib64/libc.so.6+0x23f42) #15 0x43036d in _start (/data/gannet/ripley/R/R-clang-SAN/bin/exec/R+0x43036d) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rpmatrix.c:75:49 in rpmatrix.c:97:49: runtime error: index 2 out of bounds for type 'int [2]' #0 0x7f182c9d54bf in rpmatrix /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/rpmatrix.c:97:49 #1 0x7f182c9daf85 in s_to_rp2 /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/s_to_rp.c:106:5 #2 0x74dfe8 in do_dotCode /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c #3 0x85054e in bcEval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:7054:14 #4 0x83a685 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:688:8 #5 0x89d833 in R_execClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c #6 0x89a79a in Rf_applyClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:1779:16 #7 0x83b4eb in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:811:12 #8 0x8ab39b in do_set /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:2920:8 #9 0x83acc3 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:763:12 #10 0x971876 in Rf_ReplIteration /data/gannet/ripley/R/svn/R-devel/src/main/main.c:264:2 #11 0x975df0 in R_ReplConsole /data/gannet/ripley/R/svn/R-devel/src/main/main.c:314:11 #12 0x975bd5 in run_Rmainloop /data/gannet/ripley/R/svn/R-devel/src/main/main.c:1113:5 #13 0x4da35a in main /data/gannet/ripley/R/svn/R-devel/src/main/Rmain.c:29:5 #14 0x7f183d4fdf42 in __libc_start_main (/lib64/libc.so.6+0x23f42) #15 0x43036d in _start (/data/gannet/ripley/R/R-clang-SAN/bin/exec/R+0x43036d) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rpmatrix.c:97:49 in > plot(fit, compress=TRUE) > text(fit, use.n=TRUE) > > > > cleanEx() > nameEx("estNodeRisk") > ### * estNodeRisk > > flush(stderr()); flush(stdout()) > > ### Name: estNodeRisk > ### Title: Estimates risk at a each leaf node in a tree. > ### Aliases: estNodeRisk > ### Keywords: tree > > ### ** Examples > > require(mlbench); data(BostonHousing) Loading required package: mlbench > #fit a tree: > cart <- itree(medv~.,BostonHousing,minsplit=25,minbucket=25,cp=0) > > #generate theta-hat values by computing average out-of-bag loss: > ## Not run: > ##D #don't run because of time to do bootstrap sampling... > ##D theta_hats <- getOOBLoss(model_tree.obj=cart.bh,data=bh,nboot=100) > ##D > ##D # Then for each leaf we estimate local risk by the mean in-node theta-hat. > ##D lre <- estNodeRisk(tree.obj=cart.bh,est_observation_loss=theta_hats$avgOOBloss) > ##D > ##D # to add the lre to the plot: > ##D plot(cart.bh, do_node_re= TRUE, uniform=TRUE) > ##D text(cart.bh, est_node_risk = lre) > ## End(Not run) > > > > cleanEx() detaching ‘package:mlbench’ > nameEx("getOOBLoss") > ### * getOOBLoss > > flush(stderr()); flush(stdout()) > > ### Name: getOOBLoss > ### Title: Gets OOB Loss for each observation in a passed data frame. > ### Aliases: getOOBLoss > ### Keywords: tree > > ### ** Examples > > require(mlbench); data(BostonHousing) Loading required package: mlbench > #fit a tree: > cart <- itree(medv~.,BostonHousing,minsplit=25,minbucket=25,cp=0) > > #generate theta-hat values by computing average out-of-bag loss: > ## Not run: > ##D theta_hats <- getOOBLoss(model_tree.obj=cart.bh,data=bh,nboot=100) > ##D > ##D # Then for each leaf we estimate local risk by the mean in-node theta-hat. > ##D lre <- estNodeRisk(tree.obj=cart.bh,est_observation_loss=theta_hats$avgOOBloss) > ##D > ##D # to add the lre to the plot: > ##D plot(cart.bh, do_node_re= TRUE, uniform=TRUE) > ##D text(cart.bh, est_node_risk = lre) > ## End(Not run) > > > > cleanEx() detaching ‘package:mlbench’ > nameEx("itree") > ### * itree > > flush(stderr()); flush(stdout()) > > ### Name: itree > ### Title: Recursive Partitioning and Regression Trees a la rpart, but with > ### some extensions targeted at growing interpretable/parsimonious trees. > ### Aliases: itree > ### Keywords: tree > > ### ** Examples > > #CART (same as rpart): > fit <- itree(Kyphosis ~ Age + Number + Start, data=kyphosis) rpmatrix.c:49:54: runtime error: index 2 out of bounds for type 'double [2]' #0 0x7f182c9d3940 in rpmatrix /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/rpmatrix.c:49:54 #1 0x7f182c9daf85 in s_to_rp2 /data/gannet/ripley/R/packages/tests-clang-SAN/itree/src/s_to_rp.c:106:5 #2 0x74dfe8 in do_dotCode /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c #3 0x85054e in bcEval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:7054:14 #4 0x83a685 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:688:8 #5 0x89d833 in R_execClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c #6 0x89a79a in Rf_applyClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:1779:16 #7 0x83b4eb in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:811:12 #8 0x8ab39b in do_set /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:2920:8 #9 0x83acc3 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:763:12 #10 0x971876 in Rf_ReplIteration /data/gannet/ripley/R/svn/R-devel/src/main/main.c:264:2 #11 0x975df0 in R_ReplConsole /data/gannet/ripley/R/svn/R-devel/src/main/main.c:314:11 #12 0x975bd5 in run_Rmainloop /data/gannet/ripley/R/svn/R-devel/src/main/main.c:1113:5 #13 0x4da35a in main /data/gannet/ripley/R/svn/R-devel/src/main/Rmain.c:29:5 #14 0x7f183d4fdf42 in __libc_start_main (/lib64/libc.so.6+0x23f42) #15 0x43036d in _start (/data/gannet/ripley/R/R-clang-SAN/bin/exec/R+0x43036d) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rpmatrix.c:49:54 in > fit2 <- itree(Kyphosis ~ Age + Number + Start, data=kyphosis, + parms=list(prior=c(.65,.35), split='information')) > fit3 <- itree(Kyphosis ~ Age + Number + Start, data=kyphosis, + control=itree.control(cp=.05)) > par(mfrow=c(1,2), xpd=NA) # otherwise on some devices the text is clipped > plot(fit) > text(fit, use.n=TRUE) > plot(fit2) > text(fit2, use.n=TRUE) > > #### new to itree: > #same example, but using one-sided extremes: > fit.ext <- itree(Kyphosis ~ Age + Number + Start, data=kyphosis,method="extremes", + parms=list(classOfInterest="absent")) > #we see buckets with every y="absent": > plot(fit.ext); text(fit.ext,use.n=TRUE) > > > library(mlbench); data(BostonHousing) > > #one sided purity: > fit4 <- itree(medv~.,BostonHousing,method="purity",minbucket=25) > > #low means tree: > fit5 <- itree(medv~.,BostonHousing,method="extremes",parms=-1,minbucket=25) > > #new variable penalty: > fit6 <- itree(medv~.,BostonHousing,penalty="newvar",interp_param1=.2) > > #ema penalty > fit7 <- itree(medv~.,BostonHousing,penalty="ema",interp_param1=.1) > > #one-sided-purity + new variable penalty: > fit8 <- itree(medv~.,BostonHousing,method="purity",penalty="newvar",interp_param1=.2) > > #one-sided extremes for classification must specify a "class of interest" > data(PimaIndiansDiabetes) > levels(PimaIndiansDiabetes$diabetes) [1] "neg" "pos" > fit9.a <- itree(diabetes~.,PimaIndiansDiabetes,minbucket=50, + method="extremes",parms=list(classOfInterest="neg")) > > plot(fit9.a); text(fit9.a) > > #can also pass the index of the class of interest in levels(). > fit9.b <- itree(diabetes~.,PimaIndiansDiabetes,minbucket=50, + method="extremes",parms=list(classOfInterest=1)) > # so fit9.a = fit9.b > > > > graphics::par(get("par.postscript", pos = 'CheckExEnv')) > cleanEx() detaching ‘package:mlbench’ > nameEx("kyphosis") > ### * kyphosis > > flush(stderr()); flush(stdout()) > > ### Name: kyphosis > ### Title: Data on Children who have had Corrective Spinal Surgery > ### Aliases: kyphosis > ### Keywords: datasets > > ### ** Examples > > #from the rpart examples: > fit <- itree(Kyphosis ~ Age + Number + Start, data=kyphosis) > fit2 <- itree(Kyphosis ~ Age + Number + Start, data=kyphosis, + parms=list(prior=c(.65,.35), split='information')) > fit3 <- itree(Kyphosis ~ Age + Number + Start, data=kyphosis, + control=itree.control(cp=.05)) > par(mfrow=c(1,2)) > plot(fit) > text(fit, use.n=TRUE) > plot(fit2) > text(fit2, use.n=TRUE) > > > > graphics::par(get("par.postscript", pos = 'CheckExEnv')) > cleanEx() > nameEx("meanvar.itree") > ### * meanvar.itree > > flush(stderr()); flush(stdout()) > > ### Name: meanvar.itree > ### Title: Mean-Variance Plot for an itree Object > ### Aliases: meanvar meanvar.itree > ### Keywords: tree > > ### ** Examples > > #the rpart package's example: > z.auto <- itree(Mileage ~ Weight, car.test.frame) > meanvar(z.auto, log='xy') Warning in meanvar.itree(z.auto, log = "xy") : meanvar is impacted by using penalties and is NOT comparable to unpenalized meanvar. > > > > cleanEx() > nameEx("path.itree") > ### * path.itree > > flush(stderr()); flush(stdout()) > > ### Name: path.itree > ### Title: Follow Paths to Selected Nodes of an itree Object > ### Aliases: path.itree > ### Keywords: tree > > ### ** Examples > > #rpart example: > fit <- itree(Kyphosis ~ Age + Number + Start, data=kyphosis) > summary(fit) Call: itree(formula = Kyphosis ~ Age + Number + Start, data = kyphosis) n= 81 CP nsplit rel error xerror xstd 1 0.17647059 0 1.0000000 1 0.2155872 2 0.01960784 1 0.8235294 1 0.2155872 3 0.01000000 4 0.7647059 1 0.2155872 Node number 1: 81 observations, complexity param=0.1764706 predicted class=absent expected loss=0.2098765 class counts: 64 17 probabilities: 0.790 0.210 left son=2 (62 obs) right son=3 (19 obs) Primary splits: Start < 8.5 to the right, improve=0.06269300, (0 missing) Number < 5.5 to the left, improve=0.02657782, (0 missing) Age < 39.5 to the left, improve=0.02086152, (0 missing) Surrogate splits: Number < 6.5 to the left, agree=0.802, adj=0.158, (0 split) Node number 2: 62 observations, complexity param=0.01960784 predicted class=absent expected loss=0.09677419 class counts: 56 6 probabilities: 0.903 0.097 left son=4 (29 obs) right son=5 (33 obs) Primary splits: Start < 14.5 to the right, improve=0.014010790, (0 missing) Age < 55 to the left, improve=0.009402466, (0 missing) Number < 4.5 to the left, improve=0.004084823, (0 missing) Surrogate splits: Number < 3.5 to the left, agree=0.645, adj=0.241, (0 split) Age < 16 to the left, agree=0.597, adj=0.138, (0 split) Node number 3: 19 observations predicted class=present expected loss=0.4210526 class counts: 8 11 probabilities: 0.421 0.579 Node number 4: 29 observations predicted class=absent expected loss=0 class counts: 29 0 probabilities: 1.000 0.000 Node number 5: 33 observations, complexity param=0.01960784 predicted class=absent expected loss=0.1818182 class counts: 27 6 probabilities: 0.818 0.182 left son=10 (12 obs) right son=11 (21 obs) Primary splits: Age < 55 to the left, improve=0.029117380, (0 missing) Start < 12.5 to the right, improve=0.006744099, (0 missing) Number < 3.5 to the right, improve=0.004094631, (0 missing) Surrogate splits: Start < 9.5 to the left, agree=0.758, adj=0.333, (0 split) Number < 5.5 to the right, agree=0.697, adj=0.167, (0 split) Node number 10: 12 observations predicted class=absent expected loss=0 class counts: 12 0 probabilities: 1.000 0.000 Node number 11: 21 observations, complexity param=0.01960784 predicted class=absent expected loss=0.2857143 class counts: 15 6 probabilities: 0.714 0.286 left son=22 (14 obs) right son=23 (7 obs) Primary splits: Age < 111 to the right, improve=0.057971010, (0 missing) Start < 12.5 to the right, improve=0.026838430, (0 missing) Number < 3.5 to the right, improve=0.002415459, (0 missing) Node number 22: 14 observations predicted class=absent expected loss=0.1428571 class counts: 12 2 probabilities: 0.857 0.143 Node number 23: 7 observations predicted class=present expected loss=0.4285714 class counts: 3 4 probabilities: 0.429 0.571 > path.itree(fit, node=c(11, 22)) node number: 11 root Start>=8.5 Start< 14.5 Age>=55 node number: 22 root Start>=8.5 Start< 14.5 Age>=55 Age>=111 > > > > cleanEx() > nameEx("plot.itree") > ### * plot.itree > > flush(stderr()); flush(stdout()) > > ### Name: plot.itree > ### Title: Plot an itree Object > ### Aliases: plot.itree > ### Keywords: tree > > ### ** Examples > > #the rpart example: > fit <- itree(Price ~ Mileage + Type + Country, cu.summary) > plot(fit, compress=TRUE) > text(fit, use.n=TRUE) > > ### new to itree, plotting node risk: > require(mlbench); data(BostonHousing) Loading required package: mlbench > #fit a tree: > cart <- itree(medv~.,BostonHousing,minsplit=25,minbucket=25,cp=0) > > #generate theta-hat values by computing average out-of-bag loss: > ## Not run: > ##D theta_hats <- getOOBLoss(model_tree.obj=cart.bh,data=bh,nboot=100) > ##D > ##D # Then for each leaf we estimate local risk by the mean in-node theta-hat. > ##D lre <- estNodeRisk(tree.obj=cart.bh,est_observation_loss=theta_hats$avgOOBloss) > ##D > ##D # to add the lre to the plot: > ##D plot(cart.bh, do_node_re= TRUE, uniform=TRUE) > ##D text(cart.bh, est_node_risk = lre) > ## End(Not run) > > #plot using highlighting for one-sided methods: > purity.tree <- itree(medv~.,BostonHousing,minsplit=25,minbucket=25,cp=0,method="purity") > plot(purity.tree,highlight.color="blue") > text(purity.tree) > > > > > cleanEx() detaching ‘package:mlbench’ > nameEx("post.itree") > ### * post.itree > > flush(stderr()); flush(stdout()) > > ### Name: post.itree > ### Title: PostScript Presentation Plot of an itree Object > ### Aliases: post.itree post > ### Keywords: tree > > ### ** Examples > > #the rpart examples: > z.auto <- itree(Mileage ~ Weight, car.test.frame) > post(z.auto, file = "") # display tree on active device > # now construct postscript version on file "pretty.ps" > # with no title > post(z.auto, file = "pretty.ps", title = " ") > z.hp <- itree(Mileage ~ Weight + HP, car.test.frame) > post(z.hp) > > > > cleanEx() > nameEx("predict.itree") > ### * predict.itree > > flush(stderr()); flush(stdout()) > > ### Name: predict.itree > ### Title: Predictions from a Fitted itree Object > ### Aliases: predict.itree > ### Keywords: tree > > ### ** Examples > > #verbatim from rpart examples: > z.auto <- itree(Mileage ~ Weight, car.test.frame) > predict(z.auto) Eagle Summit 4 Ford Escort 4 30.93333 30.93333 Ford Festiva 4 Honda Civic 4 30.93333 30.93333 Mazda Protege 4 Mercury Tracer 4 30.93333 30.93333 Nissan Sentra 4 Pontiac LeMans 4 30.93333 30.93333 Subaru Loyale 4 Subaru Justy 3 30.93333 30.93333 Toyota Corolla 4 Toyota Tercel 4 30.93333 30.93333 Volkswagen Jetta 4 Chevrolet Camaro V8 30.93333 20.40909 Dodge Daytona Ford Mustang V8 23.80000 20.40909 Ford Probe Honda Civic CRX Si 4 25.62500 30.93333 Honda Prelude Si 4WS 4 Nissan 240SX 4 25.62500 23.80000 Plymouth Laser Subaru XT 4 23.80000 30.93333 Audi 80 4 Buick Skylark 4 25.62500 25.62500 Chevrolet Beretta 4 Chrysler Le Baron V6 25.62500 23.80000 Ford Tempo 4 Honda Accord 4 23.80000 23.80000 Mazda 626 4 Mitsubishi Galant 4 23.80000 25.62500 Mitsubishi Sigma V6 Nissan Stanza 4 20.40909 23.80000 Oldsmobile Calais 4 Peugeot 405 4 25.62500 25.62500 Subaru Legacy 4 Toyota Camry 4 23.80000 23.80000 Volvo 240 4 Acura Legend V6 23.80000 20.40909 Buick Century 4 Chrysler Le Baron Coupe 23.80000 23.80000 Chrysler New Yorker V6 Eagle Premier V6 20.40909 20.40909 Ford Taurus V6 Ford Thunderbird V6 20.40909 20.40909 Hyundai Sonata 4 Mazda 929 V6 23.80000 20.40909 Nissan Maxima V6 Oldsmobile Cutlass Ciera 4 20.40909 23.80000 Oldsmobile Cutlass Supreme V6 Toyota Cressida 6 20.40909 20.40909 Buick Le Sabre V6 Chevrolet Caprice V8 20.40909 20.40909 Ford LTD Crown Victoria V8 Chevrolet Lumina APV V6 20.40909 20.40909 Dodge Grand Caravan V6 Ford Aerostar V6 20.40909 20.40909 Mazda MPV V6 Mitsubishi Wagon 4 20.40909 20.40909 Nissan Axxess 4 Nissan Van 4 20.40909 20.40909 > > fit <- itree(Kyphosis ~ Age + Number + Start, data=kyphosis) > predict(fit, type="prob") # class probabilities (default) absent present 1 0.4210526 0.5789474 2 0.8571429 0.1428571 3 0.4210526 0.5789474 4 0.4210526 0.5789474 5 1.0000000 0.0000000 6 1.0000000 0.0000000 7 1.0000000 0.0000000 8 1.0000000 0.0000000 9 1.0000000 0.0000000 10 0.4285714 0.5714286 11 0.4285714 0.5714286 12 1.0000000 0.0000000 13 0.4210526 0.5789474 14 1.0000000 0.0000000 15 1.0000000 0.0000000 16 1.0000000 0.0000000 17 1.0000000 0.0000000 18 0.8571429 0.1428571 19 1.0000000 0.0000000 20 1.0000000 0.0000000 21 1.0000000 0.0000000 22 0.4210526 0.5789474 23 0.4285714 0.5714286 24 0.4210526 0.5789474 25 0.4210526 0.5789474 26 1.0000000 0.0000000 27 0.4210526 0.5789474 28 0.4285714 0.5714286 29 1.0000000 0.0000000 30 1.0000000 0.0000000 31 1.0000000 0.0000000 32 0.8571429 0.1428571 33 0.8571429 0.1428571 34 1.0000000 0.0000000 35 0.8571429 0.1428571 36 1.0000000 0.0000000 37 1.0000000 0.0000000 38 0.4210526 0.5789474 39 1.0000000 0.0000000 40 0.4285714 0.5714286 41 0.4210526 0.5789474 42 1.0000000 0.0000000 43 0.4210526 0.5789474 44 0.4210526 0.5789474 45 1.0000000 0.0000000 46 0.8571429 0.1428571 47 1.0000000 0.0000000 48 0.8571429 0.1428571 49 0.4210526 0.5789474 50 0.8571429 0.1428571 51 0.4285714 0.5714286 52 1.0000000 0.0000000 53 0.4210526 0.5789474 54 1.0000000 0.0000000 55 1.0000000 0.0000000 56 1.0000000 0.0000000 57 1.0000000 0.0000000 58 0.4210526 0.5789474 59 1.0000000 0.0000000 60 0.4285714 0.5714286 61 0.4210526 0.5789474 62 0.4210526 0.5789474 63 0.4210526 0.5789474 64 1.0000000 0.0000000 65 1.0000000 0.0000000 66 1.0000000 0.0000000 67 1.0000000 0.0000000 68 0.8571429 0.1428571 69 1.0000000 0.0000000 70 1.0000000 0.0000000 71 0.8571429 0.1428571 72 0.8571429 0.1428571 73 1.0000000 0.0000000 74 0.8571429 0.1428571 75 1.0000000 0.0000000 76 1.0000000 0.0000000 77 0.8571429 0.1428571 78 1.0000000 0.0000000 79 0.8571429 0.1428571 80 0.4210526 0.5789474 81 1.0000000 0.0000000 > predict(fit, type="vector") # level numbers 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2 1 2 2 1 1 1 1 1 2 2 1 2 1 1 1 1 1 1 1 1 2 2 2 2 1 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 2 1 1 1 1 2 1 2 1 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 2 1 1 1 1 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 79 80 81 1 2 1 > predict(fit, type="class") # factor 1 2 3 4 5 6 7 8 9 10 present absent present present absent absent absent absent absent present 11 12 13 14 15 16 17 18 19 20 present absent present absent absent absent absent absent absent absent 21 22 23 24 25 26 27 28 29 30 absent present present present present absent present present absent absent 31 32 33 34 35 36 37 38 39 40 absent absent absent absent absent absent absent present absent present 41 42 43 44 45 46 47 48 49 50 present absent present present absent absent absent absent present absent 51 52 53 54 55 56 57 58 59 60 present absent present absent absent absent absent present absent present 61 62 63 64 65 66 67 68 69 70 present present present absent absent absent absent absent absent absent 71 72 73 74 75 76 77 78 79 80 absent absent absent absent absent absent absent absent absent present 81 absent Levels: absent present > predict(fit, type="matrix") # level number, class frequencies, probabilities 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2 1 2 2 1 1 1 1 1 2 2 1 2 1 1 1 1 1 1 1 1 2 2 2 2 1 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 2 1 1 1 1 2 1 2 1 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 2 1 1 1 1 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 79 80 81 1 2 1 > > sub <- c(sample(1:50, 25), sample(51:100, 25), sample(101:150, 25)) > fit <- itree(Species ~ ., data=iris, subset=sub) > fit n= 75 node), split, n, loss, yval, (yprob) * denotes terminal node 1) root 75 50 setosa (0.33333333 0.33333333 0.33333333) 2) Petal.Length< 2.5 25 0 setosa (1.00000000 0.00000000 0.00000000) * 3) Petal.Length>=2.5 50 25 versicolor (0.00000000 0.50000000 0.50000000) 6) Petal.Length< 4.85 26 2 versicolor (0.00000000 0.92307692 0.07692308) * 7) Petal.Length>=4.85 24 1 virginica (0.00000000 0.04166667 0.95833333) * > table(predict(fit, iris[-sub,], type="class"), iris[-sub, "Species"]) setosa versicolor virginica setosa 25 0 0 versicolor 0 22 1 virginica 0 3 24 > > > > cleanEx() > nameEx("print.itree") > ### * print.itree > > flush(stderr()); flush(stdout()) > > ### Name: print.itree > ### Title: Print an itree Object > ### Aliases: print.itree > ### Keywords: tree > > ### ** Examples > > #rpart examples: > z.auto <- itree(Mileage ~ Weight, car.test.frame) > z.auto n= 60 node), split, n, deviance, yval * denotes terminal node 1) root 60 1354.58300 24.58333 2) Weight>=2567.5 45 361.20000 22.46667 4) Weight>=3087.5 22 61.31818 20.40909 * 5) Weight< 3087.5 23 117.65220 24.43478 10) Weight>=2747.5 15 60.40000 23.80000 * 11) Weight< 2747.5 8 39.87500 25.62500 * 3) Weight< 2567.5 15 186.93330 30.93333 * > ## Not run: > ##D node), split, n, deviance, yval > ##D * denotes terminal node > ##D > ##D 1) root 60 1354.58300 24.58333 > ##D 2) Weight>=2567.5 45 361.20000 22.46667 > ##D 4) Weight>=3087.5 22 61.31818 20.40909 * > ##D 5) Weight<3087.5 23 117.65220 24.43478 > ##D 10) Weight>=2747.5 15 60.40000 23.80000 * > ##D 11) Weight<2747.5 8 39.87500 25.62500 * > ##D 3) Weight<2567.5 15 186.93330 30.93333 * > ## End(Not run) > > > cleanEx() > nameEx("printcp") > ### * printcp > > flush(stderr()); flush(stdout()) > > ### Name: printcp > ### Title: Displays CP table for Fitted itree Object > ### Aliases: printcp > ### Keywords: tree > > ### ** Examples > > #rpart's examples: > > z.auto <- itree(Mileage ~ Weight, car.test.frame) > printcp(z.auto) Warning in printcp(z.auto) : cp is impacted by using penalties and is NOT comparable to unpenalized cp's. Regression tree: itree(formula = Mileage ~ Weight, data = car.test.frame) Variables actually used in tree construction: [1] Weight Root node error: 1354.6/60 = 22.576 n= 60 CP nsplit rel error xerror xstd 1 0.595349 0 1.00000 1.03378 0.180465 2 0.134528 1 0.40465 0.58366 0.109010 3 0.012828 2 0.27012 0.44092 0.086528 4 0.010000 3 0.25729 0.44158 0.086630 > ## Not run: > ##D Regression tree: > ##D itree(formula = Mileage ~ Weight, data = car.test.frame) > ##D > ##D Variables actually used in tree construction: > ##D [1] Weight > ##D > ##D Root node error: 1354.6/60 = 22.576 > ##D > ##D CP nsplit rel error xerror xstd > ##D 1 0.595349 0 1.00000 1.03436 0.178526 > ##D 2 0.134528 1 0.40465 0.60508 0.105217 > ##D 3 0.012828 2 0.27012 0.45153 0.083330 > ##D 4 0.010000 3 0.25729 0.44826 0.076998 > ## End(Not run) > > > cleanEx() > nameEx("prune.itree") > ### * prune.itree > > flush(stderr()); flush(stdout()) > > ### Name: prune.itree > ### Title: Cost-complexity Pruning of an itree Object > ### Aliases: prune.itree prune > ### Keywords: tree > > ### ** Examples > > #the rpart example: > z.auto <- itree(Mileage ~ Weight, car.test.frame) > zp <- prune(z.auto, cp=0.1) > plot(zp) #plot smaller itree object > > > > cleanEx() > nameEx("residuals.itree") > ### * residuals.itree > > flush(stderr()); flush(stdout()) > > ### Name: residuals.itree > ### Title: Residuals From a Fitted itree Object > ### Aliases: residuals.itree > ### Keywords: tree > > ### ** Examples > > #the rpart example: > fit <- itree(skips ~ Opening + Solder + Mask + PadType + Panel, + data=solder, method='anova') > summary(residuals(fit)) Min. 1st Qu. Median Mean 3rd Qu. Max. -13.8000 -1.0361 -0.6833 0.0000 0.9639 16.2000 > plot(predict(fit),residuals(fit)) > > > > cleanEx() > nameEx("rsq.itree") > ### * rsq.itree > > flush(stderr()); flush(stdout()) > > ### Name: rsq.itree > ### Title: Plots the Approximate R-Square for the Different Splits > ### Aliases: rsq.itree > ### Keywords: tree > > ### ** Examples > > #rpart's example: > z.auto <- itree(Mileage ~ Weight, car.test.frame) > rsq.itree(z.auto) Warning in printcp(x) : cp is impacted by using penalties and is NOT comparable to unpenalized cp's. Regression tree: itree(formula = Mileage ~ Weight, data = car.test.frame) Variables actually used in tree construction: [1] Weight Root node error: 1354.6/60 = 22.576 n= 60 CP nsplit rel error xerror xstd 1 0.595349 0 1.00000 1.03378 0.180465 2 0.134528 1 0.40465 0.58366 0.109010 3 0.012828 2 0.27012 0.44092 0.086528 4 0.010000 3 0.25729 0.44158 0.086630 > > > > cleanEx() > nameEx("snip.itree") > ### * snip.itree > > flush(stderr()); flush(stdout()) > > ### Name: snip.itree > ### Title: Snip Subtrees of an 'itree' Object > ### Aliases: snip.itree > ### Keywords: tree > > ### ** Examples > > ## dataset not in R > ## same as rpart: > ## Not run: > ##D z.survey <- itree(market.survey) #grow the itree object > ##D plot(z.survey) #plot the tree > ##D z.survey2 <- snip.itree(z.survey,toss=2) #trim subtree at node 2 > ##D plot(z.survey2) #plot new tree > ##D > ##D # can also interactively select the node using the mouse in the > ##D # graphics window > ##D > ## End(Not run) > #works with itree fits as well: > z.auto <- itree(Mileage ~ Weight, method="purity",car.test.frame) > #snip off the long branch: > z.auto2 <- snip.itree(z.auto,toss=3) > > > > cleanEx() > nameEx("solder") > ### * solder > > flush(stderr()); flush(stdout()) > > ### Name: solder > ### Title: Soldering of Components on Printed-Circuit Boards > ### Aliases: solder > ### Keywords: datasets > > ### ** Examples > > #same as rpart: > fit <- itree(skips ~ Opening + Solder + Mask + PadType + Panel, + data=solder, method='anova') > summary(residuals(fit)) Min. 1st Qu. Median Mean 3rd Qu. Max. -13.8000 -1.0361 -0.6833 0.0000 0.9639 16.2000 > plot(predict(fit),residuals(fit)) > > > > cleanEx() > nameEx("splitstats") > ### * splitstats > > flush(stderr()); flush(stdout()) > > ### Name: splitstats > ### Title: Stats about a tree's splits. > ### Aliases: splitstats > ### Keywords: tree > > ### ** Examples > > require(mlbench); data(BostonHousing) Loading required package: mlbench > #fit a tree: > cart <- itree(medv~.,BostonHousing,minsplit=25,minbucket=25,cp=0) > splitstats(cart) var split.ct total.inv.depth total.node.size isroot isdepth1 1 crim 2 0.11654527 0.10512821 0 0 2 zn 0 0.00000000 0.00000000 0 0 3 indus 0 0.00000000 0.00000000 0 0 4 chas 0 0.00000000 0.00000000 0 0 5 nox 1 0.03121748 0.02222222 0 0 6 rm 3 0.36420395 0.35769231 1 1 7 age 1 0.03642040 0.03547009 0 0 8 dis 3 0.14203954 0.12820513 0 0 9 rad 0 0.00000000 0.00000000 0 0 10 tax 0 0.00000000 0.00000000 0 0 11 ptratio 0 0.00000000 0.00000000 0 0 12 b 0 0.00000000 0.00000000 0 0 13 lstat 5 0.30957336 0.35128205 0 1 > > > > cleanEx() detaching ‘package:mlbench’ > nameEx("summary.itree") > ### * summary.itree > > flush(stderr()); flush(stdout()) > > ### Name: summary.itree > ### Title: Summarize a Fitted itree Object > ### Aliases: summary.itree > ### Keywords: tree > > ### ** Examples > > #rpart's example: > z.auto <- itree(Mileage ~ Weight, car.test.frame) > summary(z.auto) Call: itree(formula = Mileage ~ Weight, data = car.test.frame) n= 60 CP nsplit rel error xerror xstd 1 0.59534912 0 1.0000000 1.0337818 0.18046532 2 0.13452819 1 0.4046509 0.5836606 0.10900973 3 0.01282843 2 0.2701227 0.4409221 0.08652804 4 0.01000000 3 0.2572943 0.4415805 0.08663003 Node number 1: 60 observations, complexity param=0.5953491 mean=24.58333, MSE=22.57639 left son=2 (45 obs) right son=3 (15 obs) Primary splits: Weight < 2567.5 to the right, improve=0.5953491, (0 missing) Node number 2: 45 observations, complexity param=0.1345282 mean=22.46667, MSE=8.026667 left son=4 (22 obs) right son=5 (23 obs) Primary splits: Weight < 3087.5 to the right, improve=0.5045118, (0 missing) Node number 3: 15 observations mean=30.93333, MSE=12.46222 Node number 4: 22 observations mean=20.40909, MSE=2.78719 Node number 5: 23 observations, complexity param=0.01282843 mean=24.43478, MSE=5.115312 left son=10 (15 obs) right son=11 (8 obs) Primary splits: Weight < 2747.5 to the right, improve=0.1476996, (0 missing) Node number 10: 15 observations mean=23.8, MSE=4.026667 Node number 11: 8 observations mean=25.625, MSE=4.984375 > > > > cleanEx() > nameEx("text.itree") > ### * text.itree > > flush(stderr()); flush(stdout()) > > ### Name: text.itree > ### Title: Place Text on a Dendrogram > ### Aliases: text.itree > ### Keywords: tree > > ### ** Examples > > # from rpart: > freen.tr <- itree(y ~ ., freeny) > plot(freen.tr) > text(freen.tr, use.n=TRUE, all=TRUE) > > ###unique to itree, plotting node risk: > require(mlbench); data(BostonHousing) Loading required package: mlbench > #fit a tree: > cart <- itree(medv~.,BostonHousing,minsplit=25,minbucket=25,cp=0) > > #generate theta-hat values by computing average out-of-bag loss: > ## Not run: > ##D #don't run it because of time to do the bootstrap... > ##D theta_hats <- getOOBLoss(model_tree.obj=cart.bh,data=bh,nboot=100) > ##D > ##D # Then for each leaf we estimate local risk by the mean in-node theta-hat. > ##D lre <- estNodeRisk(tree.obj=cart.bh,est_observation_loss=theta_hats$avgOOBloss) > ##D > ##D # to add the lre to the plot: > ##D plot(cart.bh, do_node_re= TRUE, uniform=TRUE) > ##D text(cart.bh, est_node_risk = lre) > ## End(Not run) > > > > cleanEx() detaching ‘package:mlbench’ > nameEx("xpred.itree") > ### * xpred.itree > > flush(stderr()); flush(stdout()) > > ### Name: xpred.itree > ### Title: Return Cross-Validated Predictions > ### Aliases: xpred.itree > ### Keywords: tree > > ### ** Examples > > #rpart's example: > fit <- itree(Mileage ~ Weight, car.test.frame) > xmat <- xpred.itree(fit) > xerr <- (xmat - car.test.frame$Mileage)^2 > apply(xerr, 2, sum) # cross-validated error estimate 0.79767456 0.28300396 0.04154257 0.01132626 1396.6687 773.1546 577.8990 594.1341 > > # approx same result as rel. error from printcp(fit) > apply(xerr, 2, sum)/var(car.test.frame$Mileage) 0.79767456 0.28300396 0.04154257 0.01132626 60.83306 33.67539 25.17087 25.87800 > printcp(fit) Warning in printcp(fit) : cp is impacted by using penalties and is NOT comparable to unpenalized cp's. Regression tree: itree(formula = Mileage ~ Weight, data = car.test.frame) Variables actually used in tree construction: [1] Weight Root node error: 1354.6/60 = 22.576 n= 60 CP nsplit rel error xerror xstd 1 0.595349 0 1.00000 1.03378 0.180465 2 0.134528 1 0.40465 0.58366 0.109010 3 0.012828 2 0.27012 0.44092 0.086528 4 0.010000 3 0.25729 0.44158 0.086630 > > > > ### *