|
a |
|
b/partyMod/man/BinaryTree-class.Rd |
|
|
1 |
\name{BinaryTree Class} |
|
|
2 |
\docType{class} |
|
|
3 |
\alias{BinaryTree-class} |
|
|
4 |
\alias{weights} |
|
|
5 |
\alias{weights-methods} |
|
|
6 |
\alias{weights,BinaryTree-method} |
|
|
7 |
\alias{show,BinaryTree-method} |
|
|
8 |
\alias{where} |
|
|
9 |
\alias{where-methods} |
|
|
10 |
\alias{where,BinaryTree-method} |
|
|
11 |
\alias{response} |
|
|
12 |
\alias{response-methods} |
|
|
13 |
\alias{response,BinaryTree-method} |
|
|
14 |
\alias{nodes} |
|
|
15 |
\alias{nodes-methods} |
|
|
16 |
\alias{nodes,BinaryTree,integer-method} |
|
|
17 |
\alias{nodes,BinaryTree,numeric-method} |
|
|
18 |
\alias{treeresponse} |
|
|
19 |
\alias{treeresponse-methods} |
|
|
20 |
\alias{treeresponse,BinaryTree-method} |
|
|
21 |
\title{Class "BinaryTree"} |
|
|
22 |
\description{A class for representing binary trees.} |
|
|
23 |
\section{Objects from the Class}{ |
|
|
24 |
Objects can be created by calls of the form \code{new("BinaryTree", ...)}. |
|
|
25 |
The most important slot is \code{tree}, a (recursive) list with elements |
|
|
26 |
\describe{ |
|
|
27 |
\item{nodeID}{ an integer giving the number of the node, starting with |
|
|
28 |
\code{1} in the root node.} |
|
|
29 |
\item{weights}{ the case weights (of the learning sample) corresponding to |
|
|
30 |
this node.} |
|
|
31 |
\item{criterion}{ a list with test statistics and p-values for each partial |
|
|
32 |
hypothesis.} |
|
|
33 |
\item{terminal}{ a logical specifying if this is a terminal node.} |
|
|
34 |
\item{psplit}{ primary split: a list with elements \code{variableID} (the |
|
|
35 |
number of the input variable splitted), \code{ordered} (a |
|
|
36 |
logical whether the input variable is ordered), |
|
|
37 |
\code{splitpoint} (the cutpoint or set of levels to the left), |
|
|
38 |
\code{splitstatistics} saves the process of standardized |
|
|
39 |
two-sample statistics the split point estimation is based on. |
|
|
40 |
The logical \code{toleft} determines if observations |
|
|
41 |
go left or right down the tree. For nominal splits, the slot |
|
|
42 |
\code{table} is a vector being greater zero if the |
|
|
43 |
corresponding level is available in the corresponding node.} |
|
|
44 |
\item{ssplits}{ a list of surrogate splits, each with the same elements as |
|
|
45 |
\code{psplit}.} |
|
|
46 |
\item{prediction}{ the prediction of the node: the mean for numeric |
|
|
47 |
responses and the conditional class probabilities for |
|
|
48 |
nominal or ordered respones. For censored responses, |
|
|
49 |
this is the mean of the logrank scores and useless as |
|
|
50 |
such.} |
|
|
51 |
\item{left}{ a list representing the left daughter node. } |
|
|
52 |
\item{right}{ a list representing the right daugther node.} |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
Please note that this data structure may be subject to change in future |
|
|
56 |
releases of the package. |
|
|
57 |
|
|
|
58 |
} |
|
|
59 |
\section{Slots}{ |
|
|
60 |
\describe{ |
|
|
61 |
\item{\code{data}:}{ an object of class \code{"\linkS4class{ModelEnv}"}.} |
|
|
62 |
\item{\code{responses}:}{ an object of class \code{"VariableFrame"} |
|
|
63 |
storing the values of the response variable(s). } |
|
|
64 |
\item{\code{cond_distr_response}:}{ a function computing the conditional |
|
|
65 |
distribution of the response. } |
|
|
66 |
\item{\code{predict_response}:}{ a function for computing predictions. } |
|
|
67 |
\item{\code{tree}:}{ a recursive list representing the tree. See above. } |
|
|
68 |
\item{\code{where}:}{ an integer vector of length n (number of |
|
|
69 |
observations in the learning sample) giving the |
|
|
70 |
number of the terminal node the corresponding |
|
|
71 |
observations is element of. } |
|
|
72 |
\item{\code{prediction_weights}:}{ a function for extracting weights from |
|
|
73 |
terminal nodes. } |
|
|
74 |
\item{\code{get_where}:}{ a function for determining the number |
|
|
75 |
of terminal nodes observations fall into. } |
|
|
76 |
\item{\code{update}:}{ a function for updating weights.} |
|
|
77 |
} |
|
|
78 |
} |
|
|
79 |
\section{Extends}{ |
|
|
80 |
Class \code{"BinaryTreePartition"}, directly. |
|
|
81 |
} |
|
|
82 |
\section{Methods}{ |
|
|
83 |
\describe{ |
|
|
84 |
\item{\code{response(object, ...)}:}{extract the response variables the |
|
|
85 |
tree was fitted to.} |
|
|
86 |
\item{\code{treeresponse(object, newdata = NULL, ...)}:}{compute |
|
|
87 |
statistics for the conditional distribution of the response as |
|
|
88 |
modelled by the tree. For regression problems, this is just the mean. |
|
|
89 |
For nominal or ordered responses, estimated conditional class |
|
|
90 |
probabilities are returned. Kaplan-Meier curves are computed for |
|
|
91 |
censored responses. Note that a list with one element for each |
|
|
92 |
observation is returned.} |
|
|
93 |
\item{\code{Predict(object, newdata = NULL, ...)}:}{ compute predictions.} |
|
|
94 |
\item{\code{weights(object, newdata = NULL, ...)}:}{ extract the weight |
|
|
95 |
vector from terminal nodes each element of the learning sample is |
|
|
96 |
element of (\code{newdata = NULL}) and for new observations, |
|
|
97 |
respectively.} |
|
|
98 |
\item{\code{where(object, newdata = NULL, ...)}:}{ extract the number of |
|
|
99 |
the terminal nodes each element of the learning sample is |
|
|
100 |
element of (\code{newdata = NULL}) and for new observations, |
|
|
101 |
respectively.} |
|
|
102 |
\item{\code{nodes(object, where, ...)}:}{ extract the nodes with |
|
|
103 |
given number (\code{where}).} |
|
|
104 |
\item{\code{plot(x, ...)}:}{ a plot method for \code{BinaryTree} |
|
|
105 |
objects, see \code{\link{plot.BinaryTree}}.} |
|
|
106 |
\item{\code{print(x, ...)}:}{ a print method for \code{BinaryTree} |
|
|
107 |
objects.} |
|
|
108 |
} |
|
|
109 |
} |
|
|
110 |
\examples{ |
|
|
111 |
|
|
|
112 |
set.seed(290875) |
|
|
113 |
|
|
|
114 |
airq <- subset(airquality, !is.na(Ozone)) |
|
|
115 |
airct <- ctree(Ozone ~ ., data = airq, |
|
|
116 |
controls = ctree_control(maxsurrogate = 3)) |
|
|
117 |
|
|
|
118 |
### distribution of responses in the terminal nodes |
|
|
119 |
plot(airq$Ozone ~ as.factor(where(airct))) |
|
|
120 |
|
|
|
121 |
### get all terminal nodes from the tree |
|
|
122 |
nodes(airct, unique(where(airct))) |
|
|
123 |
|
|
|
124 |
### extract weights and compute predictions |
|
|
125 |
pmean <- sapply(weights(airct), function(w) weighted.mean(airq$Ozone, w)) |
|
|
126 |
|
|
|
127 |
### the same as |
|
|
128 |
drop(Predict(airct)) |
|
|
129 |
|
|
|
130 |
### or |
|
|
131 |
unlist(treeresponse(airct)) |
|
|
132 |
|
|
|
133 |
### don't use the mean but the median as prediction in each terminal node |
|
|
134 |
pmedian <- sapply(weights(airct), function(w) |
|
|
135 |
median(airq$Ozone[rep(1:nrow(airq), w)])) |
|
|
136 |
|
|
|
137 |
plot(airq$Ozone, pmean, col = "red") |
|
|
138 |
points(airq$Ozone, pmedian, col = "blue") |
|
|
139 |
} |
|
|
140 |
\keyword{classes} |