s-news
[Top] [All Lists]

How to show the probabilities in Rpart tree graph?

To: <s-news@lists.biostat.wustl.edu>
Subject: How to show the probabilities in Rpart tree graph?
From: "Li, Xiaoxi" <Li.Xiaoxi@principal.com>
Date: Thu, 24 Aug 2006 13:21:54 -0500
Domainkey-signature: s=desmoines; d=principal.com; c=nofws; q=dns; b=RKT0MgaveXuxo6AJ1AmZd2phTMRxXIJdRI7ILpxfalsYeAFq+HTQ2W10ZKcywKBB8XpoYPdttRi0YrkJ8S7v3Thkmr8JF9gwRgmK9kO8C34cCMQn9yvrrnUW/2vrdawP;
Thread-index: AcbHqizj1mXWbU8PS9iHYtDY3B1BrQ==
Thread-topic: How to show the probabilities in Rpart tree graph?

Hi all,

 

I have a problem needed your help. Here is my situation:

 

I fitted my data into Rpart to generate a Classification tree, and then I printed out the Rpart objective, or best.tree. As you can see in the attachment, with the < print(best.tree) command we can see the "yprob" column.

 

 

I want to show the "yprob" or the Probabilities information in the final tree graph. However, when I use the following command

> plot(best.tree);text(best.tree,label="yprob",use.n=T,splits=T), it generated the following error message:

 

Error in text.rpart(best.tree1M, use.n = T, splits = T, label = "yprob"):

Label must be a column label of the frame component of the tree

 

As you can see, the tree does have a column "(yprob)" after I input the print(best.tree) command such as (0.500000 0.500000) and (0.5525950 0.4474050).

 

Can any one help me solve the problem and show me how to get the probabilities or the "yprob" column content into the final tree?

 

Thank you for all your help.

 

Xiaoxi

 

-----

Please see the detailed problem. Thank you.

 

>> printcp(best.tree1M)

 

Classification tree:

 

rpart(formula = OP1M ~ .,data = "" method = "class", parms =list(split = "gini"))

 

Variables actually used in tree construction:

[1] F_5YE F_PCF ....

 

Root node error: 8645/17551 = 0.49256

 

n=17551 (489 observations deleted due to missing)

     CP nsplit rel error  xerror      xstd

1 0.0253326      0   1.00000 1.00000 0.0076614

2 0.0135338      1   0.97467 0.99445 0.0076607

3 0.0045113      2   0.96113 0.98427 0.0076587

........

 

> print(best.tree)

n=17530 (510 observations deleted due to missing)

 

node),  split,  n,  loss,    yval,   (yprob)

 

* denotes terminal node

 

1) root 17530 8765.0000 1 (0.5000000 0.5000000) 

     2) Q_1PE< 1.5 2817 1252.5980 0 (0.5525950 0.4474050) *

 

     3) Q_1PE>=1.5 14713 7217.9020 1 (0.4900036 0.5099964) 

       6) H_SGG< 1.5 2800 1244.0990 0 (0.5529161 0.4470839) 

        12) F_PCF< 3.5 1699  655.5158 0 (0.6092234 0.3907766) *

.........

 

> plot(best.tree);text(best.tree,label="yprob",use.n=T,splits=T)

 

Error in text.rpart(best.tree1M, use.n = T, splits = T, label = "yprob") :

Label must be a column label of the frame component of the tree

 

 

 

 

 

 

 

 

end


-----Message Disclaimer-----

This e-mail message is intended only for the use of the individual or
entity to which it is addressed, and may contain information that is
privileged, confidential and exempt from disclosure under applicable law.
If you are not the intended recipient, any dissemination, distribution or
copying of this communication is strictly prohibited. If you have
received this communication in error, please notify us immediately by
reply email to Connect@principal.com and delete or destroy all copies of
the original message and attachments thereto. Email sent to or from the
Principal Financial Group or any of its member companies may be retained
as required by law or regulation.

Nothing in this message is intended to constitute an Electronic signature
for purposes of the Uniform Electronic Transactions Act (UETA) or the
Electronic Signatures in Global and National Commerce Act ("E-Sign")
unless a specific statement to the contrary is included in this message.

While this communication may be used to promote or market a transaction
or an idea that is discussed in the publication, it is intended to provide
general information about the subject matter covered and is provided with
the understanding that The Principal is not rendering legal, accounting,
or tax advice. It is not a marketed opinion and may not be used to avoid
penalties under the Internal Revenue Code. You should consult with
appropriate counsel or other advisors on all matters pertaining to legal,
tax, or accounting obligations and requirements.
<Prev in Thread] Current Thread [Next in Thread>