Robert King
2007-Feb-20 23:30 UTC
[Rd] text.rpart for the "class" method doesn't act on label="yprob"
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$nThe text command does add text to the plot, but adds the class labels (i.e. "yval"), not the probabilities> text(ex.rp,label="yprob")
Prof Brian Ripley
2007-Feb-23 08:10 UTC
[Rd] text.rpart for the "class" method doesn't act on label="yprob"
Not sure why this on R-devel! Nobody has contacted the maintainer, as asked by the posting guide. I've wondered about this in the past. It seems the argument was dropped in rpart3, but the help was not changed. It is checked but not used. On Wed, 21 Feb 2007, Robert King wrote:> 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") > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595