tree(formula, data, weights, subset, na.action = na.pass, control = tree.control(nobs, ...), method = "recursive.partition", split = c("deviance", "gini"), model = FALSE, x = FALSE, y = TRUE, wts = TRUE, ...)
+
; there should be no interaction
terms. Both .
and -
are allowed: regression trees can
have offset
terms.formula
, weights
and subset
.na.pass
(to do nothing) as tree
handles missing values (by dropping them down the tree as far
as possible).tree.control
."model.frame"
.formula
and data
arguments are ignored, and
model
is used to define the model. If the argument is
logical and true, the model frame is stored as component
model
in the result.tree.control
. Normally used for mincut
, minsize
or mindev
."tree"
which has components
row.names
giving the node numbers. The columns include
var
, the variable used at the split (or ""
for a
terminal node), n
, the (weighted) number of cases reaching
that node, dev
the deviance of the node, yval
, the
fitted value at the node (the mean for regression trees, a majority
class for classification trees) and split
, a two-column
matrix of the labels for the left and right splits at the
node. Classification trees also have yprob
, a matrix of
fitted probabilities for each response level.Tree
.model = TRUE
, the model frame.x = TRUE
, the model matrix.y = TRUE
, the response.wts = TRUE
, the weights.xlevels
and, for classification trees,
ylevels
.A tree with no splits is of class "singlenode"
which inherits
from class "tree"
.
Tree growth is limited to a depth of 31 by the use of integers to label nodes.
Factor predictor variables can have up to 32 levels. This limit is imposed for ease of labelling, but since their use in a classification tree with three or more levels in a response involves a search over $2^(k-1) - 1$ groupings for $k$ levels, the practical limit is much less.
Ripley, B. D. (1996) Pattern Recognition and Neural Networks. Cambridge University Press, Cambridge. Chapter 7.
tree.control
, prune.tree
,
predict.tree
, snip.tree
data(cpus, package="MASS")
cpus.ltr <- tree(log10(perf) ~ syct+mmin+mmax+cach+chmin+chmax, cpus)
cpus.ltr
summary(cpus.ltr)
plot(cpus.ltr); text(cpus.ltr)
ir.tr <- tree(Species ~., iris)
ir.tr
summary(ir.tr)
Run the code above in your browser using DataLab