Relative Contribution of Effects in a Regression Model

Relative Contribution of Effects in a Regression Model [R logo]

Help pages for package `relimp' version 0.9-7

pickFrom | Pick Subsets from a Vector
print.relimp | Relative Importance of Predictors in a Regression Model
R.to.Tcl | Convert a Character Vector to Tcl Format
relimp | Relative Importance of Predictors in a Regression Model
relrelimp | Comparison of Relative Importances in a Multinomial Logit Model
showData | Display a Data Frame in a Tk Text Widget
Tcl.to.R | Convert a Tcl List to R Character Vector


Pick Subsets from a Vector

Description

Provides a Tk dialog for interactive selection of one or more subsets from a vector. Requires the tcltk package.

Usage

pickFrom(vec, nsets = 1, return.indices = FALSE,
                 setlabels = NULL, edit.setlabels = TRUE,
                 subset = TRUE,
                 warningText = "one or more selections empty",
                 title = "Subset picker",
                 items.label = "Pick from:",
                 labels.prompt = "Your label for this set:",
                 list.height = 20,
                 items.scrollbar = TRUE,
                 preserve.order = TRUE,
                 listFont = "Courier 12",
                 labelFont = "Helvetica 11",
                 windowPos = "+150+30")

Arguments

vec | a vector
nsets | a positive integer, the number of subsets to be selected
return.indices | logical, whether indices (TRUE) or vector contents (FALSE) are to be returned
setlabels | a character vector of labels for the subsets
edit.setlabels | logical, determines whether a textbox is provided for editing the label of each subset
subset | logical, character or numeric vector indicating which elements of vec should be made available for selection. Default is to make all elements available.
warningText | character, text to use as a warning in situations where no selection is made into one or more of the specified sets
title | character, title of the Tk dialog window
items.label | character, a label for the set of items to be selected from
labels.prompt | character, a prompt for textual set label(s)
list.height | maximum number of elements of vec to display at once
items.scrollbar | logical, whether a scrollbar is to be provided when vec is longer than list.height
preserve.order | logical: should the order of items in vec be maintained in all of the returned subsets?
listFont | a Tk font specification for the items list and subsets
labelFont | a Tk font specification for the labels entrybox
windowPos | position of the Tk dialog, in pixels from top left of display

Details

If return.indices is used together with subset, the indices returned relate to vec, not to vec[subset].

Value

EITHER (if the dialog is ended with "OK") a list, with nsets components. Each component is a selected sub-vector, or a numeric vector of indices for a selected sub-vector (if return.indices is TRUE). The component names are as specified in setlabels, or as specified interactively.
OR (if either "Cancel" or the close-window control button is used) NULL.

Author(s)

David Firth, d.firth@warwick.ac.uk

Examples

## This cannot be run by example() but should be OK when pasted
## into an interactive R session
## Not run:
pickFrom(c("apple", "banana", "plum", "grapefruit"), nsets = 2,
  preserve.order = FALSE,
  setlabels = c("Fruits I like", "Fruits I tolerate"))
## End(Not run)
[Package relimp version 0.9-7 Index]


Convert a Character Vector to Tcl Format

Description

Converts a character vector into a brace-delimited Tcl list

Usage

R.to.Tcl(character.vector)

Arguments

character.vector A character vector

Value

A character vector of length 1

Author(s)

David Firth, d.firth@warwick.ac.uk

See Also

Tcl.to.R

Examples

R.to.Tcl(c("apple","banana"))


Relative Importance of Predictors in a Regression Model

Description

Produces a summary of the relative importance of two predictors or two sets of predictors in a fitted model object.

Usage

relimp(object, set1=NULL,  set2=NULL, label1="set1", label2="set2",
          subset=TRUE,
          response.cat=NULL, ...)
print.relimp(x, digits=3, ...)

Arguments

object | A model object of class lm, glm, coxph, survreg, multinom, polr, gls or lme
set1 | An index or vector of indices for the effects to be included in the numerator of the comparison
set2 | An index or vector of indices for the effects to be included in the denominator of the comparison
label1 | A character string; mnemonic name for the variables in set1
label2 | A character string; mnemonic name for the variables in set2
subset | Either a vector of numeric indices for the cases to be included in the standardization of effects, or a vector of logicals (TRUE for inclusion) whose length is the same as the number of rows in the model frame, object$model. The default choice is to include all cases in the model frame.
response.cat | If object is of class multinom, this is a character string used to specify which regression is of interest (i.e., the regression which predicts the log odds on response cat versus the model's reference category). The response.cat argument should be an element of object$lab; or NULL if object is not of class multinom.
... | For models of class glm, one may additionally set the dispersion parameter for the family (for example, dispersion=1.69). By default it is obtained from object. Supplying it here permits explicit allowance for over-dispersion, for example.
x | an object of class relimp
digits | The number of decimal places to be used in the printed summary. Default is 3.

Details

If set1 and set2 both have length 1, relative importance is measured by the ratio of the two standardized coefficients. Equivalently this is the ratio of the standard deviations of the two contributions to the linear predictor, and this provides the generalization to comparing two sets rather than just a pair of predictors.

The computed ratio is the square root of the variance-ratio quantity denoted as `omega' in Silber, J H, Rosenbaum, P R and Ross, R N (1995). Estimated standard errors are calculated by the delta method, as described in that paper for example.

If set1 and set2 are unspecified, and if the tcltk package has been loaded, a dialog box is provided (by a call to pickFrom) for the choice of set1 and set2 from the available model coefficients.

Value

An object of class relimp, with at least the following components:

model | The call used to construct the model object summarized
sets | The two sets of indices specified as arguments
log.ratio | The natural logarithm of the ratio of effect standard deviations corresponding to the two sets specified
se.log.ratio | An estimated standard error for log.ratio

If dispersion was supplied as an argument, its value is stored as the dispersion component of the resultant object.

Author(s)

David Firth d.firth@warwick.ac.uk

References

Silber, J. H., Rosenbaum, P. R. and Ross, R N (1995) Comparing the Contributions of Groups of Predictors: Which Outcomes Vary with Hospital Rather than Patient Characteristics? JASA 90, 7–18.

See Also

relrelimp

Examples

x <- rnorm(100)
z <- rnorm(100)
w <- rnorm(100)
y <- 3+ 2*x + z + w + rnorm(100)
test <- lm(y ~ x +z +w)
print(test)
relimp(test, 2, 3)    #  compares effects of x and z
relimp(test, 2, 3:4)  #  compares effect of x with that of (z,w) combined
##
##  Data on housing and satisfaction, from Venables and Ripley
##  -- multinomial logit model
library(MASS)
library(nnet)
data(housing)
house.mult <- multinom(Sat ~ Infl + Type + Cont, weights = Freq,
  data = housing)
relimp(house.mult, set1 = 2:3, set2 = 7, response.cat = "High")


Comparison of Relative Importances in a Multinomial Logit Model

Description

Produces a summary of the relative importance of two predictors or two sets of predictors in a fitted multinom model object, and compares relative importances across two of the fitted logit models.

Usage

relrelimp(object, set1=NULL, set2=NULL, label1="set1", label2="set2",
          subset=TRUE,
          response.cat1=NULL, response.cat2=NULL)

Arguments

object | A model object of class multinom
set1 | An index or vector of indices for the effects to be included in the numerator of the comparison
set2 | An index or vector of indices for the effects to be included in the denominator of the comparison
label1 | A character string; mnemonic name for the variables in set1
label2 | A character string; mnemonic name for the variables in set2
subset | Either a vector of numeric indices for the cases to be included in the standardization of effects, or a vector of logicals (TRUE for inclusion) whose length is the same as the number of rows in the model frame, object$model. The default choice is to include all cases in the model frame.
response.cat1 | A character string used to specify the first regression of interest (i.e., the regression which predicts the log odds on response.cat1 versus the model's reference category). The response.cat1 argument should be an element of object$lab.
response.cat2 | A character string used to specify the second regression of interest (i.e., the regression which predicts the log odds on response.cat2 versus the model's reference category). The response.cat2 argument should be an element of object$lab.

Details

Computes a relative importance summary as described in relimp, for each of the two regressions specified by response.cat1 and response.cat2 (relative to the same reference category); and computes the difference of those two relative importance summaries, along with an estimated standard error for that difference.

Value

An object of class relrelimp, with at least the following components:

model | The call used to construct the model object summarized
sets | The two sets of indices specified as arguments
response.category | A character vector containing the specified response.cat1 and response.cat2
log.ratio | The natural logarithm of the ratio of effect standard deviations corresponding to the two sets specified. A vector with three components: the first is for response.cat1 versus the reference category, the second for response.cat2 versus the reference category, the third is the difference.
se.log.ratio | Estimated standard errors for the elements of log.ratio

Author(s)

David Firth, d.firth@warwick.ac.uk

See Also

relimp

Examples

##  Data on housing and satisfaction, from Venables and Ripley
library(MASS)
library(nnet)
data(housing)
house.mult <- multinom(Sat ~ Infl + Type + Cont, weights = Freq,
  data = housing)
relrelimp(house.mult, set1 = 2:3, set2 = 7,
                      label1 = "Influence", label2 = "Contact",
                      response.cat1 = "Medium", response.cat2 = "High")
## Computes the relative contribution of Influence and Contact in
## each of the two logistic regressions (Med/Low and High/Low), and
## compares those two relative-contribution measures.


Display a Data Frame in a Tk Text Widget

Description

Displays the contents of a data frame in a modeless Tk text window, for inspection. Objects not of class data.frame, for example objects of class table, or matrix, are coerced using as.data.frame prior to display.

Usage

showData(dataframe,
       colname.bgcolor = "grey50",
       rowname.bgcolor = "grey50",
       body.bgcolor = "white",
       colname.textcolor = "white",
       rowname.textcolor = "white",
       body.textcolor = "black",
       font = "Courier 12",
       maxheight = 30,
       maxwidth = 80,
       title = NULL,
       rowname.bar = "left",
       colname.bar = "top",
       rownumbers = FALSE,
       placement = "-20-40",
       suppress.X11.warnings = TRUE)

Arguments

dataframe | A data frame, or an object to which as.data.frame() can be validly applied
colname.bgcolor | A background colour for the variable-names panel
rowname.bgcolor | A background colour for the row-names panel
body.bgcolor | A background colour for the data
colname.textcolor | A colour for the variable names
rowname.textcolor | A colour for the row names
body.textcolor | A colour for the data
font | The text font used – should be a monospaced font
maxheight | The maximum number of rows to display
maxwidth | The maximum width of display, in characters
title | A title for the window. Default is to use the name of the dataframe as given in the call to showData()
rowname.bar | position of sidebar for row names, "left" or "right", or c("left","right"), or NULL
colname.bar | position of column names, "top" or "bottom", or c("top","bottom"), or NULL
rownumbers | logical, whether row numbers should be displayed
placement | Position of the bottom right corner of the window
suppress.X11.warnings | logical, if TRUE then any X11 warnings are suppressed

Value

invisible(NULL)

Note

An error results if the printed representation of dataframe exceeds the maximum allowed width of 10000 characters; see options.

Text can be copied from the Tk window to the system clipboard, using <Control-C> or via a right-click pop-up menu.

On some systems the window may take a few seconds to appear if the data frame is very large.

Author(s)

David Firth, d.firth@warwick.ac.uk

Examples

## This cannot be run by example() but should be OK when pasted
## into an interactive R session
## Not run:
data(mtcars)
showData(mtcars)
## End(Not run)


Convert a Tcl List to R Character Vector

Description

Converts a brace-delimited list from Tcl into a character vector

Usage

Tcl.to.R(tcl.list)

Arguments

tcl.list a character string

Value

a character vector

Author(s)

David Firth, d.firth@warwick.ac.uk

See Also

R.to.Tcl

Examples

Tcl.to.R("{apple} {banana} {pear}")