Title: | Relative Contribution of Effects in a Regression Model |
---|---|
Description: | Functions to facilitate inference on the relative importance of predictors in a linear or generalized linear model, and a couple of useful Tcl/Tk widgets. |
Authors: | David Firth with contributions from Heather Turner and John Fox |
Maintainer: | David Firth <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0-5 |
Built: | 2024-11-06 06:39:42 UTC |
Source: | CRAN |
Provides a Tk dialog or a text-based menu for interactive selection of one or more subsets from a vector.
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, graphics = TRUE, listFont = "Courier 12", labelFont = "Helvetica 11", windowPos = "+150+30")
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, graphics = TRUE, listFont = "Courier 12", labelFont = "Helvetica 11", windowPos = "+150+30")
vec |
a vector |
nsets |
a positive integer, the number of subsets to be selected |
return.indices |
logical, whether indices ( |
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 |
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 |
items.scrollbar |
logical, whether a scrollbar is to be provided when
|
preserve.order |
logical: should the order of items in |
graphics |
logical: should a dialog be used, if possible? |
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 |
If graphics = TRUE
and the tcltk
package is operational,
a Tk dialog is used, otherwise a text menu.
If return.indices
is used together with subset
, the
indices returned relate to vec
, not to vec[subset]
.
EITHER (in the case of a text menu or 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 the dialog is ended either "Cancel" or the close-window control
button is used)
NULL
.
David Firth, with contributions from Heather Turner
## These examples 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) ## Not run: ## Type selections as e.g. 1:2, 4 pickFrom(c("apple", "banana", "plum", "grapefruit"), nsets = 2, preserve.order = FALSE, setlabels = c("Fruits I like", "Fruits I tolerate"), graphics = FALSE) ## End(Not run)
## These examples 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) ## Not run: ## Type selections as e.g. 1:2, 4 pickFrom(c("apple", "banana", "plum", "grapefruit"), nsets = 2, preserve.order = FALSE, setlabels = c("Fruits I like", "Fruits I tolerate"), graphics = FALSE) ## End(Not run)
Converts a character vector into a brace-delimited Tcl list
R.to.Tcl(character.vector)
R.to.Tcl(character.vector)
character.vector |
A character vector |
A character vector of length 1
David Firth, [email protected]
R.to.Tcl(c("apple","banana"))
R.to.Tcl(c("apple","banana"))
Produces a summary of the relative importance of two predictors or two sets of predictors in a fitted model object.
relimp(object, set1=NULL, set2=NULL, label1="set1", label2="set2", subset=TRUE, response.cat=NULL, ...) ## S3 method for class 'relimp' print(x, digits=3, ...)
relimp(object, set1=NULL, set2=NULL, label1="set1", label2="set2", subset=TRUE, response.cat=NULL, ...) ## S3 method for class 'relimp' print(x, digits=3, ...)
object |
A model object of class
|
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 |
label2 |
A character string; mnemonic name for the
variables in |
subset |
Either a vector of numeric indices for the cases to be included
in the standardization of effects, or a vector of logicals
( |
response.cat |
If |
... |
For models of class |
x |
an object of class |
digits |
The number of decimal places to be used in the printed summary. Default is 3. |
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.
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.
David Firth [email protected]
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.
set.seed(182) ## an arbitrary number, just for reproducibility 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")
set.seed(182) ## an arbitrary number, just for reproducibility 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")
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.
relrelimp(object, set1=NULL, set2=NULL, label1="set1", label2="set2", subset=TRUE, response.cat1=NULL, response.cat2=NULL)
relrelimp(object, set1=NULL, set2=NULL, label1="set1", label2="set2", subset=TRUE, response.cat1=NULL, response.cat2=NULL)
object |
A model object of class
|
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 |
label2 |
A character string; mnemonic name for the
variables in |
subset |
Either a vector of numeric indices for the cases to be included
in the standardization of effects, or a vector of logicals
( |
response.cat1 |
A character
string used to specify the first regression of interest
(i.e., the regression
which predicts the log odds on |
response.cat2 |
A character
string used to specify the second regression of interest
(i.e., the regression
which predicts the log odds on |
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.
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
|
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 |
se.log.ratio |
Estimated standard errors for the elements of
|
David Firth, [email protected]
## 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.
## 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.
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.
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)
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)
dataframe |
A data frame, or an object to which
|
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 |
rowname.bar |
position of sidebar for row names, |
colname.bar |
position of column names, |
rownumbers |
logical, whether row numbers should be displayed |
placement |
Position of the bottom right corner of the window |
suppress.X11.warnings |
logical, if |
Invisibly returns the Tk window containing the displayed data frame.
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.
David Firth, [email protected]; with Rcmdr-specific features contributed by John Fox
## 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)
## 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)
Converts a brace-delimited list from Tcl into a character vector
Tcl.to.R(tcl.list)
Tcl.to.R(tcl.list)
tcl.list |
a character string |
a character vector
David Firth, [email protected]
Tcl.to.R("{apple} {banana} {pear}")
Tcl.to.R("{apple} {banana} {pear}")