Skip to content

Commit

Permalink
Ungroups the data to avoid issues with the model matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed May 14, 2024
1 parent cec1ef7 commit 5fe36d0
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 12 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Imports:
rlang,
stats
Suggests:
fixest,
knitr,
rmarkdown,
testthat (>= 3.0.0),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# capybara 0.4.5

* Ungroups the data to avoid issues with the model matrix

# capybara 0.4

* Uses R's C API efficiently to add a bit more of memory optimizations
Expand Down
8 changes: 8 additions & 0 deletions R/feglm.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
#' )
#'
#' summary(mod)
#'
#' mod <- feglm(
#' trade ~ log_dist + lang + cntg + clny | exp_year + imp_year | pair,
#' trade_panel,
#' family = poisson(link = "log")
#' )
#'
#' summary(mod, type = "clustered")
#' @export
feglm <- function(
formula = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ update_formula_ <- function(formula) {
}

model_frame_ <- function(data, formula, weights) {
data <- select(data, all_of(c(all.vars(formula), weights)))
data <- select(ungroup(data), all_of(c(all.vars(formula), weights)))

lhs <- names(data)[[1L]]

Expand Down
8 changes: 4 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ output: github_document

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

Expand Down
3 changes: 3 additions & 0 deletions docs/news/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pkgdown: 2.0.7
pkgdown_sha: ~
articles:
intro: intro.html
last_built: 2024-04-09T14:22Z
last_built: 2024-05-14T01:44Z

2 changes: 1 addition & 1 deletion docs/reference/apes.html

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

2 changes: 1 addition & 1 deletion docs/reference/bias_corr.html

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

32 changes: 31 additions & 1 deletion docs/reference/feglm.html

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

2 changes: 1 addition & 1 deletion docs/reference/felm.html

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

2 changes: 1 addition & 1 deletion docs/reference/fenegbin.html

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

2 changes: 1 addition & 1 deletion docs/reference/fepoisson.html

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

8 changes: 8 additions & 0 deletions man/feglm.Rd

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

17 changes: 17 additions & 0 deletions tests/testthat/test-feglm.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test_that("fepoisson is similar to fixest", {
mod <- fepoisson(
trade ~ log_dist + lang + cntg + clny | exp_year + imp_year | pair,
trade_panel
)

mod_fixest <- fixest::fepois(
trade ~ log_dist + lang + cntg + clny | exp_year + imp_year,
trade_panel,
cluster = ~pair
)

summary_mod <- summary(mod, type = "clustered")
summary_mod_fixest <- summary(mod_fixest)

expect_equal(unname(round(summary_mod$cm[,2] - summary_mod_fixest$coeftable[,2], 2)), rep(0, 4))
})

0 comments on commit 5fe36d0

Please sign in to comment.