Title: | Measures of the Sturdiness of Regression Coefficients |
---|---|
Description: | Implements the s-values proposed by Ed. Leamer. It provides a context-minimal approach for sensitivity analysis using extreme bounds to assess the sturdiness of regression coefficients. |
Authors: | Carlos Cinelli |
Maintainer: | Carlos Cinelli <[email protected]> |
License: | GPL-3 |
Version: | 0.1.6.9 |
Built: | 2024-11-04 05:04:36 UTC |
Source: | https://github.com/carloscinelli/svalues |
The R package sValues implements the measure of sturdiness of coefficients proposed by Leamer (2014) and discussed in Leamer (2015). The S-values try to provide a sensible framework to assess the sensitivity of coefficient estimates to model ambiguity.
The main function of the package is the sValues
function.
More information can be found on its help documentation, examples and vignette.
The package also includes an example dataset on economic growth.
Leamer, E. (2014). S-values: Conventional context-minimal measures of the sturdiness of regression coefficients. Working Paper
Leamer, E. (2015). S-values and bayesian weighted all-subsets regressions. European Economic Review.
Extract sValues Model Coefficients/Statistics
## S3 method for class 'sValues' coef(object, type = "default", ...) betas(object) t_values(object) s_values(object) extreme_bounds(object)
## S3 method for class 'sValues' coef(object, type = "default", ...) betas(object) t_values(object) s_values(object) extreme_bounds(object)
object |
an object of class |
type |
which coefficient/statistic to extract? Current options are "betas", "t_values", "s_values", "extreme_bounds" and "default". See details. |
... |
further arguments passed to or from other methods. |
For the coef
function, the default is to extract the beta coefficients, t-values and s-values. You can can get
each one of those individually by setting type
to either "betas", "t_values" or "s_values".
You can also get the extreme bounds of the estimates by setting type
to "extreme_bounds".
Finally, you can set type = "all"
to get everything.
For each option of coef
, there is an alternative helper function with the same name.
That is, coef(x, "betas")
is equivalent to betas(x)
, or coef(x, "extreme_bounds")
is equivalent
to extreme_bounds(x)
.
The function returns a data.frame
with the estimates for each variable.
data(economic_growth) eg_sv <- sValues(GR6096 ~ ., data = economic_growth) eg_betas <- coef(eg_sv, "betas") eg_t_values <- coef(eg_sv, "t_values") eg_s_values <- coef(eg_sv, "s_values") eg_ext_bounds <- coef(eg_sv, "extreme_bounds") # get sturdy estimates for R2 bounds 0.5 - 1 eg_s_values[abs(eg_s_values[3]) > 1, 3, drop = FALSE]
data(economic_growth) eg_sv <- sValues(GR6096 ~ ., data = economic_growth) eg_betas <- coef(eg_sv, "betas") eg_t_values <- coef(eg_sv, "t_values") eg_s_values <- coef(eg_sv, "s_values") eg_ext_bounds <- coef(eg_sv, "extreme_bounds") # get sturdy estimates for R2 bounds 0.5 - 1 eg_s_values[abs(eg_s_values[3]) > 1, 3, drop = FALSE]
Sala i Martin's (88 countries) Leamer's (87 countries) Original (139 countries)
economic_growth economic_growth_original economic_growth_sala_i_martin
economic_growth economic_growth_original economic_growth_sala_i_martin
An object of class data.frame
with 87 rows and 68 columns.
Plot methods for objects of the class sValues
.
## S3 method for class 'sValues' plot(x, type = "t_s_plot", ...)
## S3 method for class 'sValues' plot(x, type = "t_s_plot", ...)
x |
an object of class |
type |
the type of the plot. Current options are t_s_plot which returns a scatterplot of s-values vs t-values for all coefficients and beta_plot which returns a plot of the different estimates for the coefficients. |
... |
additional arguments to be passed to the plot functions. See details. |
Additional arguments:
t_s_plot
R2_bounds
: a numeric vector of length two specifying which R2 bounds range to plot.
beta_plot
variables
: a character vector specifying which variables to plot. Default is "all".
error_bar
: should the error bars be plotted? Default is FALSE
.
ext_bounds_shades
: should shades representing the extreme bounds be plotted? Default is FALSE
.
It returns a ggplot
object with the requested plot.
# growth regressions example data(economic_growth) eg_sv <- sValues(GR6096 ~ ., data = economic_growth) plot(eg_sv, R2_bounds = c(0.5, 1)) plot(eg_sv, R2_bounds = c(0.1, 1)) plot(eg_sv, type = "beta_plot", variable = "OPENDEC1", error_bar = FALSE) plot(eg_sv, type = "beta_plot", variable = "OPENDEC1", error_bar = TRUE)
# growth regressions example data(economic_growth) eg_sv <- sValues(GR6096 ~ ., data = economic_growth) plot(eg_sv, R2_bounds = c(0.5, 1)) plot(eg_sv, R2_bounds = c(0.1, 1)) plot(eg_sv, type = "beta_plot", variable = "OPENDEC1", error_bar = FALSE) plot(eg_sv, type = "beta_plot", variable = "OPENDEC1", error_bar = TRUE)
Succinct display of S-values results.
## S3 method for class 'sValues' print(x, ..., print.length = 6)
## S3 method for class 'sValues' print(x, ..., print.length = 6)
x |
an object of class |
... |
further arguments passed to or from other methods. |
print.length |
how many variables to show in the screen? This is used for pretty printing. The default is 6. |
NULL
data(economic_growth) eg_sv <- sValues(GR6096 ~ ., data = economic_growth) eg_sv str(eg_sv)
data(economic_growth) eg_sv <- sValues(GR6096 ~ ., data = economic_growth) eg_sv str(eg_sv)
str
method for sValues
.
## S3 method for class 'sValues' str(object, max.level = 1, ...)
## S3 method for class 'sValues' str(object, max.level = 1, ...)
object |
an object of class |
max.level |
maximal level of nesting which is applied for displaying nested structures. Default is 1. |
... |
further arguments passed to or from other methods. |
For now, this function is equivalent to print.sValues
.
## S3 method for class 'sValues' summary(object, ...)
## S3 method for class 'sValues' summary(object, ...)
object |
an object of class |
... |
further arguments passed to or from other methods. |
The function sValues
performs the extreme bound analysis proposed by Leamer (2014) and
discussed in Leamer (2015).
For further details see the package vignette.
sValues(..., R2_bounds = c(0.1, 0.5, 1), favorites = NULL, R2_favorites = NULL, scale = TRUE) ## S3 method for class 'formula' sValues(formula, data, R2_bounds = c(0.1, 0.5, 1), favorites = NULL, R2_favorites = NULL, scale = TRUE, ...) ## S3 method for class 'matrix' sValues(m, R2_bounds = c(0.1, 0.5, 1), favorites = NULL, R2_favorites = NULL, scale = TRUE, ...) ## S3 method for class 'data.frame' sValues(df, R2_bounds = c(0.1, 0.5, 1), favorites = NULL, R2_favorites = NULL, scale = TRUE, ...)
sValues(..., R2_bounds = c(0.1, 0.5, 1), favorites = NULL, R2_favorites = NULL, scale = TRUE) ## S3 method for class 'formula' sValues(formula, data, R2_bounds = c(0.1, 0.5, 1), favorites = NULL, R2_favorites = NULL, scale = TRUE, ...) ## S3 method for class 'matrix' sValues(m, R2_bounds = c(0.1, 0.5, 1), favorites = NULL, R2_favorites = NULL, scale = TRUE, ...) ## S3 method for class 'data.frame' sValues(df, R2_bounds = c(0.1, 0.5, 1), favorites = NULL, R2_favorites = NULL, scale = TRUE, ...)
... |
arguments passed to other methods. The first argument should be a |
R2_bounds |
a numeric vector with two or more R2 bounds to be considered in the analysis. The default values are
|
favorites |
optional - a character vector that specifies the "favorite" variables to be used in the analysis.
These variables will have different lower and upper R2 bounds as defined in the |
R2_favorites |
optional - a numeric vector with two or more R2 bounds for the "favorite" variables. |
scale |
should the variables be scaled/standardized to zero mean and unit variance?
The default is |
formula |
an object of the class |
data |
needed only when you pass a formula as first parameter. An object of the class |
m |
an object of class |
df |
an object of class |
sValues
returns an object a list of class "sValues" containing the main results of the analysis:
info
: a list
with the general information about the parameters used in the analysis, such as the
formula, the data, the bounds and favorite variables.
simple
: a list
with the results of the simple linear regressions for each variable.
all
: the results of the linear regression with all variables.
bayes
: a list
with the results of the bayesian regression for each combination of the R2 bounds.
Each bayesian regression includes the coefficient estimates, the variance-covariance matrix and the t-values.
ext_bounds
: a list
with the extreme bounds estimates for each combination of the R2 bounds.
s_values
: a data.frame
with the s_values for each combination of the R2 bounds.
Leamer, E. (2014). S-values: Conventional context-minimal measures of the sturdiness of regression coefficients. Working Paper
Leamer, E. (2015). S-values and bayesian weighted all-subsets regressions. European Economic Review.
coef.sValues
to extract coefficients or statistics;
print.sValues
for printing;
summary.sValues
for summaries;
plot.sValues
for plots.
# growth regressions example ## All variables, No favorites data(economic_growth) eg_sv <- sValues(GR6096 ~ ., data = economic_growth) eg_sv # prints results plot(eg_sv, R2_bounds = c(0.5, 1)) plot(eg_sv, type = "beta_plot", variable = "P60", error_bar = TRUE) coefs_eg <- coef(eg_sv) # extract coefficients coefs_eg ## only 14 variables eg_sv_14 <- sValues(GR6096 ~GDPCH60L + OTHFRAC + ABSLATIT + LT100CR + BRIT + GOVNOM1 + WARTIME + SCOUT + P60 + PRIEXP70 + OIL + H60 + POP1560 + POP6560, data = economic_growth) eg_sv_14 coefs_eg_14 <- coef(eg_sv_14) ## With 14 favorites among all variables favorites <- c("GDPCH60L", "OTHFRAC", "ABSLATIT", "LT100CR", "BRIT", "GOVNOM1", "WARTIME", "SCOUT", "P60", "PRIEXP70", "OIL", "H60", "POP1560", "POP6560") eg_sv_fav <- sValues(GR6096 ~ ., data = economic_growth, R2_bounds = c(0.5, 1), favorites = favorites, R2_favorites = c(0.4, 0.8)) eg_sv_fav plot(eg_sv_fav, R2_bounds = c(0.5, 1)) plot(eg_sv_fav, type = "beta_plot", variable = "P60", error_bar = TRUE) coefs_eg_fav <- coef(eg_sv_fav) coefs_eg_fav
# growth regressions example ## All variables, No favorites data(economic_growth) eg_sv <- sValues(GR6096 ~ ., data = economic_growth) eg_sv # prints results plot(eg_sv, R2_bounds = c(0.5, 1)) plot(eg_sv, type = "beta_plot", variable = "P60", error_bar = TRUE) coefs_eg <- coef(eg_sv) # extract coefficients coefs_eg ## only 14 variables eg_sv_14 <- sValues(GR6096 ~GDPCH60L + OTHFRAC + ABSLATIT + LT100CR + BRIT + GOVNOM1 + WARTIME + SCOUT + P60 + PRIEXP70 + OIL + H60 + POP1560 + POP6560, data = economic_growth) eg_sv_14 coefs_eg_14 <- coef(eg_sv_14) ## With 14 favorites among all variables favorites <- c("GDPCH60L", "OTHFRAC", "ABSLATIT", "LT100CR", "BRIT", "GOVNOM1", "WARTIME", "SCOUT", "P60", "PRIEXP70", "OIL", "H60", "POP1560", "POP6560") eg_sv_fav <- sValues(GR6096 ~ ., data = economic_growth, R2_bounds = c(0.5, 1), favorites = favorites, R2_favorites = c(0.4, 0.8)) eg_sv_fav plot(eg_sv_fav, R2_bounds = c(0.5, 1)) plot(eg_sv_fav, type = "beta_plot", variable = "P60", error_bar = TRUE) coefs_eg_fav <- coef(eg_sv_fav) coefs_eg_fav