[R] help with rpart

Sarah Goslee sarah.goslee at gmail.com
Fri Jul 29 16:48:53 CEST 2011


Mark,

The R-help list is not telepathic. I asked entirely reasonable follow-up
questions intended to elicit from you a more extensive explanation of
your problem.

On Fri, Jul 29, 2011 at 10:26 AM,  <mark at statcourse.com> wrote:
> 1. I did not receive your reply, which, not incidentally, does not address
> either of my questions.

Nor did you address mine, except to repeat them with more exclamation
marks.

> 2. I wish to plot.rpart the entire tree!  How can I do this?


What do you want to see that plot() does not show?
library(rpart)
fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis)
par(mfrow=c(1,2), xpd=NA) # otherwise on some devices the text is clipped
plot(fit)
text(fit, use.n=TRUE)

You want the "whole tree" - what is missing? That's the entire tree as
shown by print(fit).


> 3. I wish to predict.rpart the appropriate assignment for a single vector of
> observations using the tree produced by rpart. How can I do this?

newdata <- data.frame(Age=c(18, 22), Number=c(3,4), Start=c(15, 15))
predict(fit, newdata = newdata, type="class")

This seems to me to provide the predicted class information for new data.
What do you want that predict() is not providing?

> Can anyone be of practical assistance?

Of course. But we need to know *what you want*.
A minimal reproducible example is handy, and I've now provided one
for you because I'm feeling generous.

> Mark
>
> -------- Original Message --------
> Subject: Re: [R] help with rpart
> From: Sarah Goslee <sarah.goslee at gmail.com>
> Date: Thu, July 28, 2011 1:10 pm
> To: mark at statcourse.com
> Cc: r-help at r-project.org
>
> Why repost after receiving a reply? Reposting is unnecessary. If the
> first reply was unsatisfactory, why? More detail in your question
> leads to a more useful and informative reply.
>
> Just in case you didn't get it:
>
> On Thu, Jul 28, 2011 at 11:52 AM, <mark at statcourse.com> wrote:
>> 1. How can I plot the entire tree produced by rpart?
>
> What is plot() not doing that you need?
>
>> 2. How can I submit a vector of values to a tree produced by rpart and
>> have
>> it make an assignment?
>
> What is predict() not doing that you need?
>

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list