Skip to content

Commit

Permalink
Add quick argument to felm tidier (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpghayes committed Oct 22, 2018
2 parents 140eb58 + b2982b9 commit e2d9ed0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
5 changes: 4 additions & 1 deletion NEWS.md
Expand Up @@ -140,15 +140,18 @@ Several old vignettes have also been updated:
- Added `conf.int` argument to `tidy.coxph` (#220 by @larmarange)
- Added `augment` method for chi-squared tests (#138 by @larmarange)
- changed default se.type for `tidy.rq` to match that of `quantreg::summary.rq()` (#404 by @ethchr)
- Added argument `quick` for `tidy.plm` and `tidy.felm` (#502 and #509 by @MatthieuStigler)
- Many small improvements throughout


## Contributors

Many many thanks to all the following for their thoughtful comments on design, bug reports and PRs! The community of broom contributors has been kind, supportive and insightful and I look forward to working you all again!

[@atyre2](https://github.com/atyre2), [@batpigandme](https://github.com/batpigandme), [@bfgray3](https://github.com/bfgray3), [@bmannakee](https://github.com/bmannakee), [@briatte](https://github.com/briatte), [@cawoodjm](https://github.com/cawoodjm), [@cimentadaj](https://github.com/cimentadaj), [@dan87134](https://github.com/dan87134), [@dgrtwo](https://github.com/dgrtwo), [@dmenne](https://github.com/dmenne), [@ekatko1](https://github.com/ekatko1), [@ellessenne](https://github.com/ellessenne), [@erleholgersen](https://github.com/erleholgersen),
[@ethchr](https://github.com/ethchr),
[@Hong-Revo](https://github.com/Hong-Revo), [@huftis](https://github.com/huftis), [@IndrajeetPatil](https://github.com/IndrajeetPatil), [@jacob-long](https://github.com/jacob-long), [@jarvisc1](https://github.com/jarvisc1), [@jenzopr](https://github.com/jenzopr), [@jgabry](https://github.com/jgabry), [@jimhester](https://github.com/jimhester), [@josue-rodriguez](https://github.com/josue-rodriguez), [@karldw](https://github.com/karldw), [@kfeilich](https://github.com/kfeilich), [@larmarange](https://github.com/larmarange), [@lboller](https://github.com/lboller), [@mariusbarth](https://github.com/mariusbarth), [@michaelweylandt](https://github.com/michaelweylandt), [@mine-cetinkaya-rundel](https://github.com/mine-cetinkaya-rundel), [@mkuehn10](https://github.com/mkuehn10), [@mvevans89](https://github.com/mvevans89), [@nutterb](https://github.com/nutterb), [@ShreyasSingh](https://github.com/ShreyasSingh), [@stephlocke](https://github.com/stephlocke), [@strengejacke](https://github.com/strengejacke), [@topepo](https://github.com/topepo), [@willbowditch](https://github.com/willbowditch), [@WillemSleegers](https://github.com/WillemSleegers), and [@wilsonfreitas](https://github.com/wilsonfreitas)
[@Hong-Revo](https://github.com/Hong-Revo), [@huftis](https://github.com/huftis), [@IndrajeetPatil](https://github.com/IndrajeetPatil), [@jacob-long](https://github.com/jacob-long), [@jarvisc1](https://github.com/jarvisc1), [@jenzopr](https://github.com/jenzopr), [@jgabry](https://github.com/jgabry), [@jimhester](https://github.com/jimhester), [@josue-rodriguez](https://github.com/josue-rodriguez), [@karldw](https://github.com/karldw), [@kfeilich](https://github.com/kfeilich), [@larmarange](https://github.com/larmarange), [@lboller](https://github.com/lboller), [@mariusbarth](https://github.com/mariusbarth), [@michaelweylandt](https://github.com/michaelweylandt), [@mine-cetinkaya-rundel](https://github.com/mine-cetinkaya-rundel), [@mkuehn10](https://github.com/mkuehn10), [@mvevans89](https://github.com/mvevans89), [@nutterb](https://github.com/nutterb), [@ShreyasSingh](https://github.com/ShreyasSingh), [@stephlocke](https://github.com/stephlocke), [@strengejacke](https://github.com/strengejacke), [@topepo](https://github.com/topepo), [@willbowditch](https://github.com/willbowditch), [@WillemSleegers](https://github.com/WillemSleegers), [@wilsonfreitas](https://github.com/wilsonfreitas), and
[@MatthieuStigler](https://github.com/MatthieuStigler)

# broom 0.4.4

Expand Down
38 changes: 25 additions & 13 deletions R/lfe-tidiers.R
Expand Up @@ -3,6 +3,7 @@
#'
#' @param x A `felm` object returned from [lfe::felm()].
#' @template param_confint
#' @template param_quick
#' @param fe Logical indicating whether or not to include estimates of
#' fixed effects. Defaults to `FALSE`.
#' @template param_unused_dots
Expand Down Expand Up @@ -44,11 +45,18 @@
#' @aliases felm_tidiers lfe_tidiers
#' @family felm tidiers
#' @seealso [tidy()], [lfe::felm()]
tidy.felm <- function(x, conf.int = FALSE, conf.level = .95, fe = FALSE, ...) {
nn <- c("estimate", "std.error", "statistic", "p.value")
ret <- fix_data_frame(stats::coef(summary(x)), nn)
tidy.felm <- function(x, conf.int = FALSE, conf.level = .95, fe = FALSE, quick = FALSE, ...) {

if (conf.int) {
if(quick) {
co <- stats::coef(x)
ret <- data_frame(term = names(co), estimate = unname(co))
} else {
nn <- c("estimate", "std.error", "statistic", "p.value")
ret <- fix_data_frame(stats::coef(summary(x)), nn)
}


if (!quick & conf.int) {
# avoid "Waiting for profiling to be done..." message
CI <- suppressMessages(stats::confint(x, level = conf.level))
colnames(CI) <- c("conf.low", "conf.high")
Expand All @@ -57,16 +65,20 @@ tidy.felm <- function(x, conf.int = FALSE, conf.level = .95, fe = FALSE, ...) {

if (fe) {
ret <- mutate(ret, N = NA, comp = NA)
object <- lfe::getfe(x)

nn <- c("estimate", "std.error", "N", "comp")
ret_fe <- lfe::getfe(x, se = TRUE, bN = 100) %>%
select(effect, se, obs, comp) %>%
fix_data_frame(nn) %>%
mutate(statistic = estimate / std.error) %>%
mutate(p.value = 2 * (1 - stats::pt(statistic, df = N)))
if(quick) {
ret_fe <- lfe::getfe(x) %>%
select(effect, obs, comp) %>%
fix_data_frame(c("estimate", "N", "comp"))
} else {
nn <- c("estimate", "std.error", "N", "comp")
ret_fe <- lfe::getfe(x, se = TRUE, bN = 100) %>%
select(effect, se, obs, comp) %>%
fix_data_frame(nn) %>%
mutate(statistic = estimate / std.error) %>%
mutate(p.value = 2 * (1 - stats::pt(statistic, df = N)))
}

if (conf.int) {
if (!quick & conf.int) {

crit_val_low <- stats::qnorm(1 - (1 - conf.level) / 2)
crit_val_high <- stats::qnorm(1 - (1 - conf.level) / 2)
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-lfe.R
Expand Up @@ -29,14 +29,22 @@ test_that("felm tidier arguments", {

test_that("tidy.felm", {
td <- tidy(fit)
td_quick <- tidy(fit, quick = TRUE)
td2 <- tidy(fit2, conf.int = TRUE, fe = TRUE, fe.error = FALSE)
td2_quick <- tidy(fit2, conf.int = TRUE, fe = TRUE, fe.error = FALSE, quick = TRUE)
td3 <- tidy(fit2, conf.int = TRUE, fe = TRUE)
td3_quick <- tidy(fit2, conf.int = TRUE, fe = TRUE, quick = TRUE)
td4 <- tidy(fit_form)
td4_quick <- tidy(fit_form, quick = TRUE)

check_tidy_output(td)
check_tidy_output(td_quick)
check_tidy_output(td2)
check_tidy_output(td2_quick)
check_tidy_output(td3)
check_tidy_output(td3_quick)
check_tidy_output(td4)
check_tidy_output(td4_quick)

check_dims(td, 2, 5)
})
Expand Down

0 comments on commit e2d9ed0

Please sign in to comment.