s-news
[Top] [All Lists]

Re: Q: How can I get a complete sequence of sub-trees and their

To: s-news@lists.biostat.wustl.edu
Subject: Re: Q: How can I get a complete sequence of sub-trees and their
From: Ernst Linder <elinder@cisunix.unh.edu>
Date: Tue, 24 Feb 2004 16:27:08 -0500
References: <E1AveXt-0007nb-B0.--d2058550df398dd0030e6de61b4465739ea83f71@maroon.csi.cam.ac.uk> <403B9134.2020700@cisunix.unh.edu>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0
Dear S-Plus users:

I was able to solve my problem.  In short, I needed the "snip.tree" command
rather than the "prune.tree" command.
I enclose my function below, for anyone interested.

Andy Liaw pointed out that the relative measures of importance of variables
based on deviance reduction by internal splits in a tree
should be used with caution. In particular, if the input variables
for a tree are of mixed type (eg continuous versus categorical) such
measure may be severely biased since one type of variable may
favor more splits than the other type.

Thanks again,

Ernst.




# Calculates relative importance of variables in a tree
# Provides a table (vector) of the contribution of each variable
rel.impo <- function(tree1)
{
# Sequence of internal nodes
intern.fr <- tree1$frame[tree1$frame$var != '<leaf>',]
nodes <- row.names(intern.fr)
vars <- as.character(intern.fr$var)
n.intern <- nrow(intern.fr)

# Calculate deviance of recursively snipped subtrees
devs <- rep(deviance(tree1),(n.intern+1))
for (i in 2 : n.intern)
       devs[i] <- deviance(snip.tree(tree1,nodes=nodes[(n.intern+2-i)]))
devs[n.intern+1] <- tree1$frame$dev[1]

# Calculate differences in deviances and rearrange terms in correct sequence
impo <- diff(devs)
vars <- vars[n.intern : 1]

tapply(impo,vars,sum)
}


--
****************************************************************
Ernst Linder                        elinder@math.unh.edu
Department of Mathematics and Statistics     603 - 862- 2687
University of New Hampshire            Fax:  603 - 862 - 4096
Durham, NH 03824                www.math.unh.edu/~elinder
****************************************************************


<Prev in Thread] Current Thread [Next in Thread>