Peter Flom
2003-Jul-17 19:56 UTC
[R] Rpart question - labeling nodes with something not in x$frame
I have a tree created with tr.hh.logcas <- rpart(log(YCASSX + 1)~AGE+DRUGUSEY+SEX+OBSXNUM +WINDLE, xval = 10) I would like to label the nodes with YCASSX rather than log(YCASSX + 1). But the help file for text in library rpart says that you can only use labels that are part of x$frame, which YCASSX is not. Is there a way to do what I want? Thanks in advance Peter Peter L. Flom, PhD Assistant Director, Statistics and Data Analysis Core Center for Drug Use and HIV Research National Development and Research Institutes 71 W. 23rd St www.peterflom.com New York, NY 10010 (212) 845-4485 (voice) (917) 438-0894 (fax)
Ko-Kang Kevin Wang
2003-Jul-17 20:27 UTC
[R] Rpart question - labeling nodes with something not in x$frame
On Thu, 17 Jul 2003, Peter Flom wrote:> I have a tree created with > > tr.hh.logcas <- rpart(log(YCASSX + 1)~AGE+DRUGUSEY+SEX+OBSXNUM +WINDLE, > xval = 10) > > I would like to label the nodes with YCASSX rather than log(YCASSX + > 1). But the help file for text in library rpart says that you can only > use labels that are part of x$frame, which YCASSX is not.This may not be the best solution, but what I have done once is to add another column into the data frame with the labels I want. For example: data(iris) library(rpart) # Recoding the response: # s: setosa # c: versicolor # v: virginica ir <- iris[, -5] Species <- rep(c("s", "c", "v"), rep(50, 3)) ir <- as.data.frame(cbind(ir, Species)) ir.rp <- rpart(Species ~ ., data = ir) plot(ir.rp) text(ir.rp) This is probably the long/silly way, but it works ;-D -- Cheers, Kevin ------------------------------------------------------------------------------ "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage (1791-1871) ---- From Computer Stupidities: http://rinkworks.com/stupid/ -- Ko-Kang Kevin Wang Master of Science (MSc) Student SLC Tutor and Lab Demonstrator Department of Statistics University of Auckland New Zealand Homepage: http://www.stat.auckland.ac.nz/~kwan022 Ph: 373-7599 x88475 (City) x88480 (Tamaki)