calc.relimp {relaimpo} | R Documentation |
calc.relimp calculates several relative importance metrics for the linear model.
The recommended metrics are lmg
(R^2 partitioned by averaging over orders, like in Lindemann, Merenda and Gold (1980, p.119ff))
and pmvd
(a newly proposed metric by Feldman (2005) that is provided in the non-US version of the package only).
For completeness and comparison purposes, several other metrics are also on offer (cf. e.g. Darlington (1968)).
## generic function calc.relimp(object, ...) ## default S3 method, should be called without suffix ".default" calc.relimp.default(object, x = NULL, ..., type = "lmg", diff = FALSE, rank = TRUE, rela = FALSE, always = NULL, groups = NULL, groupnames = NULL, weights=NULL, design=NULL) ## S3 method for formula object, should be called without suffix ".formula" calc.relimp.formula(formula, data, weights, na.action, ..., subset=NULL) ## S3 method for objects of class lm calc.relimp.lm(object, type = "lmg", groups = NULL, groupnames=NULL, always = NULL, ...)
object |
The class of this object determines which of the methods is used:
There are special methods for output objects from function lm
(or linear model objects inheriting from class lm
generated by other functions like glm and svyglm )
and for formula objects.
For all other types of object, the default method is used.
Thus, object can be a formula (e.g. y~x1+x2+x3+x2:x3) (cf. below for details) OR the output of a linear model call (inheriting from class lm , but not mlm );
output objects from lm , glm , svyglm or aov work
(if linear with identity link in case of glm's);
there may be further functions that output objects inheriting from lm
which may or may not work reasonably with calc.relimp ;
for calc.relimp to be appropriate, the underlying model must at least be linear!
The restrictions on usage of interactions listed under item formula below also apply to linear model objects. OR the covariance matrix of a response y and regressors x, (e.g. obtained by cov(cbind(y,x)), if y is a column vector of response values and x a corresponding matrix of regressors) OR a (raw) data matrix or data frame with the response variable in the first column OR a response vector or one-column matrix, if x contains the corresponding matrix or data frame of regressors. |
formula |
The first object, if a formula is to be given;
one response only.
Interaction terms are currently limited to second-order. Note: If several interaction terms are given, calculations may be very resource intensive, if these are all connected (e.g. with A:B, B:C, C:D, all A,B,C,D are connected, while with A:B, C:D, D:E there are separate groups A,B and C,D,E). Interaction terms occurring in always do not increase resource usage (but are only permitted if the respective main effects also occur in always). Interactions and groups currently cannot be used simultaneously. |
x |
a (raw) data matrix or data frame containing the regressors,
if object is a response vector or one-column matrix
OR NULL, if object is anything else |
type |
can be a character string, character vector or list of character strings.
It is the collection of metrics that are to be calculated.
Available metrics: lmg , pmvd (non-US version only), last , first ,
betasq , pratt . For brief sketches of their meaning cf. details section. |
diff |
logical; if TRUE, pairwise differences between the relative contributions are calculated; default FALSE |
rank |
logical; if TRUE, ranks of regressors in terms of relative contributions are calculated; default TRUE |
rela |
is a logical requesting relative importances summing to 100% (rela=TRUE ).
If rela is FALSE (default), some of the metrics sum to R^2 (lmg , pmvd , pratt ),
others do not have a meaningful sum (last , first , betasq ). |
always |
is a vector of column numbers or names of variables to be always in the
model (adjusted for). Valid numbers are 2 to (number of regressors + 1) (1 is reserved for the response),
valid character strings are all column names of object or x respectively
that refer to regressor variables. Numbers and names cannot be mixed.
Relative importance is only assessed for the variables not selected in always . |
groups |
is a list of vectors of column numbers or names of variables to be combined into groups.
If only one group is needed, a vector can be given. The numbers and character strings needed are of the same form
as for always .
Relative importance is only allocated between groups of regressors, no subdivision within groups is calculated. Regressors that do not occur in any group are included as singletons. A regressor must not occur in always and in groups . Also, groups cannot be used with a linear model or a formula
in case of higher order effects (interactions). |
groupnames |
is a vector of names for the variable groups to be used for annotation of output. |
weights |
is a vector of case weights for the observations in the data frame (or matrix).
You can EITHER specify weights OR a design .
Note that weights must not be specified for linear model objects (since these should contain their weights as
part of the model). |
design |
is a design object of class survey.design (cf. package survey).
You can EITHER specify a design OR weights . For calc.relimp , the design is used
for calculating weights only.
Note that it is discouraged (though possible) to specify a design for a conventional linear model object
(since a survey-specific linear model should be used for survey data, cf. function svyglm ).
Also note that care is needed when using subset together with design :
the subset -Option only treats the data handed directly to calc.relimp ,
the design has to be equivalently treated beforehand. |
data |
if first object is of class formula: an optional matrix or data frame that the variables in formula and subset come from; if it is omitted, all names must be meaningful in the environment from which calc.relimp is called |
subset |
if first object is of class formula:
an optional expression indicating the subset of the observations of data that should be used in the fit.
This can be a logical vector, or a numeric vector indicating which observation numbers are to be included,
or a character vector of the row names to be included. All (non-missing) observations are included by
default. |
na.action |
if first object is of class formula:
an optional function that indicates what should happen when the data contain 'NA's.
The default is first, any na.action attribute of data, second the setting given in the call to calc.relimp,
third the na.action setting of options. Possible choices are "na.fail",
(print an error message and terminate if there are any incomplete observations),
"na.omit" or "na.exclude" (equivalent for package relaimpo ,
both analyse complete cases only and print a warning, this is also what is done the default method ). |
... |
usable for further arguments, particularly most arguments of default method can be given to all other methods (exception: weights and design cannot be given to lm-method) |
Each metric is calculated using the internal function “metric”calc
, e.g. lmgcalc
.
Three of the metrics in calc.relimp
(lmg
, pmvd
and pratt
) decompose the model R^2.
If always
requests some variables to be always in the model, these variables are included in the model first.
Only the remaining R^2 that is not explained by these variables is decomposed among the other regressors.
lmg
, pmvd
and pratt
sum to the R^2 that is to be decomposed,
if rela = FALSE
and to 100pct if rela = TRUE
.
The other metrics also (artificially) sum to 100pct if rela = TRUE
.
If rela = FALSE
, they are given relative to var(y) (or the conditional variance of y after adjusting out the variables
requested in always
) but do not sum to R^2.
Note that relaimpo can only provide metric lmg
for models with interactions (2-way interactions only).
It averages only over those orders, for which the interactions enter the model after both their main effects.
Note that there are different types of weights, weights indicating the variability of the response
(observations with a more variable responses receive a lower weight than those with a less variable response,
like in the Aitken estimator), frequency weights indicating the number of observations with exactly the observed
data pattern of the current observation, or weights indicating the number of population units represented by the
current observation (inverse sampling probability, weights typically used in survey situations). All three types of
weight alike can be handed to function calc.relimp
using the weights=
option. Note, however, that they
have to be treated differently for bootstrapping (cf. boot.relimp
).
Data from complex surveys can be treated by providing a survey design with design=
-option.
For calc.relimp
, it is also sufficient to provide the weights derived from the design using the
weights=
-option.
calc.relimp
cannot handle data with missing values directly. It applies complete-case analysis,
i.e. drops all units with any missing values by default. While this can be appropriate, if there are only few
missing values, data with more severe missingness issues need special treatment. Package relaimpo
offers the function mianalyze.relimp
that handles multiply-imputed datasets (that can be created
by several other R-packages). Currently, possibilities in this function are limited due to the fact that
it uses complex survey designs and bootstrapping which do not (yet) go together well with factors, interactions
and calculated quantities in formulae.
var.y |
the variance of the response |
R2 |
the coefficient of determination, R^2 |
R2.decomp |
the part of the coefficient of determination that is decomposed among the variables under investigation |
lmg |
vector of relative contributions obtained from the lmg method, if lmg has been requested in type |
lmg.diff |
vector of pairwise differences between relative contributions obtained from the lmg method,
if lmg has been requested in type and diff=TRUE |
lmg.rank |
rank of the regressors relative contributions obtained from the lmg method,
if lmg has been requested in type and rank=TRUE |
metric, metric.diff, metric.rank |
analogous to lmg for other metrics |
ave.coeffs |
average coefficients for variables not not requested by always only
for models of different sizes;
note that coefficients refer to modeling residuals after adjusting out variables listed in always (both from response and other explanatory variables) |
namen |
names of variables, starting with response |
type |
character vector of metrics available |
rela |
Have metrics been normalized to sum 100% ? |
always |
column numbers of variables always in the model;
in case of factors, the column numbers given here are not identical to those in
the call to calc.relimp , but refer to the columns of the model matrix |
alwaysnam |
names of variables always in the model |
call |
contains the call that generated the object |
lmg
and pmvd
are computer-intensive. Although they are calculated based on the
covariance matrix, which saves substantial computing time in comparison to carrying out actual regressions,
these methods still take quite long for problems with many regressors.
relaimpo
is a package for univariate linear models.
Using relaimpo
on objects that inherit from class lm
but are not univariate linear model objects
may produce nonsensical results without warning. Objects of class mlm
or glm
with link functions other than identity
or family other than gaussian lead to an error message.
There are two versions of this package. The version on CRAN is globally licensed under GPL version 2 (or later).
There is an extended version with the interesting additional metric pmvd
that is licensed according to GPL version 2
under the geographical restriction "outside of the US" because of potential issues with US patent 6,640,204.
This version can be obtained from Ulrike Groempings website (cf. references section).
Whenever you load the package, a display tells you, which version you are loading.
Ulrike Groemping, TFH Berlin
Chevan, A. and Sutherland, M. (1991) Hierarchical Partitioning. The American Statistician 45, 90–96.
Darlington, R.B. (1968) Multiple regression in psychological research and practice. Psychological Bulletin 69, 161–182.
Feldman, B. (2005) Relative Importance and Value. Manuscript (Version 1.1, March 19 2005), downloadable at http://www.prismanalytics.com/docs/RelativeImportance050319.pdf
Lindeman, R.H., Merenda, P.F. and Gold, R.Z. (1980) Introduction to Bivariate and Multivariate Analysis, Glenview IL: Scott, Foresman.
Go to http://prof.tfh-berlin.de/groemping/ for further information and references.
relaimpo, booteval.relimp
, mianalyze.relimp
,
classesmethods.relaimpo
##################################################################### ### Example: relative importance of various socioeconomic indicators ### for Fertility in Switzerland ### Fertility is first column of data set swiss ##################################################################### data(swiss) calc.relimp(swiss, type = c("lmg", "last", "first", "betasq", "pratt") ) # calculation of all available relative importance metrics # non-US version offers the additional metric "pmvd", # i.e. call would be # calc.relimp(cov(swiss), # type = c("lmg", "pmvd", "last", "first", "betasq, "pratt"), # rela = TRUE ) ## same analysis with formula or lm method and a few modified options crf <- calc.relimp(Fertility~Agriculture+Examination+Education+Catholic+Infant.Mortality,swiss, subset = Catholic>40, type = c("lmg", "last", "first", "betasq", "pratt"), rela = TRUE ) crf linmod <- lm(Fertility~Agriculture+Examination+Education+Catholic+Infant.Mortality,swiss) crlm <- calc.relimp(linmod, type = c("lmg", "last", "first", "betasq", "pratt"), rela = TRUE ) plot(crlm) # bar plot of the relative importance metrics #of statistical interest in this context: correlation matrix cor(swiss) #demonstration of conditioning on one regressor using always calc.relimp(swiss, type = c("lmg", "last", "first", "betasq", "pratt"), rela = FALSE, always = "Education" ) # using calc.relimp with grouping of two regressors # and weights (not reasonable here, purely for demo purposes) calc.relimp(swiss, type = c("lmg", "last", "first"), rela = FALSE, groups = c("Education","Examination"), weights = abs(-23:23) ) # using calc.relimp with grouping of two regressors # and a design object (not reasonable here, purely for demo purposes) des <- svydesign(~1, data=swiss, weights=~abs(-23:23)) calc.relimp(swiss, type = c("lmg", "last", "first"), rela = FALSE, groups = c("Education","Examination"), groupnames ="EduExam", design = des) # calc.relimp with factors (betasq and pratt not possible) # (calc.relimp would not be necessary here, # because the experiment is balanced) calc.relimp(1/time~poison+treat,data=poisons, rela = FALSE, type = c("lmg", "last", "first")) # including also the interaction (lmg possible only) calc.relimp(1/time~poison*treat,data=poisons, rela = FALSE)