From Robert.King at newcastle.edu.au  Wed Feb 21 00:30:25 2007
From: Robert.King at newcastle.edu.au (Robert King)
Date: Wed, 21 Feb 2007 10:30:25 +1100
Subject: [Rd] text.rpart for the "class" method doesn't act on label="yprob"
Message-ID: <200702211030.26010.robert.king@newcastle.edu.au>

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")



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