Re: [R] Help on variable ranking

From: Frank E Harrell Jr <>
Date: Wed 17 Jan 2007 - 12:50:27 GMT

Rupendra Chulyadyo wrote:
> Hello all,
> I want to assign relative score to the predictor variables on the basis of
> its influence on the dependent variable. But I could not find any standard
> statistical approach appropriate for this purpose.
> Please suggest the possible approaches.
> Thanks in advance,
> Rupendra Chulyadyo
> Institute of Engineering,
> Tribhuvan University,
> Nepal

You might consider using the bootstrap to get confidence intervals of the rank of each predictor's partial chi-square or partial R-square. The following takes into account all terms that might be associated with a variable (nonlinear and interaction terms, dummy variables). The code is taken from an example in the anova.Design help file in the Design package. Unless the dataset is huge and there is little collinearity, you will be surprised how difficult it is to pick winners and losers from the predictors [try ranking gene expressions from gene microarray data for even more of a shock]. Note that Bayesian ranking procedures are more accurate, but this quick and dirty approach isn't bad.

mydata <- data.frame(x1=runif(200), x2=runif(200),

set.seed(9) # so can reproduce example
mydata$y <- ifelse(runif(200)<=plogis(mydata$x1-.5 + .5*(mydata$x2-.5) +

b <- boot(mydata, function(data, i, ...) rank(-plot(anova(

                 lrm(y ~ rcs(x1,4)+pol(x2,2)+sex,data,subset=i)),
                 sort='none', pl=FALSE)),
                 R=25)  # should really do R=500 but will take a while
Rank <- b$t0
lim <- t(apply(b$t, 2, quantile, probs=c(.025,.975))) # Use the Hmisc Dotplot function to display ranks and their confidence # intervals. Sort the categories by descending adj. chi-square, for ranks original.chisq <- plot(anova(lrm(y ~ rcs(x1,4)+pol(x2,2)+sex,data=mydata)),
                        sort='none', pl=FALSE)
predictor <- as.factor(names(original.chisq)) predictor <- reorder.factor(predictor, -original.chisq)

Dotplot(predictor ~ Cbind(Rank, lim), pch=3, xlab='Rank',


'Ranks and 0.95 Confidence Limits for ',chi^2,' - d.f.')))
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed Jan 17 23:56:36 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 17 Jan 2007 - 13:30:23 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.