[Rd] text.rpart for the "class" method doesn't act on label="yprob"

Robert King Robert.King at newcastle.edu.au
Wed Feb 21 00:30:25 CET 2007


Hello All,

Am I misreading the documentation?

The text.rpart documentation says:
"label   a column name of x$frame; values of this will label the nodes. For
the "class" method, label="yval" results in the factor levels being
used, "yprob" results in the probability of the winning factor level being
used, and ‘specific yval level’ results in the probability of that factor
level."

However, yprob doesn't seem to do this:
> pred = rep(letters[1:6],5)
> resp = rep(letters[1:3],10)
> ex.rp <- rpart(resp~pred)
> plot(ex.rp)
> text(ex.rp,label="yval")

# works as advertised

> plot(ex.rp)
> text(ex.rp,label="yprob")

Error in text.rpart(ex.rp, label = "yprob") :
        Label must be a column label of the frame component of the tree

If I try to fake it, by making an element of the frame, like this:
> ex.rp$frame$yprob = (ex.rp$frame$n-ex.rp$frame$dev)/ex.rp$frame$n

The text command does add text to the plot, but adds the class labels
(i.e. "yval"), not the probabilities

> text(ex.rp,label="yprob")



More information about the R-devel mailing list