Skip to content

Commit

Permalink
4x speed for cluster with purrr
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Feb 5, 2024
1 parent 76ed19f commit 62b7a54
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 21 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Imports:
Formula,
magrittr,
MASS,
purrr,
rlang,
stats
Suggests:
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ importFrom(dplyr,ungroup)
importFrom(dplyr,vars)
importFrom(dplyr,where)
importFrom(magrittr,"%>%")
importFrom(purrr,map_dfr)
importFrom(rlang,":=")
importFrom(rlang,sym)
importFrom(stats,as.formula)
Expand Down
1 change: 1 addition & 0 deletions R/capybara-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#' @name capybara-package
#' @importFrom dplyr all_of filter group_by mutate mutate_at select summarise
#' ungroup vars where
#' @importFrom purrr map_dfr
#' @importFrom rlang sym :=
#' @importFrom Formula Formula
#' @importFrom MASS negative.binomial theta.ml
Expand Down
7 changes: 3 additions & 4 deletions R/generics_vcov.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ vcov.feglm <- function(
cl <- cl.combn[, j]
B.r <- B.r + crossprod(
as.matrix(
do.call(
rbind,
lapply(split(G, G[, cl]), function(df) colSums(df[sp.vars]))
)
G %>%
split(.[, cl]) %>%
map_dfr(~ colSums(.x[sp.vars]))
)
)
}
Expand Down
5 changes: 3 additions & 2 deletions docs/articles/intro.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-02-05T06:34Z
last_built: 2024-02-05T19:03Z

6 changes: 3 additions & 3 deletions docs/reference/apes.html

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

4 changes: 2 additions & 2 deletions docs/reference/bias_corr.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/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.

14 changes: 9 additions & 5 deletions vignettes/intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ summary(fepoisson(
))
```

The coefficients are almost idential to those in Table 3 from @Yotov2016 that
were obtained with Stata.
The coefficients are almost identical to those in Table 3 from
@yotov2016advanced that were obtained with Stata. The difference is attributed
to the different fitting algorithms used by the two software.

To cluster the standard errors, we need to crete a pair variable and modify
the model formula to add a cluster term. The result is similar and the
difference is explained by the different algorithms used to estimate the
variance-covariance matrix, which is based on @cameron2011robust.
the model formula to add a cluster term.

```{r}
dppml <- dppml %>%
Expand All @@ -83,4 +82,9 @@ summary(
)
```

The result is similar and the difference is explained by the different
algorithms used to estimate the variance-covariance matrix. Capybara clustering
algorithm is based on @cameron2011robust while Stata uses a sandwich-type
estimator.

# References

0 comments on commit 62b7a54

Please sign in to comment.