yindalon
2012-Mar-04 23:04 UTC
[Rd] rpart package, text function, and round of class counts
I run the following code: library(rpart) data(kyphosis) fit <- rpart(Kyphosis ~ ., data=kyphosis) plot(fit) text(fit, use.n=TRUE) The text labels represent the count of each class at the leaf node. Unfortunately, the numbers are rounded and in scientific notation rather than the exact number of examples sorted by that node in each class. The plot is supposed to look like http://www.statmethods.net/advstats/images/ctree.png as per http://www.statmethods.net/advstats/cart.html. I'm running 2.14.1 on a mac. Can anyone verify or point out if I am doing something obviously wrong for displaying the counts rounded and in scientific notation rather than the true counts in each class at each node? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/rpart-package-text-function-and-round-of-class-counts-tp4444576p4444576.html Sent from the R devel mailing list archive at Nabble.com.
Achim Zeileis
2012-Mar-05 06:35 UTC
[Rd] rpart package, text function, and round of class counts
On Sun, 4 Mar 2012, yindalon wrote:> I run the following code: > > library(rpart) > data(kyphosis) > fit <- rpart(Kyphosis ~ ., data=kyphosis) > plot(fit) > text(fit, use.n=TRUE) > > The text labels represent the count of each class at the leaf node. > Unfortunately, the numbers are rounded and in scientific notation rather > than the exact number of examples sorted by that node in each class.You probably have a getOption("digits") of 4 or lower. text.rpart uses getOption("digits") - 3 as the default which then means only 1 significant digit and hence it rounds and uses scientific notation. Using text(fit, use.n = TRUE, digits = 3) should do the trick. Maybe adding setting xpd = TRUE in addition helps in avoiding clipping of some labels. Also, I would recommend to use library("partykit") plot(as.party(fit)) for visualization which uses a display like for the ctree() function (also mentioned on the web page you quote below).> The plot is supposed to look like > http://www.statmethods.net/advstats/images/ctree.png as per > http://www.statmethods.net/advstats/cart.html. > > I'm running 2.14.1 on a mac. > > Can anyone verify or point out if I am doing something obviously wrong for > displaying the counts rounded and in scientific notation rather than the > true counts in each class at each node? > Thanks. > > -- > View this message in context: http://r.789695.n4.nabble.com/rpart-package-text-function-and-round-of-class-counts-tp4444576p4444576.html > Sent from the R devel mailing list archive at Nabble.com. > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >