An open API service indexing awesome lists of open source software.

https://github.com/s3alfisc/fwildclusterboot

Fast Wild Cluster Bootstrap Inference for Regression Models / OLS in R. Additionally, R port to WildBootTests.jl via the JuliaConnectoR.
https://github.com/s3alfisc/fwildclusterboot

clustered-standard-errors linear-regression-models wild-bootstrap wild-cluster-bootstrap

Last synced: about 1 month ago
JSON representation

Fast Wild Cluster Bootstrap Inference for Regression Models / OLS in R. Additionally, R port to WildBootTests.jl via the JuliaConnectoR.

Awesome Lists containing this project

README

        

---
output: github_document
editor_options:
chunk_output_type: console
---

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

# fwildclusterboot

[![Status at rOpenSci Software Peer Review](https://badges.ropensci.org/546_status.svg)](https://github.com/ropensci/software-review/issues/546)
[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![CRAN status](https://www.r-pkg.org/badges/version/fwildclusterboot)](https://CRAN.R-project.org/package=fwildclusterboot)
![runiverse-package](https://s3alfisc.r-universe.dev/badges/fwildclusterboot)
[![R-CMD-check](https://github.com/s3alfisc/fwildclusterboot/workflows/R-CMD-check/badge.svg)](https://github.com/s3alfisc/fwildclusterboot/actions)
[![Codecov test coverage](https://codecov.io/gh/s3alfisc/fwildclusterboot/branch/master/graph/badge.svg)](https://app.codecov.io/gh/s3alfisc/fwildclusterboot?branch=master)
`r badger::badge_cran_download("fwildclusterboot", "grand-total", "blue")`
`r badger::badge_cran_download("fwildclusterboot", "last-month", "green")`

The `{fwildclusterboot}` package implements multiple fast wild cluster bootstrap algorithms as developed in [Roodman et al (2019)](https://econpapers.repec.org/paper/qedwpaper/1406.htm) and [MacKinnon, Nielsen & Webb (2022)](https://www.econ.queensu.ca/sites/econ.queensu.ca/files/wpaper/qed_wp_1485.pdf).

Via the [JuliaConnectoR](https://CRAN.R-project.org/package=JuliaConnectoR), `{fwildclusterboot}` further ports functionality of [WildBootTests.jl](https://github.com/droodman/WildBootTests.jl) - which provides an even faster implementation of the wild cluster bootstrap for OLS and supports the WRE bootstrap for IV and tests of multiple joint hypotheses.

The package's central function is `boottest()`. It allows to test univariate hypotheses using a wild cluster bootstrap at extreme speed: via the 'fast' algorithm, it is possible to run a wild cluster bootstrap with $B = 100.000$ iterations in less than a second!

```{r, fig.width=10, fig.height=3, echo = FALSE, warning = FALSE, message = FALSE}
library(ggplot2)
df <- readRDS("C:/Users/alexa/Dropbox/R package development/fwildclusterboot develop/benchmarks/r_comparions.rds")

df$B <- factor(df$B, levels = c("10K", "100K"))
df$N_G <- factor(df$N_G, levels = c("N_G = 20", "N_G = 50", "N_G = 100", "N_G = 500", "N_G = 1000"))
df$`boot algo` <- df$type
```

```{r, fig.width=10, fig.height=3, echo = FALSE, warning = FALSE, message = FALSE}
ggplot(data = df, aes(x = B, y = time, color = `boot algo`)) +
facet_wrap(~N_G, nrow = 1) +
geom_point() +
scale_y_continuous(trans='log10') +
labs(title = "Benchmarks", caption = "N = 10_000, k = 20 covariates and one cluster of dimension N_G (3 iterations each, median runtime is plotted).")+
#theme_bw() +
xlab("Bootstrap iterations") +
ylab("time in seconds, log scale") +
theme_bw()
```

`{fwildclusterboot}` supports the following features:

+ The wild bootstrap for OLS (Wu 1986).
+ The wild cluster bootstrap for OLS (Cameron, Gelbach & Miller 2008, Roodman et al, 2019).
+ Multiple new versions of the wild cluster bootstrap as described in MacKinnon, Nielsen & Webb (2022), including the WCR13 (WCR-V), WCR31 (WCR-S), WCR33 (WCR-B), WCU13 (WCU-V), WCU31 (WCU-S) and WCU33 (WCU-B).
+ The subcluster bootstrap (MacKinnon and Webb 2018).
+ Confidence intervals formed by inverting the test and iteratively searching for bounds.
+ Multiway clustering.
+ One-way fixed effects.

Additional features are provided through `WildBootTests.jl`:

+ Highly optimized versions of the '11' and '31' wild cluster bootstrap variants
+ A highly optimized version of the Wild Restricted Efficient bootstrap (WRE) for IV/2SLS/LIML [(Davidson & MacKinnon, 2010)](https://www.tandfonline.com/doi/abs/10.1198/jbes.2009.07221).
+ Arbitrary and multiple linear hypotheses in the parameters.

`{fwildclusterboot}` supports the following models:

+ OLS: `lm` (from stats), `fixest` (from fixest), `felm` from (lfe)
+ IV: `ivreg` (from ivreg).

### Installation

You can install compiled versions of`{fwildclusterboot}` from CRAN (compiled), R-universe (compiled) or github by following one of the steps below:

```{r, eval = FALSE}
# from CRAN
install.packages("fwildclusterboot")

# from r-universe (windows & mac, compiled R > 4.0 required)
install.packages('fwildclusterboot', repos ='https://s3alfisc.r-universe.dev')
# dev version from github
# note: installation requires Rtools
library(devtools)
install_github("s3alfisc/fwildclusterboot")
```

### The `boottest()` function

For a longer introduction to `{fwildclusterboot}`, take a look at the [vignette](https://s3alfisc.github.io/fwildclusterboot/articles/fwildclusterboot.html).

```{r, warning = FALSE, message = FALSE}
library(fwildclusterboot)

# set seed via dqset.seed for engine = "R" & Rademacher, Webb & Normal weights
dqrng::dqset.seed(2352342)
# set 'familiar' seed for all other algorithms and weight types
set.seed(23325)

data(voters)

# fit the model via fixest::feols(), lfe::felm() or stats::lm()
lm_fit <- lm(proposition_vote ~ treatment + log_income + as.factor(Q1_immigration) + as.factor(Q2_defense), data = voters)
# bootstrap inference via boottest()
lm_boot <- boottest(lm_fit, clustid = c("group_id1"), B = 9999, param = "treatment")
summary(lm_boot)
```

## Citation

If you are in `R`, you can simply run the following command to get the BibTeX citation for `{fwildclusterboot}`:

```{r, warning = FALSE, message = FALSE}
citation("fwildclusterboot")
```

Alternatively, if you prefer to cite the "Fast & Wild" paper by Roodman et al, it would be great if you mentioned `{fwildclusterboot}` in a footnote =) !