Learn R Programming

⚠️There's a newer version (0.13.0) of this package.Take me there.

fwildclusterboot

The fwildclusterboot package is an R port of STATA’s boottest package.

It implements the fast wild cluster bootstrap algorithm developed in Roodman et al (2019) for regression objects in R. It currently works for regression objects of type lm, felm and fixest from base R and the lfe and fixest packages.

The package’s central function is boottest(). It allows the user to test two-sided, univariate hypotheses using a wild cluster bootstrap. Importantly, it uses the “fast” algorithm developed in Roodman et al, which makes it feasible to calculate test statistics based on a large number of bootstrap draws even for large samples – as long as the number of bootstrapping clusters is not too large.

The fwildclusterboot package currently supports multi-dimensional clustering and one-dimensional, two-sided hypotheses. It supports regression weights, multiple distributions of bootstrap weights, fixed effects, restricted (WCR) and unrestricted (WCU) bootstrap inference and subcluster bootstrapping for few treated clusters (MacKinnon & Webb, (2018)).

The boottest() function

library(fixest)
library(fwildclusterboot)

data(voters)

# fit the model via fixest::feols(), lfe::felm() or stats::lm()
feols_fit <- feols(proposition_vote ~ treatment  + log_income | Q1_immigration + Q2_defense, data = voters)

# bootstrap inference via boottest()
feols_boot <- boottest(feols_fit, clustid = c("group_id1"), B = 9999, param = "treatment")

summary(feols_boot)
#> boottest.fixest(object = feols_fit, clustid = c("group_id1"), 
#>     param = "treatment", B = 9999)
#>  
#>  Observations: 300
#>   Bootstr. Type: rademacher
#>  Clustering: 1-way
#>  Confidence Sets: 95%
#>  Number of Clusters: 40
#> 
#>        term estimate statistic p.value conf.low conf.high
#> 1 treatment    0.079     4.123       0    0.039     0.119

For a longer introduction to the package’s key function, boottest(), please follow this link.

Benchmarks

Results of timing benchmarks of boottest(), with a sample of N = 50000, k = 19 covariates and one cluster of dimension N_G (10 iterations each).

Installation

You can install fwildclusterboot from CRAN or the development version from github by following the steps below:

# from CRAN 
install.packages("fwildclusterboot")

# dev version from github
# note: installation requires Rtools
library(devtools)
install_github("s3alfisc/fwildclusterboot")

Copy Link

Version

Install

install.packages('fwildclusterboot')

Monthly Downloads

109

Version

0.3.4

License

GPL-3

Maintainer

Alexander Fischer

Last Published

May 1st, 2021

Functions in fwildclusterboot (0.3.4)

boot_algo2

Fast wild cluster bootstrap algorithm
cpp_get_nb_threads

Get maximum number of threads on hardware for open mp support
crosstab3

collapse way to calculate crosstabs
crosstab

optimized collapse way to calculate crosstabs
boottest.lm

Fast wild cluster bootstrap inference for object of class lm
create_data

Simulate Data
check_set_nthreads

Simple function that checks that the nber of threads is valid
boottest.felm

Fast wild cluster bootstrap inference for object of class felm
boottest

Fast wild cluster bootstrap inference
crosstab4

Function 4 to calculate crosstabs
boottest.fixest

Fast wild cluster bootstrap inference for object of class fixest
glance.boottest

S3 method to glance at objects of class boottest
getBoottest_nthreads

get the number of threads for use with open mp
voters

Random example data set
tidy.boottest

S3 method to summarize objects of class boottest into tidy data.frame
plot.boottest

Plot the bootstrap distribution of t-statistics
setBoottest_nthreads

Set the number of threads for use with open mp via options By default, only one thread is used
summary.boottest

S3 method to summarize objects of class boottest
preprocess2

function that pre-processes regression objects of type lm, fixest and feols
eigenMapMatMult

Matrix Multiplication via Eigen
eigenMatMult

Matrix Multiplication via Eigen
invert_p_val2

Calculation of Confidence Sets
p_val_null2

Calculate p-values based on A, B, CC, CD, DD and other inputs
.onLoad

setting options for nthreads when package is loaded