SCM

[#6722] Feature request: tidy and glance methods for class "selection"

Date:
2021-04-20 23:59
Priority:
3
State:
Open
Submitted by:
Vincent Arel-Bundock (vincentab)
Assigned to:
Nobody (None)
Product:
sampleSelection
Operating System:
None
Status:
Open
Summary:
Feature request: tidy and glance methods for class "selection"

Detailed description
Hi all,

Thanks a lot for your work on this package!

Would you consider including `tidy` and `glance` methods in your package?

The `broom` package offers a standardized mechanism to extract information from statistical models programmatically, in a predictable way.

The `tidy` method returns a data.frame with one row per estimate, and columns with standardized names: term, estimate, std.error, statistic, p.value, conf.low, conf.high, etc.

The `glance` method returns a one-row data.frame with one model characteristic/statistic per column: nobs, log.lik, etc.

This makes it easy for users to extract information from models without having to investigate the names of elements in summary(x), which is difficult to do in general because all R packages seem to use different conventions.

The other benefit of `broom` methods, is that they are used in a variety of downstream packages. For example, if you implement `glance` and `tidy` methods, your package's models will automatically be supported by my `modelsummary` package, which can help users create regression tables and plots: https://vincentarelbundock.github.io/modelsummary/

Here is a proof of concept of the kind of code you would need to include in the package. Some of this code is broom-specific, but it easy to use standard data.frames also if you want to avoid a dependency.

library(sampleSelection)

mod_selection <- selection(
inlf ~ educ + kidslt6 + kidsge6,
wage ~ educ + exper + expersq,
method = "2step",
data = mroz)

tidy.selection <- function(x,
conf.int = FALSE,
conf.level = 0.95,
...) {
s <- summary(x, ...)
ret <- broom:::as_tidy_tibble(s$estimate,
new_names = c("estimate", "std.error",
"statistic", "p.value"))

# selection models include an outcome and a selection equation
ret$group <- NA_character_
ret$group[s$param$index$betaS] <- "Selection"
ret$group[s$param$index$betaO] <- "Outcome"

if (isTRUE(conf.int)) {
ci <- broom:::broom_confint_terms(x, level = conf.level)
ret <- dplyr::left_join(ret, ci, by = "term")
}
ret
}

glance.selection <- function(x, ...) {
broom:::as_glance_tibble(
nobs = stats::nobs(x),
method = x$method[1],
rho = x$rho,
sigma = x$sigma,
na_types = "icrr")
}

Comments:

No Comments Have Been Posted

Attached Files:

Changes

No Changes Have Been Made to This Item

Thanks to:
Vienna University of Economics and Business Powered By FusionForge