-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpart.html
3350 lines (2748 loc) · 134 KB
/
rpart.html
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
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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Package 'rpart' reference manual</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<!-- styling for math. katex.min.css expects fonts in same dir so use CDN -->
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.css">
<link rel="stylesheet" type="text/css" href="https://r-universe.dev/static/R.css">
<link rel="stylesheet" type="text/css" href="https://r-universe.dev/static/prism.css">
<!-- for (future) customizations -->
<script src="https://r-universe.dev/static/manual.js"></script>
<link rel="stylesheet" type="text/css" href="https://r-universe.dev/static/manual.css?nocache=1">
</head>
<body class="postdoc macintosh">
<h1 class="manual-title">Package 'rpart'</h1>
<table class="description-table">
<tr>
<th>Title:</th>
<td class="description-title">Recursive Partitioning and Regression Trees</td>
</tr>
<tr>
<th>Description:</th>
<td class="description-description">Recursive partitioning for classification,
regression and survival trees. An implementation of most of the
functionality of the 1984 book by Breiman, Friedman, Olshen and Stone.</td>
</tr>
<tr>
<th>Authors:</th>
<td class="description-author"><span>Terry Therneau [aut],
Beth Atkinson [aut, cre],
Brian Ripley [trl] (producer of the initial R port, maintainer
1999-2017)</span></td>
</tr>
<tr>
<th>Maintainer:</th>
<td class="description-maintainer">Beth Atkinson <[email protected]></td>
</tr>
<tr>
<th>License:</th>
<td class="description-license">GPL-2 | GPL-3</td>
</tr>
<tr>
<th>Version:</th>
<td class="description-version">4.1.23</td>
</tr>
<tr>
<th>Built:</th>
<td class="description-date">2024-06-15 17:27:55 UTC</td>
</tr>
<tr>
<th>Source:</th>
<td class="description-source">CRAN</td>
</tr>
</table>
<a href="#help-index" style="color:black;"><h2 id="help-index">Help Index</h2></a>
<ul id="help-index-list">
<li class="help-index-item"><a href="#car.test.frame">Automobile Data from 'Consumer Reports' 1990</a></li>
<li class="help-index-item"><a href="#car90">Automobile Data from 'Consumer Reports' 1990</a></li>
<li class="help-index-item"><a href="#cu.summary">Automobile Data from 'Consumer Reports' 1990</a></li>
<li class="help-index-item"><a href="#kyphosis">Data on Children who have had Corrective Spinal Surgery</a></li>
<li class="help-index-item"><a href="#labels.rpart">
Create Split Labels For an Rpart Object
</a></li>
<li class="help-index-item"><a href="#meanvar.rpart">
Mean-Variance Plot for an Rpart Object
</a></li>
<li class="help-index-item"><a href="#na.rpart">
Handles Missing Values in an Rpart Object
</a></li>
<li class="help-index-item"><a href="#path.rpart">
Follow Paths to Selected Nodes of an Rpart Object
</a></li>
<li class="help-index-item"><a href="#plot.rpart">
Plot an Rpart Object
</a></li>
<li class="help-index-item"><a href="#plotcp">
Plot a Complexity Parameter Table for an Rpart Fit
</a></li>
<li class="help-index-item"><a href="#post.rpart">
PostScript Presentation Plot of an Rpart Object
</a></li>
<li class="help-index-item"><a href="#predict.rpart">
Predictions from a Fitted Rpart Object
</a></li>
<li class="help-index-item"><a href="#print.rpart">
Print an Rpart Object
</a></li>
<li class="help-index-item"><a href="#printcp">
Displays CP table for Fitted Rpart Object
</a></li>
<li class="help-index-item"><a href="#prune.rpart">
Cost-complexity Pruning of an Rpart Object
</a></li>
<li class="help-index-item"><a href="#residuals.rpart">
Residuals From a Fitted Rpart Object
</a></li>
<li class="help-index-item"><a href="#rpart">
Recursive Partitioning and Regression Trees
</a></li>
<li class="help-index-item"><a href="#rpart.control">
Control for Rpart Fits
</a></li>
<li class="help-index-item"><a href="#rpart.exp">Initialization function for exponential fitting</a></li>
<li class="help-index-item"><a href="#rpart.object">
Recursive Partitioning and Regression Trees Object
</a></li>
<li class="help-index-item"><a href="#rsq.rpart">
Plots the Approximate R-Square for the Different Splits
</a></li>
<li class="help-index-item"><a href="#snip.rpart">
Snip Subtrees of an Rpart Object
</a></li>
<li class="help-index-item"><a href="#solder.balance">Soldering of Components on Printed-Circuit Boards</a></li>
<li class="help-index-item"><a href="#stagec">Stage C Prostate Cancer</a></li>
<li class="help-index-item"><a href="#summary.rpart">
Summarize a Fitted Rpart Object
</a></li>
<li class="help-index-item"><a href="#text.rpart">
Place Text on a Dendrogram Plot
</a></li>
<li class="help-index-item"><a href="#xpred.rpart">
Return Cross-Validated Predictions
</a></li>
</ul>
<hr>
<div class="manual-pages-content">
<div class="container manual-page" id="car.test.frame"><div class="page-main">
<a href="#car.test.frame" class="help-page-title"><h2>Automobile Data from 'Consumer Reports' 1990</h2></a>
<h3>Description</h3>
<p>The <code>car.test.frame</code> data frame has 60 rows and 8 columns,
giving data on makes of cars taken from the April, 1990 issue of
<em>Consumer Reports</em>. This is part of a larger dataset, some
columns of which are given in <code><a href="#cu.summary">cu.summary</a></code>.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">car.test.frame
</code><code class="language-r">car.test.frame</code></pre>
<h3>Format</h3>
<p>This data frame contains the following columns:
</p>
<dl>
<dt><code>Price</code></dt>
<dd>
<p>a numeric vector giving the list price in US dollars of a standard model
</p>
</dd>
<dt><code>Country</code></dt>
<dd>
<p>of origin, a factor with levels
‘<span class="samp">France</span>’,
‘<span class="samp">Germany</span>’,
‘<span class="samp">Japan</span>’ ,
‘<span class="samp">Japan/USA</span>’,
‘<span class="samp">Korea</span>’,
‘<span class="samp">Mexico</span>’,
‘<span class="samp">Sweden</span>’ and
‘<span class="samp">USA</span>’
</p>
</dd>
<dt><code>Reliability</code></dt>
<dd>
<p>a numeric vector coded <code>1</code> to <code>5</code>.
</p>
</dd>
<dt><code>Mileage</code></dt>
<dd>
<p>fuel consumption miles per US gallon, as tested.
</p>
</dd>
<dt><code>Type</code></dt>
<dd>
<p>a factor with levels
<code>Compact</code>
<code>Large</code>
<code>Medium</code>
<code>Small</code>
<code>Sporty</code>
<code>Van</code>
</p>
</dd>
<dt><code>Weight</code></dt>
<dd>
<p>kerb weight in pounds.
</p>
</dd>
<dt><code>Disp.</code></dt>
<dd>
<p>the engine capacity (displacement) in litres.
</p>
</dd>
<dt><code>HP</code></dt>
<dd>
<p>the net horsepower of the vehicle.
</p>
</dd>
</dl>
<h3>Source</h3>
<p><em>Consumer Reports</em>, April, 1990, pp. 235–288 quoted in
</p>
<p>John M. Chambers and Trevor J. Hastie eds. (1992)
<em>Statistical Models in S</em>, Wadsworth and Brooks/Cole,
Pacific Grove, CA, pp. 46–47.
</p>
<h3>See Also</h3>
<p><code><a href="#car90">car90</a></code>,
<code><a href="#cu.summary">cu.summary</a></code>
</p>
<h3>Examples</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">z.auto <- rpart(Mileage ~ Weight, car.test.frame)
summary(z.auto)
</code><code class="language-r">z.auto <span class="token operator"><-</span> rpart<span class="token punctuation">(</span>Mileage <span class="token operator">~</span> Weight<span class="token punctuation">,</span> car.test.frame<span class="token punctuation">)</span>
summary<span class="token punctuation">(</span>z.auto<span class="token punctuation">)</span></code></pre>
<hr>
</div></div>
<div class="container manual-page" id="car90"><div class="page-main">
<a href="#car90" class="help-page-title"><h2>Automobile Data from 'Consumer Reports' 1990</h2></a>
<h3>Description</h3>
<p>Data on 111 cars, taken from pages 235–255, 281–285 and 287–288 of the
April 1990 <em>Consumer Reports</em> Magazine.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">data(car90)</code><code class="language-r">data<span class="token punctuation">(</span>car90<span class="token punctuation">)</span></code></pre>
<h3>Format</h3>
<p>The data frame contains the following columns
</p>
<dl>
<dt>Country</dt>
<dd>
<p>a factor giving the country in which the car was
manufactured</p>
</dd>
<dt>Disp</dt>
<dd>
<p>engine displacement in cubic inches</p>
</dd>
<dt>Disp2</dt>
<dd>
<p>engine displacement in liters</p>
</dd>
<dt>Eng.Rev</dt>
<dd>
<p>engine revolutions per mile, or engine speed at 60 mph</p>
</dd>
<dt>Front.Hd</dt>
<dd>
<p>distance between the car's head-liner and the head
of a 5 ft. 9 in. front seat passenger, in inches, as measured by CU</p>
</dd>
<dt>Frt.Leg.Room</dt>
<dd>
<p>maximum front leg room, in inches, as measured by CU</p>
</dd>
<dt>Frt.Shld</dt>
<dd>
<p>front shoulder room, in inches, as measured by CU</p>
</dd>
<dt>Gear.Ratio</dt>
<dd>
<p>the overall gear ratio, high gear, for manual transmission</p>
</dd>
<dt>Gear2</dt>
<dd>
<p>the overall gear ratio, high gear, for automatic transmission</p>
</dd>
<dt>HP</dt>
<dd>
<p>net horsepower</p>
</dd>
<dt>HP.revs</dt>
<dd>
<p>the red line—the maximum safe engine speed in rpm</p>
</dd>
<dt>Height</dt>
<dd>
<p>height of car, in inches, as supplied by manufacturer</p>
</dd>
<dt>Length</dt>
<dd>
<p>overall length, in inches, as supplied by manufacturer</p>
</dd>
<dt>Luggage</dt>
<dd>
<p>luggage space</p>
</dd>
<dt>Mileage</dt>
<dd>
<p>a numeric vector of gas mileage in miles/gallon as
tested by CU; contains NAs.</p>
</dd>
<dt>Model2</dt>
<dd>
<p>alternate name, if the car was sold under two labels</p>
</dd>
<dt>Price</dt>
<dd>
<p>list price with standard equipment, in dollars</p>
</dd>
<dt>Rear.Hd</dt>
<dd>
<p>distance between the car's head-liner and the head of
a 5 ft 9 in. rear seat passenger, in inches, as measured by CU</p>
</dd>
<dt>Rear.Seating</dt>
<dd>
<p>rear fore-and-aft seating room, in inches,
as measured by CU</p>
</dd>
<dt>RearShld</dt>
<dd>
<p>rear shoulder room, in inches, as measured by CU</p>
</dd>
<dt>Reliability</dt>
<dd>
<p>an ordered factor with levels ‘<span class="samp">Much worse</span>’ <
‘<span class="samp">worse</span>’ < ‘<span class="samp">average</span>’ < ‘<span class="samp">better</span>’ < ‘<span class="samp">Much
better</span>’: contains <code>NA</code>s.</p>
</dd>
<dt>Rim</dt>
<dd>
<p>factor giving the rim size</p>
</dd>
<dt>Sratio.m</dt>
<dd>
<p>Number of turns of the steering
wheel required for a turn of 30 foot radius, manual steering</p>
</dd>
<dt>Sratio.p</dt>
<dd>
<p>Number of turns of the steering
wheel required for a turn of 30 foot radius, power steering</p>
</dd>
<dt>Steering</dt>
<dd>
<p>steering type offered: manual, power, or both</p>
</dd>
<dt>Tank</dt>
<dd>
<p>fuel refill capacity in gallons</p>
</dd>
<dt>Tires</dt>
<dd>
<p>factor giving tire size</p>
</dd>
<dt>Trans1</dt>
<dd>
<p>manual transmission, a factor with levels ‘<span class="samp"></span>’,
‘<span class="samp">man.4</span>’, ‘<span class="samp">man.5</span>’ and ‘<span class="samp">man.6</span>’</p>
</dd>
<dt>Trans2</dt>
<dd>
<p>automatic transmission, a factor with levels ‘<span class="samp"></span>’,
‘<span class="samp">auto.3</span>’, ‘<span class="samp">auto.4</span>’, and ‘<span class="samp">auto.CVT</span>’. No car is
missing both the manual and automatic transmission variables, but
several had both as options</p>
</dd>
<dt>Turning</dt>
<dd>
<p>the radius of the turning circle in feet</p>
</dd>
<dt>Type</dt>
<dd>
<p>a factor giving the general type of car.
The levels are: ‘<span class="samp">Small</span>’, ‘<span class="samp">Sporty</span>’, ‘<span class="samp">Compact</span>’, ‘<span class="samp">Medium</span>’, ‘<span class="samp">Large</span>’, ‘<span class="samp">Van</span>’</p>
</dd>
<dt>Weight</dt>
<dd>
<p>an order statistic giving the relative weights of the
cars; 1 is the lightest and 111 is the heaviest</p>
</dd>
<dt>Wheel.base</dt>
<dd>
<p>length of wheelbase, in inches, as supplied by manufacturer</p>
</dd>
<dt>Width</dt>
<dd>
<p>width of car, in inches, as supplied by manufacturer</p>
</dd>
</dl>
<h3>Source</h3>
<p>This is derived (with permission) from the data set <code>car.all</code> in
S-PLUS, but with some further clean up of variable names and definitions.
</p>
<h3>See Also</h3>
<p><code><a href="#car.test.frame">car.test.frame</a></code>,
<code><a href="#cu.summary">cu.summary</a></code> for extracts from other versions of the dataset.
</p>
<h3>Examples</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">data(car90)
plot(car90$Price/1000, car90$Weight,
xlab = "Price (thousands)", ylab = "Weight (lbs)")
mlowess <- function(x, y, ...) {
keep <- !(is.na(x) | is.na(y))
lowess(x[keep], y[keep], ...)
}
with(car90, lines(mlowess(Price/1000, Weight, f = 0.5)))
</code><code class="language-r">data<span class="token punctuation">(</span>car90<span class="token punctuation">)</span>
plot<span class="token punctuation">(</span>car90<span class="token operator">$</span>Price<span class="token operator">/</span><span class="token number">1000</span><span class="token punctuation">,</span> car90<span class="token operator">$</span>Weight<span class="token punctuation">,</span>
xlab <span class="token operator">=</span> <span class="token string">"Price (thousands)"</span><span class="token punctuation">,</span> ylab <span class="token operator">=</span> <span class="token string">"Weight (lbs)"</span><span class="token punctuation">)</span>
mlowess <span class="token operator"><-</span> <span class="token keyword">function</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token ellipsis">...</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
keep <span class="token operator"><-</span> <span class="token operator">!</span><span class="token punctuation">(</span>is.na<span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token operator">|</span> is.na<span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">)</span>
lowess<span class="token punctuation">(</span>x<span class="token punctuation">[</span>keep<span class="token punctuation">]</span><span class="token punctuation">,</span> y<span class="token punctuation">[</span>keep<span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token ellipsis">...</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
with<span class="token punctuation">(</span>car90<span class="token punctuation">,</span> lines<span class="token punctuation">(</span>mlowess<span class="token punctuation">(</span>Price<span class="token operator">/</span><span class="token number">1000</span><span class="token punctuation">,</span> Weight<span class="token punctuation">,</span> f <span class="token operator">=</span> <span class="token number">0.5</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span></code></pre>
<hr>
</div></div>
<div class="container manual-page" id="cu.summary"><div class="page-main">
<a href="#cu.summary" class="help-page-title"><h2>Automobile Data from 'Consumer Reports' 1990</h2></a>
<h3>Description</h3>
<p>The <code>cu.summary</code> data frame has 117 rows and 5 columns,
giving data on makes of cars taken from the April, 1990 issue of
<em>Consumer Reports</em>.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">cu.summary
</code><code class="language-r">cu.summary</code></pre>
<h3>Format</h3>
<p>This data frame contains the following columns:
</p>
<dl>
<dt><code>Price</code></dt>
<dd>
<p>a numeric vector giving the list price in US dollars of a standard model
</p>
</dd>
<dt><code>Country</code></dt>
<dd>
<p>of origin, a factor with levels
‘<span class="samp">Brazil</span>’,
‘<span class="samp">England</span>’,
‘<span class="samp">France</span>’,
‘<span class="samp">Germany</span>’,
‘<span class="samp">Japan</span>’,
‘<span class="samp">Japan/USA</span>’,
‘<span class="samp">Korea</span>’,
‘<span class="samp">Mexico</span>’,
‘<span class="samp">Sweden</span>’ and
‘<span class="samp">USA</span>’
</p>
</dd>
<dt><code>Reliability</code></dt>
<dd>
<p>an ordered factor with levels
‘<span class="samp">Much worse</span>’ < ‘<span class="samp">worse</span>’ < ‘<span class="samp">average</span>’ < ‘<span class="samp">better</span>’ < ‘<span class="samp">Much better</span>’
</p>
</dd>
<dt><code>Mileage</code></dt>
<dd>
<p>fuel consumption miles per US gallon, as tested.
</p>
</dd>
<dt><code>Type</code></dt>
<dd>
<p>a factor with levels
<code>Compact</code>
<code>Large</code>
<code>Medium</code>
<code>Small</code>
<code>Sporty</code>
<code>Van</code>
</p>
</dd>
</dl>
<h3>Source</h3>
<p><em>Consumer Reports</em>, April, 1990, pp. 235–288 quoted in
</p>
<p>John M. Chambers and Trevor J. Hastie eds. (1992)
<em>Statistical Models in S</em>, Wadsworth and Brooks/Cole,
Pacific Grove, CA, pp. 46–47.
</p>
<h3>See Also</h3>
<p><code><a href="#car.test.frame">car.test.frame</a></code>,
<code><a href="#car90">car90</a></code>
</p>
<h3>Examples</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">fit <- rpart(Price ~ Mileage + Type + Country, cu.summary)
par(xpd = TRUE)
plot(fit, compress = TRUE)
text(fit, use.n = TRUE)
</code><code class="language-r">fit <span class="token operator"><-</span> rpart<span class="token punctuation">(</span>Price <span class="token operator">~</span> Mileage <span class="token operator">+</span> Type <span class="token operator">+</span> Country<span class="token punctuation">,</span> cu.summary<span class="token punctuation">)</span>
par<span class="token punctuation">(</span>xpd <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span>
plot<span class="token punctuation">(</span>fit<span class="token punctuation">,</span> compress <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span>
text<span class="token punctuation">(</span>fit<span class="token punctuation">,</span> use.n <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span></code></pre>
<hr>
</div></div>
<div class="container manual-page" id="kyphosis"><div class="page-main">
<a href="#kyphosis" class="help-page-title"><h2>Data on Children who have had Corrective Spinal Surgery</h2></a>
<h3>Description</h3>
<p>The <code>kyphosis</code> data frame has 81 rows and 4 columns.
representing data on children who have had corrective spinal surgery
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">kyphosis
</code><code class="language-r">kyphosis</code></pre>
<h3>Format</h3>
<p>This data frame contains the following columns:
</p>
<dl>
<dt><code>Kyphosis</code></dt>
<dd>
<p>a factor with levels
<code>absent</code>
<code>present</code>
indicating if a kyphosis (a type of deformation)
was present after the operation.
</p>
</dd>
<dt><code>Age</code></dt>
<dd>
<p>in months
</p>
</dd>
<dt><code>Number</code></dt>
<dd>
<p>the number of vertebrae involved
</p>
</dd>
<dt><code>Start</code></dt>
<dd>
<p>the number of the first (topmost) vertebra operated on.
</p>
</dd>
</dl>
<h3>Source</h3>
<p>John M. Chambers and Trevor J. Hastie eds. (1992)
<em>Statistical Models in S</em>, Wadsworth and Brooks/Cole,
Pacific Grove, CA.
</p>
<h3>Examples</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)
fit2 <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis,
parms = list(prior = c(0.65, 0.35), split = "information"))
fit3 <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis,
control = rpart.control(cp = 0.05))
par(mfrow = c(1,2), xpd = TRUE)
plot(fit)
text(fit, use.n = TRUE)
plot(fit2)
text(fit2, use.n = TRUE)
</code><code class="language-r">fit <span class="token operator"><-</span> rpart<span class="token punctuation">(</span>Kyphosis <span class="token operator">~</span> Age <span class="token operator">+</span> Number <span class="token operator">+</span> Start<span class="token punctuation">,</span> data <span class="token operator">=</span> kyphosis<span class="token punctuation">)</span>
fit2 <span class="token operator"><-</span> rpart<span class="token punctuation">(</span>Kyphosis <span class="token operator">~</span> Age <span class="token operator">+</span> Number <span class="token operator">+</span> Start<span class="token punctuation">,</span> data <span class="token operator">=</span> kyphosis<span class="token punctuation">,</span>
parms <span class="token operator">=</span> list<span class="token punctuation">(</span>prior <span class="token operator">=</span> c<span class="token punctuation">(</span><span class="token number">0.65</span><span class="token punctuation">,</span> <span class="token number">0.35</span><span class="token punctuation">)</span><span class="token punctuation">,</span> split <span class="token operator">=</span> <span class="token string">"information"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
fit3 <span class="token operator"><-</span> rpart<span class="token punctuation">(</span>Kyphosis <span class="token operator">~</span> Age <span class="token operator">+</span> Number <span class="token operator">+</span> Start<span class="token punctuation">,</span> data<span class="token operator">=</span>kyphosis<span class="token punctuation">,</span>
control <span class="token operator">=</span> rpart.control<span class="token punctuation">(</span>cp <span class="token operator">=</span> <span class="token number">0.05</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
par<span class="token punctuation">(</span>mfrow <span class="token operator">=</span> c<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span> xpd <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span>
plot<span class="token punctuation">(</span>fit<span class="token punctuation">)</span>
text<span class="token punctuation">(</span>fit<span class="token punctuation">,</span> use.n <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span>
plot<span class="token punctuation">(</span>fit2<span class="token punctuation">)</span>
text<span class="token punctuation">(</span>fit2<span class="token punctuation">,</span> use.n <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span></code></pre>
<hr>
</div></div>
<div class="container manual-page" id="labels.rpart"><div class="page-main">
<a href="#labels.rpart" class="help-page-title"><h2>
Create Split Labels For an Rpart Object
</h2></a>
<h3>Description</h3>
<p>This function provides labels for the branches of an <code>rpart</code> tree.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">## S3 method for class 'rpart'
labels(object, digits = 4, minlength = 1L, pretty, collapse = TRUE, ...)
</code><code class="language-r"><span class="token comment">## S3 method for class 'rpart'</span>
labels<span class="token punctuation">(</span>object<span class="token punctuation">,</span> digits <span class="token operator">=</span> <span class="token number">4</span><span class="token punctuation">,</span> minlength <span class="token operator">=</span> <span class="token number">1L</span><span class="token punctuation">,</span> pretty<span class="token punctuation">,</span> collapse <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">,</span> <span class="token ellipsis">...</span><span class="token punctuation">)</span></code></pre>
<h3 class="r-arguments-title">Arguments</h3>
<table>
<tr>
<td><code id="object">object</code></td>
<td>
<p>fitted model object of class <code>"rpart"</code>. This is assumed to be the
result of some function that produces an object with the same named
components as that returned by the <code>rpart</code> function.
</p>
</td>
</tr>
<tr>
<td><code id="digits">digits</code></td>
<td>
<p>the number of digits to be used for numeric values.
All of the <code>rpart</code> functions that call labels
explicitly set this value, with <code>options("digits")</code>
as the default.
</p>
</td>
</tr>
<tr>
<td><code id="minlength">minlength</code></td>
<td>
<p>the minimum length for abbreviation of character or factor variables.
If <code>0</code> no abbreviation is done; if <code>1</code> single English letters are
used, first lower case than upper case (with a maximum of 52
levels). If the value is greater than , the <code><a href="https://r-universe.dev/manuals/base.html#abbreviate">abbreviate</a></code>
function is used, passed the <code>minlength</code> argument.
</p>
</td>
</tr>
<tr>
<td><code id="pretty">pretty</code></td>
<td>
<p>an argument included for compatibility with the original Splus tree package:
<code>pretty = 0</code> implies <code>minlength = 0L</code>,
<code>pretty = NULL</code> implies <code>minlength = 1L</code>, and
<code>pretty = TRUE</code> implies <code>minlength = 4L</code>.
</p>
</td>
</tr>
<tr>
<td><code id="collapse">collapse</code></td>
<td>
<p>logical. The returned set of labels is always of the same length as
the number of nodes in the tree.
</p>
<p>If <code>collapse = TRUE</code> (default),
the returned value is a vector of labels for the branch leading into
each node, with <code>"root"</code> as the label for the top node.
</p>
<p>If <code>FALSE</code>, the returned value is a two
column matrix of labels for the left and right branches leading
out from each node, with <code>"leaf"</code> as the branch labels for terminal
nodes.
</p>
</td>
</tr>
<tr>
<td><code id="...">...</code></td>
<td>
<p>optional arguments to <code>abbreviate</code>.</p>
</td>
</tr>
</table>
<h3>Value</h3>
<p>Vector of split labels (<code>collapse = TRUE</code>) or matrix of left and
right splits (<code>collapse = FALSE</code>) for the supplied <code>rpart</code>
object. This function is called by printing methods for <code>rpart</code>
and is not intended to be called directly by the users.
</p>
<h3>See Also</h3>
<p><code><a href="https://r-universe.dev/manuals/base.html#abbreviate">abbreviate</a></code>
</p>
<hr>
</div></div>
<div class="container manual-page" id="meanvar.rpart"><div class="page-main">
<a href="#meanvar.rpart" class="help-page-title"><h2>
Mean-Variance Plot for an Rpart Object
</h2></a>
<h3>Description</h3>
<p>Creates a plot on the current graphics device of the deviance of the
node divided by the number of observations at the node. Also returns
the node number.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">meanvar(tree, ...)
## S3 method for class 'rpart'
meanvar(tree, xlab = "ave(y)", ylab = "ave(deviance)", ...)
</code><code class="language-r">meanvar<span class="token punctuation">(</span>tree<span class="token punctuation">,</span> <span class="token ellipsis">...</span><span class="token punctuation">)</span>
<span class="token comment">## S3 method for class 'rpart'</span>
meanvar<span class="token punctuation">(</span>tree<span class="token punctuation">,</span> xlab <span class="token operator">=</span> <span class="token string">"ave(y)"</span><span class="token punctuation">,</span> ylab <span class="token operator">=</span> <span class="token string">"ave(deviance)"</span><span class="token punctuation">,</span> <span class="token ellipsis">...</span><span class="token punctuation">)</span></code></pre>
<h3 class="r-arguments-title">Arguments</h3>
<table>
<tr>
<td><code id="tree">tree</code></td>
<td>
<p>fitted model object of class <code>"rpart"</code>. This is assumed to be the result
of some function that produces an object with the same named
components as that returned by the <code>rpart</code> function.
</p>
</td>
</tr>
<tr>
<td><code id="xlab">xlab</code></td>
<td>
<p>x-axis label for the plot.
</p>
</td>
</tr>
<tr>
<td><code id="ylab">ylab</code></td>
<td>
<p>y-axis label for the plot.
</p>
</td>
</tr>
<tr>
<td><code id="...">...</code></td>
<td>
<p>additional graphical parameters may be supplied as arguments to this function.
</p>
</td>
</tr>
</table>
<h3>Value</h3>
<p>an invisible list containing the following vectors is returned.
</p>
<table>
<tr>
<td><code>x</code></td>
<td>
<p>fitted value at terminal nodes (<code>yval</code>).
</p>
</td>
</tr>
<tr>
<td><code>y</code></td>
<td>
<p>deviance of node divided by number of observations at node.
</p>
</td>
</tr>
<tr>
<td><code>label</code></td>
<td>
<p>node number.
</p>
</td>
</tr>
</table>
<h3>Side Effects</h3>
<p>a plot is put on the current graphics device.
</p>
<h3>See Also</h3>
<p><code><a href="#plot.rpart">plot.rpart</a></code>.
</p>
<h3>Examples</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">z.auto <- rpart(Mileage ~ Weight, car.test.frame)
meanvar(z.auto, log = 'xy')
</code><code class="language-r">z.auto <span class="token operator"><-</span> rpart<span class="token punctuation">(</span>Mileage <span class="token operator">~</span> Weight<span class="token punctuation">,</span> car.test.frame<span class="token punctuation">)</span>
meanvar<span class="token punctuation">(</span>z.auto<span class="token punctuation">,</span> log <span class="token operator">=</span> <span class="token string">'xy'</span><span class="token punctuation">)</span></code></pre>
<hr>
</div></div>
<div class="container manual-page" id="na.rpart"><div class="page-main">
<a href="#na.rpart" class="help-page-title"><h2>
Handles Missing Values in an Rpart Object
</h2></a>
<h3>Description</h3>
<p>Handles missing values in an <code>"rpart"</code> object.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">na.rpart(x)
</code><code class="language-r">na.rpart<span class="token punctuation">(</span>x<span class="token punctuation">)</span></code></pre>
<h3 class="r-arguments-title">Arguments</h3>
<table><tr>
<td><code id="x">x</code></td>
<td>
<p>a model frame.
</p>
</td>
</tr></table>
<h3>Details</h3>
<p>Default function that handles missing values when calling the
function <code>rpart</code>.
</p>
<p>It omits cases where part of the response is missing or all the
explanatory variables are missing.
</p>
<hr>
</div></div>
<div class="container manual-page" id="path.rpart"><div class="page-main">
<a href="#path.rpart" class="help-page-title"><h2>
Follow Paths to Selected Nodes of an Rpart Object
</h2></a>
<h3>Description</h3>
<p>Returns a names list where each element contains the splits on the
path from the root to the selected nodes.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">path.rpart(tree, nodes, pretty = 0, print.it = TRUE)
</code><code class="language-r">path.rpart<span class="token punctuation">(</span>tree<span class="token punctuation">,</span> nodes<span class="token punctuation">,</span> pretty <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">,</span> print.it <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span></code></pre>
<h3 class="r-arguments-title">Arguments</h3>
<table>
<tr>
<td><code id="tree">tree</code></td>
<td>
<p>fitted model object of class <code>"rpart"</code>. This is assumed to be the
result of some function that produces an object with the same named
components as that returned by the <code>rpart</code> function.
</p>
</td>
</tr>
<tr>
<td><code id="nodes">nodes</code></td>
<td>
<p>an integer vector containing indices (node numbers) of all nodes for
which paths are desired. If missing, user selects nodes as described
below.
</p>
</td>
</tr>
<tr>
<td><code id="pretty">pretty</code></td>
<td>
<p>an integer denoting the extent to which factor levels in split labels
will be abbreviated. A value of (0) signifies no abbreviation. A
<code>NULL</code>, the default, signifies using elements of letters to represent
the different factor levels.
</p>
</td>
</tr>
<tr>
<td><code id="print.it">print.it</code></td>
<td>
<p>Logical. Denotes whether paths will be printed out as
nodes are interactively selected. Irrelevant if <code>nodes</code>
argument is supplied.
</p>
</td>
</tr>
</table>
<h3>Details</h3>
<p>The function has a required argument as an <code>rpart</code> object and
a list of nodes as optional arguments. Omitting a list of
nodes will cause the function to wait for the user to
select nodes from the dendrogram. It will return a list,
with one component for each node specified or selected.
The component contains the sequence of splits leading to
that node. In the graphical interaction, the individual
paths are printed out as nodes are selected.
</p>
<h3>Value</h3>
<p>A named (by node) list, each element of which contains all
the splits on the path from the root to the specified or
selected nodes.
</p>
<h3>Graphical Interaction</h3>
<p>A dendrogram of the <code>rpart</code> object is expected to be visible on
the graphics device, and a graphics input device (e.g. a mouse) is
required. Clicking (the selection button) on a node selects that
node. This process may be repeated any number of times. Clicking the
exit button will stop the selection process and return the list of
paths.
</p>
<h3>References</h3>
<p>This function was modified from <code>path.tree</code> in S.
</p>
<h3>See Also</h3>
<p><code><a href="#rpart">rpart</a></code>
</p>
<h3>Examples</h3>
<pre class="language-r"><code class="language-r-input" hidden="hidden">fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)
print(fit)
path.rpart(fit, nodes = c(11, 22))
</code><code class="language-r">fit <span class="token operator"><-</span> rpart<span class="token punctuation">(</span>Kyphosis <span class="token operator">~</span> Age <span class="token operator">+</span> Number <span class="token operator">+</span> Start<span class="token punctuation">,</span> data <span class="token operator">=</span> kyphosis<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>fit<span class="token punctuation">)</span>
path.rpart<span class="token punctuation">(</span>fit<span class="token punctuation">,</span> nodes <span class="token operator">=</span> c<span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">,</span> <span class="token number">22</span><span class="token punctuation">)</span><span class="token punctuation">)</span></code></pre>
<hr>
</div></div>