Skip to content

Commit

Permalink
Pass ... to summary.fixest
Browse files Browse the repository at this point in the history
  • Loading branch information
grantmcdermott committed Dec 12, 2023
1 parent e690ee1 commit f837d3c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export(ggiplot)
export(iplot_data)
import(fixest)
import(ggplot2)
importFrom(fixest,coefplot)
importFrom(fixest,iplot)
3 changes: 3 additions & 0 deletions R/ggcoefplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
#' channel. For example, we can make the CI band lighter with
#' `ci.fill.par = list(alpha = 0.2)` (the default alpha is 0.3).
#' * `dict` a dictionary for overriding coefficient names.
#' * All other `...` arguments are passed to `summary.fixest` before plotting
#' (e.g., for on-the-fly VCOV adjustment) and will be silently ignored if
#' not relevant.
#' @details These functions generally try to mimic the functionality and (where
#' appropriate) arguments of `fixest::coefplot` and `fixest::iplot` as
#' closely as possible. However, by leveraging the ggplot2 API and
Expand Down
9 changes: 4 additions & 5 deletions R/ggiplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ ggiplot = function(
ref.line.par = list(col = "black", lty = 2, lwd = 0.3)
if (!is.null(dots[["ref.line.par"]])) ref.line.par = utils::modifyList(ref.line.par, dots[["ref.line.par"]])


# The next few blocks grab the underlying iplot/coefplot data, contingent on the
# object that was passed into the function (i.e. fixest, fixest_multi, or
# list)
Expand All @@ -58,11 +57,11 @@ ggiplot = function(
if (inherits(object, c("fixest", "fixest_multi"))) {

if (length(ci_level) == 1) {
data = iplot_data_func(object, .ci_level = ci_level, .dict = dict, .aggr_es = aggr_eff, .keep = keep, .drop = drop, .group = group, .i.select = i.select)
data = iplot_data_func(object, .ci_level = ci_level, .dict = dict, .aggr_es = aggr_eff, .keep = keep, .drop = drop, .group = group, .i.select = i.select, ...)
} else {
data = lapply(
ci_level,
function(ci_l) iplot_data_func(object, .ci_level = ci_l, .dict = dict, .aggr_es = aggr_eff, .keep = keep, .drop = drop, .group = group, .i.select = i.select)
function(ci_l) iplot_data_func(object, .ci_level = ci_l, .dict = dict, .aggr_es = aggr_eff, .keep = keep, .drop = drop, .group = group, .i.select = i.select, ...)
)
data = do.call("rbind", data)
}
Expand All @@ -82,13 +81,13 @@ ggiplot = function(
if (length(ci_level) == 1) {
data = lapply(
object, iplot_data_func,
.ci_level = ci_level, .dict = dict, .aggr_es = aggr_eff, .group = group, .i.select = i.select
.ci_level = ci_level, .dict = dict, .aggr_es = aggr_eff, .group = group, .i.select = i.select, ...
)
} else {
data = lapply(ci_level, function(ci_l) {
lapply(object, iplot_data_func,
.ci_level = ci_l,
.dict = dict, .aggr_es = aggr_eff, .group = group, .i.select = i.select
.dict = dict, .aggr_es = aggr_eff, .group = group, .i.select = i.select, ...
)
})
data = do.call(function(...) Map("rbind", ...), data)
Expand Down
17 changes: 13 additions & 4 deletions R/iplot_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
#' aggregated mean treatment effects for some subset of the model should be
#' added as a column to the returned data frame. Passed to
#' `aggr_es(..., aggregation = "mean")`.
#' @param ... Other arguments passed on to `summary.fixest`, e.g. for
#' post-estimation VCOV adjustment. Irrelevant arguments will be silently
#' ignored.
#' @details This function is a wrapper around
#' `fixest::iplot(..., only.params = TRUE)`, but with various checks and tweaks
#' to better facilitate plotting with `ggplot2` and handling of complex object
Expand All @@ -51,6 +54,7 @@
#' relative x-axis positions, and other aesthetic information needed to draw
#' a ggplot2 object.
#' @import ggplot2
#' @importFrom fixest coefplot iplot
#' @export
#' @examples
#' library(fixest)
Expand All @@ -77,7 +81,8 @@ iplot_data = function(
.i.select = 1,
# .aggr_es = c("none", "post", "pre", "both"),
.aggr_es = NULL,
.group = "auto"
.group = "auto",
...
) {

# .aggr_es = match.arg(.aggr_es)
Expand All @@ -94,7 +99,10 @@ iplot_data = function(
.group = NULL
}

p = fixest::coefplot(object, only.params = TRUE, ci_level = .ci_level, dict = .dict, keep = .keep, drop = .drop, internal.only.i = .internal.only.i, i.select = .i.select)
# Catch any args pass through ... to summary.fixest (e.g., vcov adjustments)
object = summary(object, ...)

p = coefplot(object, only.params = TRUE, ci_level = .ci_level, dict = .dict, keep = .keep, drop = .drop, internal.only.i = .internal.only.i, i.select = .i.select)
d = p$prms

if (inherits(object, "fixest_multi")) {
Expand Down Expand Up @@ -423,9 +431,10 @@ coefplot_data = function(
.dict = fixest::getFixest_dict(),
.internal.only.i = FALSE,
.i.select = 1,
.aggr_es = "none"
.aggr_es = "none",
...
) {

iplot_data(object, .ci_level = .ci_level, .dict = .dict, .keep = .keep, .drop = .drop, .internal.only.i = .internal.only.i, .group = .group)
iplot_data(object, .ci_level = .ci_level, .dict = .dict, .keep = .keep, .drop = .drop, .internal.only.i = .internal.only.i, .group = .group, ...)

}
3 changes: 3 additions & 0 deletions man/ggcoefplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions man/iplot_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f837d3c

Please sign in to comment.