Patralekha Bhattacharya
2005-Mar-15 12:41 UTC
[R] need help with plot.rpart and text.rpart
Hi, I am new to R and need help with rpart. I am trying to create a classification tree using rpart. In order to plot the reults I use the plot function and the text function to label the plot of the tree dendrogram with text. The documentation of text.rpart says : "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, neither the label="yprob" option nor the label='specific yval level' option works for me. I have copied a section of my code in order to include the error message.> plot(fit) > text(fit, label="yprob")Error in text.rpart(fit, label = "yprob") : Label must be a column label of the frame component of the tree On inspecting fit$frame I noticed that neither "yprob" nor 'specific yval level' are included in the frame. I therefore even tried to create these variable in the frame by using the following fit$frame <- transform(fit$frame, newVar=fit$frame$yval2[,4]) where fit$frame$yval2[,4] are the probabilities of the winning factor level. However, using this I just get the values of "yval" as the labels which I could have got anyway by setting the option label="yval". I would really appreciate any help on this. Thanks in advance. Pat
Possibly Parallel Threads
- rpart subsets
- rpart subset fix
- text.rpart for the "class" method doesn't act on label="yprob"
- Displaying number of Y/N affected by tree in rule form RE: R question/request on rules from rpart
- rpart error with 0-frequency factor levels (with partial fix) (PR#1378)