Title: | Fast Wild Cluster Bootstrap Inference for Linear Models |
---|---|
Description: | Implementation of fast algorithms for wild cluster bootstrap inference developed in 'Roodman et al' (2019, 'STATA' Journal, <doi:10.1177/1536867X19830877>) and 'MacKinnon et al' (2022), which makes it feasible to quickly calculate bootstrap test statistics based on a large number of bootstrap draws even for large samples. Multiple bootstrap types as described in 'MacKinnon, Nielsen & Webb' (2022) are supported. Further, 'multiway' clustering, regression weights, bootstrap weights, fixed effects and 'subcluster' bootstrapping are supported. Further, both restricted ('WCR') and unrestricted ('WCU') bootstrap are supported. Methods are provided for a variety of fitted models, including 'lm()', 'feols()' (from package 'fixest') and 'felm()' (from package 'lfe'). Additionally implements a 'heteroskedasticity-robust' ('HC1') wild bootstrap. Last, the package provides an R binding to 'WildBootTests.jl', which provides additional speed gains and functionality, including the 'WRE' bootstrap for instrumental variable models (based on models of type 'ivreg()' from package 'ivreg') and hypotheses with q > 1. |
Authors: | Alexander Fischer [aut, cre], David Roodman [aut], Megha Joshi [rev] (Megha reviewed the package (v. 0.13) for ropensci , see <https://github.com/ropensci/software-review/issues/546>), Eunseop Kim [rev] (Eunseop reviewed the package (v. 0.13) for ropensci , see <https://github.com/ropensci/software-review/issues/546>), Achim Zeileis [ctb] (Author of included sandwich fragments), Nathaniel Graham [ctb] (Contributor to included sandwich fragments), Susanne Koell [ctb] (Contributor to included sandwich fragments), Laurent Berge [ctb] (Author of included fixest fragments), Sebastian Krantz [ctb] |
Maintainer: | Alexander Fischer <[email protected]> |
License: | GPL-3 |
Version: | 0.14.3 |
Built: | 2024-11-21 05:38:24 UTC |
Source: | https://github.com/s3alfisc/fwildclusterboot |
fixest::aggregate()
This is a function helping to replicate the estimator from Sun and Abraham (2021, Journal of Econometrics). You first need to perform an estimation with cohort and relative periods dummies (typically using the function i), this leads to estimators of the cohort average treatment effect on the treated (CATT). Then you can use this function to retrieve the average treatment effect on each relative period,or for any other way you wish to aggregate the CATT.
boot_aggregate( x, agg, full = FALSE, use_weights = TRUE, clustid = NULL, B, bootstrap_type = "fnw11", bootcluster = "max", fe = NULL, sign_level = 0.05, beta0 = NULL, type = "rademacher", impose_null = TRUE, p_val_type = "two-tailed", nthreads = getBoottest_nthreads(), tol = 1e-06, maxiter = 10, ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), engine = getBoottest_engine(), floattype = "Float64", maxmatsize = FALSE, bootstrapc = FALSE, getauxweights = FALSE, sampling = "dqrng", ... )
boot_aggregate( x, agg, full = FALSE, use_weights = TRUE, clustid = NULL, B, bootstrap_type = "fnw11", bootcluster = "max", fe = NULL, sign_level = 0.05, beta0 = NULL, type = "rademacher", impose_null = TRUE, p_val_type = "two-tailed", nthreads = getBoottest_nthreads(), tol = 1e-06, maxiter = 10, ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), engine = getBoottest_engine(), floattype = "Float64", maxmatsize = FALSE, bootstrapc = FALSE, getauxweights = FALSE, sampling = "dqrng", ... )
x |
An object of type fixest estimated using |
agg |
A character scalar describing the variable names to be
aggregated, it is pattern-based. All variables that match the pattern
will be aggregated. It must be of the form |
full |
Logical scalar, defaults to |
use_weights |
Logical, default is |
clustid |
A character vector or rhs formula containing the names of the cluster variables. If NULL, a heteroskedasticity-robust (HC1) wild bootstrap is run. |
B |
Integer. The number of bootstrap iterations. When the number of clusters is low, increasing B adds little additional runtime. |
bootstrap_type |
Determines which wild cluster bootstrap type should be run. Options are "fnw11", which runs a "11" type wild cluster bootstrap via the algorithm outlined in "fast and wild" (Roodman et al (2019)). |
bootcluster |
A character vector or rhs formula of length 1. Specifies
the bootstrap clustering variable or variables. If more
than one variable is specified, then bootstrapping is clustered by the
intersections of
clustering implied by the listed variables. To mimic the behavior of
stata's boottest command,
the default is to cluster by the intersection of all the variables
specified via the |
fe |
A character vector or rhs formula of length one which contains the name of the fixed effect to be projected out in the bootstrap. Note: if regression weights are used, fe needs to be NULL. |
sign_level |
A numeric between 0 and 1 which sets the significance level of the inference procedure. E.g. sign_level = 0.05 returns 0.95% confidence intervals. By default, sign_level = 0.05. |
beta0 |
Deprecated function argument. Replaced by function argument 'r'. |
type |
character or function. The character string specifies the type
of boostrap to use: One of "rademacher", "mammen", "norm"
and "webb". Alternatively, type can be a function(n) for drawing
wild bootstrap factors. "rademacher" by default.
For the Rademacher distribution, if the number of replications B
exceeds
the number of possible draw ombinations, 2^(#number of clusters),
then |
impose_null |
Logical. Controls if the null hypothesis is imposed on
the bootstrap dgp or not. Null imposed |
p_val_type |
Character vector of length 1. Type of p-value. By default "two-tailed". Other options include "equal-tailed", ">" and "<". |
nthreads |
The number of threads. Can be: a) an integer lower than, or equal to, the maximum number of threads; b) 0: meaning all available threads will be used; c) a number strictly between 0 and 1 which represents the fraction of all threads to use. The default is to use 1 core. |
tol |
Numeric vector of length 1. The desired accuracy (convergence tolerance) used in the root finding procedure to find the confidence interval. 1e-6 by default. |
maxiter |
Integer. Maximum number of iterations used in the root finding procedure to find the confidence interval. 10 by default. |
ssc |
An object of class |
engine |
Character scalar. Either "R", "R-lean" or "WildBootTests.jl".
Controls if |
floattype |
Float64 by default. Other option: Float32. Should floating point numbers in Julia be represented as 32 or 64 bit? Only relevant when 'engine = "WildBootTests.jl"' |
maxmatsize |
NULL by default = no limit. Else numeric scalar to set the maximum size of auxilliary weight matrix (v), in gigabytes. Only relevant when 'engine = "WildBootTests.jl"' |
bootstrapc |
Logical scalar, FALSE by default. TRUE to request bootstrap-c instead of bootstrap-t. Only relevant when 'engine = "WildBootTests.jl"' |
getauxweights |
Logical. Whether to save auxilliary weight matrix (v) |
sampling |
'dqrng' or 'standard'. If 'dqrng', the 'dqrng' package is
used for random number generation (when available). If 'standard',
functions from the 'stats' package are used when available.
This argument is mostly a convenience to control random number generation in
a wrapper package around |
... |
misc function arguments |
Note that contrary to the SA article, here the cohort share in the sample is considered to be a perfect measure for the cohort share in the population.
Most of this function is written by Laurent Bergé and used in the fixest package published under GPL-3, https://cran.r-project.org/web/packages/fixest/index.html minor changes by Alexander Fischer
A data frame with aggregated coefficients, p-values and confidence intervals.
## Not run: if(requireNamespace("fixest")){ library(fixest) data(base_stagg) # The DiD estimation res_sunab = feols(y ~ x1 + sunab(year_treated, year) | id + year, base_stagg) res_sunab_3ref = feols(y ~ x1 + sunab( year_treated, year, ref.p = c(.F + 0:2, -1)) | id + year, cluster = "id", base_stagg, ssc = ssc(adj = FALSE, cluster.adj = FALSE)) aggregate(res_sunab, agg = "ATT") # test ATT equivalence boot_att <- boot_aggregate( res_sunab, B = 9999, agg = "ATT", clustid = "id" ) head(boot_att) #'boot_agg2 <- boot_aggregate( res_sunab, B = 99999, agg = TRUE, ssc = boot_ssc(adj = FALSE, cluster.adj = FALSE) ) } ## End(Not run)
## Not run: if(requireNamespace("fixest")){ library(fixest) data(base_stagg) # The DiD estimation res_sunab = feols(y ~ x1 + sunab(year_treated, year) | id + year, base_stagg) res_sunab_3ref = feols(y ~ x1 + sunab( year_treated, year, ref.p = c(.F + 0:2, -1)) | id + year, cluster = "id", base_stagg, ssc = ssc(adj = FALSE, cluster.adj = FALSE)) aggregate(res_sunab, agg = "ATT") # test ATT equivalence boot_att <- boot_aggregate( res_sunab, B = 9999, agg = "ATT", clustid = "id" ) head(boot_att) #'boot_agg2 <- boot_aggregate( res_sunab, B = 99999, agg = TRUE, ssc = boot_ssc(adj = FALSE, cluster.adj = FALSE) ) } ## End(Not run)
boottest()
set the small sample correction factor applied in boottest()
boot_ssc( adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional" )
boot_ssc( adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional" )
adj |
Logical scalar, defaults to TRUE. If TRUE, applies a small sample correction of (N-1) / (N-k) where N is the number of observations and k is the number of estimated coefficients excluding any fixed effects projected out in either fixest::feols() or lfe::felm(). |
fixef.K |
Character scalar, equal to 'none': the fixed effects parameters are discarded when calculating k in (N-1) / (N-k). |
cluster.adj |
Logical scalar, defaults to TRUE. If TRUE, a cluster correction G/(G-1) is performed, with G the number of clusters. |
cluster.df |
Either "conventional"(the default) or "min". Controls how "G" is computed for multiway clustering if cluster.adj = TRUE. Note that the covariance matrix in the multiway clustering case is of the form V = V_1 + V_2 - V_12. If "conventional", then each summand G_i is multiplied with a small sample adjustment G_i / (G_i - 1). If "min", all summands are multiplied with the same value, min(G) / (min(G) - 1) |
A list with encoded info on how to form small sample corrections
boot_ssc(adj = TRUE, cluster.adj = TRUE) boot_ssc(adj = TRUE, cluster.adj = TRUE, cluster.df = "min")
boot_ssc(adj = TRUE, cluster.adj = TRUE) boot_ssc(adj = TRUE, cluster.adj = TRUE, cluster.df = "min")
boottest
is a S3 method that allows for fast wild cluster
bootstrap inference for objects of class lm, fixest and felm by implementing
the fast wild bootstrap algorithm developed in Roodman et al., 2019.
boottest(object, ...)
boottest(object, ...)
object |
An object of type lm, fixest, felm or ivreg |
... |
other arguments |
Technical Details For technical details, either take a look at the references below, or check out the wild (cluster) bootstrap vignette.
An object of class boottest
.
To guarantee reproducibility, you can either use boottest()'s
seed
function argument, or
set a global random seed via
set.seed()
when using
the lean algorithm (via engine = "R-lean"
), 2) the heteroskedastic
wild bootstrap
the wild cluster bootstrap via engine = "R"
with Mammen weights
or 4) engine = "WildBootTests.jl"
dqrng::dqset.seed()
when using engine = "R"
for Rademacher, Webb
or Normal weights
The fast wild cluster bootstrap algorithms are further implemented in the following software packages:
Stata:boottest
Julia:WildBootTests.jl
Python:wildboottest
Roodman et al., 2019, "Fast and wild: Bootstrap inference in STATA using boottest", The STATA Journal. (https://ideas.repec.org/p/qed/wpaper/1406.html)
MacKinnon, James G., Morten Ørregaard Nielsen, and Matthew D. Webb. Fast and reliable jackknife and bootstrap methods for cluster-robust inference. No. 1485. 2022.
Cameron, A. Colin, Jonah B. Gelbach, and Douglas L. Miller. "Bootstrap-based improvements for inference with clustered errors." The Review of Economics and Statistics 90.3 (2008): 414-427.
Cameron, A.Colin & Douglas L. Miller. "A practitioner's guide to cluster-robust inference" Journal of Human Resources (2015) doi:10.3368/jhr.50.2.317
Davidson & MacKinnon. "Wild Bootstrap Tests for IV regression" Journal of Economics and Business Statistics (2010) doi:10.1198/jbes.2009.07221
MacKinnon, James G., and Matthew D. Webb. "The wild bootstrap for few (treated) clusters." The Econometrics Journal 21.2 (2018): 114-135.
MacKinnon, James G., and Matthew D. Webb. "Cluster-robust inference: A guide to empirical practice" Journal of Econometrics (2022) doi:10.1016/j.jeconom.2022.04.001
MacKinnon, James. "Wild cluster bootstrap confidence intervals." L'Actualite economique 91.1-2 (2015): 11-33.
Webb, Matthew D. "Reworking wild bootstrap based inference for clustered errors" . No. 1315. Queen's Economics Department Working Paper, 2013.
boottest.lm, boottest.fixest, boottest.felm, boottest.ivreg
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) summary(boot) print(boot) plot(boot) nobs(boot) pval(boot) confint(boot) generics::tidy(boot)
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) summary(boot) print(boot) plot(boot) nobs(boot) pval(boot) confint(boot) generics::tidy(boot)
boottest.felm
is a S3 method that allows for fast wild cluster
bootstrap inference for objects of class felm by implementing
fast wild bootstrap algorithms as developed in Roodman et al., 2019
and MacKinnon, Nielsen & Webb (2022).
## S3 method for class 'felm' boottest( object, param, B, clustid = NULL, bootcluster = "max", fe = NULL, conf_int = TRUE, R = NULL, r = 0, beta0 = NULL, sign_level = 0.05, type = "rademacher", impose_null = TRUE, bootstrap_type = "fnw11", p_val_type = "two-tailed", tol = 1e-06, maxiter = 10, sampling = "dqrng", nthreads = getBoottest_nthreads(), ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), engine = getBoottest_engine(), floattype = "Float64", maxmatsize = FALSE, bootstrapc = FALSE, getauxweights = FALSE, ... )
## S3 method for class 'felm' boottest( object, param, B, clustid = NULL, bootcluster = "max", fe = NULL, conf_int = TRUE, R = NULL, r = 0, beta0 = NULL, sign_level = 0.05, type = "rademacher", impose_null = TRUE, bootstrap_type = "fnw11", p_val_type = "two-tailed", tol = 1e-06, maxiter = 10, sampling = "dqrng", nthreads = getBoottest_nthreads(), ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), engine = getBoottest_engine(), floattype = "Float64", maxmatsize = FALSE, bootstrapc = FALSE, getauxweights = FALSE, ... )
object |
An object of class felm |
param |
A character vector or rhs formula. The name of the regression coefficient(s) for which the hypothesis is to be tested |
B |
Integer. The number of bootstrap iterations. When the number of clusters is low, increasing B adds little additional runtime. |
clustid |
A character vector or rhs formula containing the names of the cluster variables. If NULL, a heteroskedasticity-robust (HC1) wild bootstrap is run. |
bootcluster |
A character vector or rhs formula of length 1.
Specifies the bootstrap clustering variable or variables. If more
than one variable is specified, then bootstrapping is clustered
by the intersections of
clustering implied by the listed variables. To mimic the behavior
of stata's boottest command,
the default is to cluster by the intersection of all the variables
specified via the |
fe |
A character vector or rhs formula of length one which contains the name of the fixed effect to be projected out in the bootstrap. Note: if regression weights are used, fe needs to be NULL. |
conf_int |
A logical vector. If TRUE, boottest computes confidence intervals by test inversion. If FALSE, only the p-value is returned. |
R |
Hypothesis Vector giving linear combinations of coefficients.
Must be either NULL or a vector of the same length as |
r |
A numeric. Shifts the null hypothesis H0: param = r vs H1: param != r |
beta0 |
Deprecated function argument. Replaced by function argument 'r'. |
sign_level |
A numeric between 0 and 1 which sets the significance level of the inference procedure. E.g. sign_level = 0.05 returns 0.95% confidence intervals. By default, sign_level = 0.05. |
type |
character or function. The character string specifies the type
of boostrap to use: One of "rademacher", "mammen", "norm"
and "webb". Alternatively, type can be a function(n) for drawing
wild bootstrap factors. "rademacher" by default.
For the Rademacher distribution, if the number of replications B
exceeds the number of possible draw ombinations,
2^(#number of clusters), then |
impose_null |
Logical. Controls if the null hypothesis is imposed on
the bootstrap dgp or not. Null imposed |
bootstrap_type |
Determines which wild cluster bootstrap type should be run. Options are "fnw11","11", "13", "31" and "33" for the wild cluster bootstrap and "11" and "31" for the heteroskedastic bootstrap. For more information, see the details section. "fnw11" is the default for the cluster bootstrap, which runs a "11" type wild cluster bootstrap via the algorithm outlined in "fast and wild" (Roodman et al (2019)). "11" is the default for the heteroskedastic bootstrap. |
p_val_type |
Character vector of length 1. Type of p-value. By default "two-tailed". Other options include "equal-tailed", ">" and "<". |
tol |
Numeric vector of length 1. The desired accuracy (convergence tolerance) used in the root finding procedure to find the confidence interval. 1e-6 by default. |
maxiter |
Integer. Maximum number of iterations used in the root finding procedure to find the confidence interval. 10 by default. |
sampling |
'dqrng' or 'standard'. If 'dqrng', the 'dqrng' package is
used for random number generation (when available). If 'standard',
functions from the 'stats' package are used when available.
This argument is mostly a convenience to control random number generation in
a wrapper package around |
nthreads |
The number of threads. Can be: a) an integer lower than, or equal to, the maximum number of threads; b) 0: meaning all available threads will be used; c) a number strictly between 0 and 1 which represents the fraction of all threads to use. The default is to use 1 core. |
ssc |
An object of class |
engine |
Character scalar. Either "R" or "WildBootTests.jl".
Controls the algorithm employed by boottest.
"R" is the default and implements the cluster bootstrap
as in Roodman (2019). "WildBootTests.jl" executes the wild
cluster bootstrap by via the WildBootTests.jl
package. For it to run, Julia and WildBootTests.jl need to
be installed. Check out the set_up_ ... functions
The "fast and wild" algorithm is extremely fast for small
number of clusters, but because it is fully vectorized,
very memory-demanding.
For large number of clusters and large number of bootstrap
iterations, the fast and wild algorithm becomes infeasible.
If a out-of-memory error #
occurs, the "lean" algorithm is a memory friendly, but less
performant rcpp-armadillo based implementation of the wild
cluster bootstrap.
Note that if no cluster is provided, boottest() always
defaults to the "lean" algorithm. Note that you can set the
employed algorithm globally by using the
|
floattype |
Float64 by default. Other option: Float32. Should floating point numbers in Julia be represented as 32 or 64 bit? Only relevant when 'engine = "WildBootTests.jl"' |
maxmatsize |
NULL by default = no limit. Else numeric scalar to set the maximum size of auxilliary weight matrix (v), in gigabytes. Only relevant when 'engine = "WildBootTests.jl"' |
bootstrapc |
Logical scalar, FALSE by default. TRUE to request bootstrap-c instead of bootstrap-t. Only relevant when 'engine = "WildBootTests.jl"' |
getauxweights |
Logical. Whether to save auxilliary weight matrix (v) |
... |
Further arguments passed to or from other methods. |
An object of class boottest
p_val |
The bootstrap p-value. |
conf_int |
The bootstrap confidence interval. |
param |
The tested parameter. |
N |
Sample size. Might differ from the regression sample size if the cluster variables contain NA values. |
boot_iter |
Number of Bootstrap Iterations. |
clustid |
Names of the cluster Variables. |
N_G |
Dimension of the cluster variables as used in boottest. |
sign_level |
Significance level used in boottest. |
type |
Distribution of the bootstrap weights. |
impose_null |
Whether the null was imposed on the bootstrap dgp or not. |
R |
The vector "R" in the null hypothesis of interest Rbeta = r. |
r |
The scalar "r" in the null hypothesis of interest Rbeta = r. |
point_estimate |
R'beta. A scalar: the constraints vector times the regression coefficients. |
grid_vals |
All t-statistics calculated while calculating the confidence interval. |
p_grid_vals |
All p-values calculated while calculating the confidence interval. |
t_stat |
The 'original' regression test statistics. |
t_boot |
All bootstrap t-statistics. |
regression |
The regression object used in boottest. |
call |
Function call of boottest. |
engine |
The employed bootstrap algorithm. |
nthreads |
The number of threads employed. |
To guarantee reproducibility, you need to set a global random seed via
set.seed()
when using
the lean algorithm (via engine = "R-lean"
) including the
heteroskedastic wild bootstrap
the wild cluster bootstrap via engine = "R"
with Mammen weights or
engine = "WildBootTests.jl"
dqrng::dqset.seed()
when using engine = "R"
for Rademacher, Webb
or Normal weights
boottest
computes confidence intervals by inverting p-values.
In practice, the following procedure is used:
Based on an initial guess for starting values, calculate p-values for 26 equal spaced points between the starting values.
Out of the 26 calculated p-values, find the two pairs of values x for which the corresponding p-values px cross the significance level sign_level.
Feed the two pairs of x into an numerical root finding procedure and
solve for the root. boottest currently relies on
stats::uniroot
and sets an absolute tolerance of 1e-06 and
stops the procedure after 10 iterations.
boottest
does not calculate standard errors.
If your felm() model contains fixed effects, boottest() will internally convert all fixed
effects but the one specified via the fe
argument to dummy variables.
boottest
quietlyYou can suppress all warning and error messages by setting the following global
options:
options(rlib_warning_verbosity = "quiet")
options(rlib_message_verbosity = "quiet")
Not that this will turn off all warnings (messages) produced via rlang::warn()
and
rlang::inform()
, which might not be desirable if you use other software build on
rlang
, as e.g. the tidyverse
.
The fast wild cluster bootstrap algorithms are further implemented in the following software packages:
Stata:boottest
Julia:WildBootTests.jl
Python:wildboottest
Roodman et al., 2019, "Fast and wild: Bootstrap inference in STATA using boottest", The STATA Journal. (https://ideas.repec.org/p/qed/wpaper/1406.html)
MacKinnon, James G., Morten Ørregaard Nielsen, and Matthew D. Webb. Fast and reliable jackknife and bootstrap methods for cluster-robust inference. No. 1485. 2022.
Cameron, A. Colin, Jonah B. Gelbach, and Douglas L. Miller. "Bootstrap-based improvements for inference with clustered errors." The Review of Economics and Statistics 90.3 (2008): 414-427.
Cameron, A.Colin & Douglas L. Miller. "A practitioner's guide to cluster-robust inference" Journal of Human Resources (2015) doi:10.3368/jhr.50.2.317
Davidson & MacKinnon. "Wild Bootstrap Tests for IV regression" Journal of Economics and Business Statistics (2010) doi:10.1198/jbes.2009.07221
MacKinnon, James G., and Matthew D. Webb. "The wild bootstrap for few (treated) clusters. " The Econometrics Journal 21.2 (2018): 114-135.
MacKinnon, James G., and Matthew D. Webb. "Cluster-robust inference: A guide to empirical practice" Journal of Econometrics (2022) doi:10.1016/j.jeconom.2022.04.001
MacKinnon, James. "Wild cluster bootstrap confidence intervals." L'Actualite economique 91.1-2 (2015): 11-33.
Webb, Matthew D. Reworking wild bootstrap based inference for clustered errors. No. 1315. Queen's Economics Department Working Paper, 2013.
## Not run: requireNamespace("lfe") data(voters) felm_fit <- felm(proposition_vote ~ treatment + ideology1 + log_income | Q1_immigration, data = voters ) boot1 <- boottest(felm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) boot2 <- boottest(felm_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2") ) boot3 <- boottest(felm_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2"), fe = "Q1_immigration" ) boot4 <- boottest(felm_fit, B = 999, param = "treatment", clustid = c("group_id1", "group_id2"), fe = "Q1_immigration", sign_level = 0.2, r = 2 ) # test treatment + ideology1 = 2 boot5 <- boottest(felm_fit, B = 9999, clustid = c("group_id1", "group_id2"), param = c("treatment", "ideology1"), R = c(1, 1), r = 2 ) summary(boot1) print(boot1) plot(boot1) nobs(boot1) pval(boot1) confint(boot1) generics::tidy(boot1) # run different bootstrap types following MacKinnon, Nielsen & Webb (2022): # default: the fnw algorithm boot_fnw11 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "fnw11" ) # WCR 31 boot_WCR31 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "31" ) # WCU33 boot_WCR31 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "33", impose_null = FALSE ) ## End(Not run)
## Not run: requireNamespace("lfe") data(voters) felm_fit <- felm(proposition_vote ~ treatment + ideology1 + log_income | Q1_immigration, data = voters ) boot1 <- boottest(felm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) boot2 <- boottest(felm_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2") ) boot3 <- boottest(felm_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2"), fe = "Q1_immigration" ) boot4 <- boottest(felm_fit, B = 999, param = "treatment", clustid = c("group_id1", "group_id2"), fe = "Q1_immigration", sign_level = 0.2, r = 2 ) # test treatment + ideology1 = 2 boot5 <- boottest(felm_fit, B = 9999, clustid = c("group_id1", "group_id2"), param = c("treatment", "ideology1"), R = c(1, 1), r = 2 ) summary(boot1) print(boot1) plot(boot1) nobs(boot1) pval(boot1) confint(boot1) generics::tidy(boot1) # run different bootstrap types following MacKinnon, Nielsen & Webb (2022): # default: the fnw algorithm boot_fnw11 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "fnw11" ) # WCR 31 boot_WCR31 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "31" ) # WCU33 boot_WCR31 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "33", impose_null = FALSE ) ## End(Not run)
boottest.fixest
is a S3 method that allows for fast wild cluster
bootstrap inference for objects of class fixest by implementing
fast wild bootstrap algorithms as developed in Roodman et al., 2019
and MacKinnon, Nielsen & Webb (2022).
## S3 method for class 'fixest' boottest( object, param, B, clustid = NULL, bootcluster = "max", fe = NULL, sign_level = 0.05, conf_int = TRUE, R = NULL, r = 0, beta0 = NULL, type = "rademacher", impose_null = TRUE, bootstrap_type = "fnw11", p_val_type = "two-tailed", tol = 1e-06, maxiter = 10, sampling = "dqrng", nthreads = getBoottest_nthreads(), ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), engine = getBoottest_engine(), floattype = "Float64", maxmatsize = FALSE, bootstrapc = FALSE, getauxweights = FALSE, ... )
## S3 method for class 'fixest' boottest( object, param, B, clustid = NULL, bootcluster = "max", fe = NULL, sign_level = 0.05, conf_int = TRUE, R = NULL, r = 0, beta0 = NULL, type = "rademacher", impose_null = TRUE, bootstrap_type = "fnw11", p_val_type = "two-tailed", tol = 1e-06, maxiter = 10, sampling = "dqrng", nthreads = getBoottest_nthreads(), ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), engine = getBoottest_engine(), floattype = "Float64", maxmatsize = FALSE, bootstrapc = FALSE, getauxweights = FALSE, ... )
object |
An object of class fixest and estimated via |
param |
A character vector or rhs formula. The name of the regression coefficient(s) for which the hypothesis is to be tested |
B |
Integer. The number of bootstrap iterations. When the number of clusters is low, increasing B adds little additional runtime. |
clustid |
A character vector or rhs formula containing the names of the cluster variables. If NULL, a heteroskedasticity-robust (HC1) wild bootstrap is run. |
bootcluster |
A character vector or rhs formula of length 1. Specifies
the bootstrap clustering variable or variables. If more
than one variable is specified, then bootstrapping is clustered by the
intersections of
clustering implied by the listed variables. To mimic the behavior of
stata's boottest command,
the default is to cluster by the intersection of all the variables
specified via the |
fe |
A character vector or rhs formula of length one which contains the name of the fixed effect to be projected out in the bootstrap. Note: if regression weights are used, fe needs to be NULL. |
sign_level |
A numeric between 0 and 1 which sets the significance level of the inference procedure. E.g. sign_level = 0.05 returns 0.95% confidence intervals. By default, sign_level = 0.05. |
conf_int |
A logical vector. If TRUE, boottest computes confidence intervals by test inversion. If FALSE, only the p-value is returned. |
R |
Hypothesis Vector giving linear combinations of coefficients.
Must be either NULL or a vector of the same length as |
r |
A numeric. Shifts the null hypothesis H0: param = r vs H1: param != r |
beta0 |
Deprecated function argument. Replaced by function argument 'r'. |
type |
character or function. The character string specifies the type
of boostrap to use: One of "rademacher", "mammen", "norm"
and "webb". Alternatively, type can be a function(n) for drawing
wild bootstrap factors. "rademacher" by default.
For the Rademacher distribution, if the number of replications B
exceeds
the number of possible draw ombinations, 2^(#number of clusters),
then |
impose_null |
Logical. Controls if the null hypothesis is imposed on
the bootstrap dgp or not. Null imposed |
bootstrap_type |
Determines which wild cluster bootstrap type should be run. Options are "fnw11","11", "13", "31" and "33" for the wild cluster bootstrap and "11" and "31" for the heteroskedastic bootstrap. For more information, see the details section. "fnw11" is the default for the cluster bootstrap, which runs a "11" type wild cluster bootstrap via the algorithm outlined in "fast and wild" (Roodman et al (2019)). "11" is the default for the heteroskedastic bootstrap. |
p_val_type |
Character vector of length 1. Type of p-value. By default "two-tailed". Other options include "equal-tailed", ">" and "<". |
tol |
Numeric vector of length 1. The desired accuracy (convergence tolerance) used in the root finding procedure to find the confidence interval. 1e-6 by default. |
maxiter |
Integer. Maximum number of iterations used in the root finding procedure to find the confidence interval. 10 by default. |
sampling |
'dqrng' or 'standard'. If 'dqrng', the 'dqrng' package is
used for random number generation (when available). If 'standard',
functions from the 'stats' package are used when available.
This argument is mostly a convenience to control random number generation in
a wrapper package around |
nthreads |
The number of threads. Can be: a) an integer lower than, or equal to, the maximum number of threads; b) 0: meaning all available threads will be used; c) a number strictly between 0 and 1 which represents the fraction of all threads to use. The default is to use 1 core. |
ssc |
An object of class |
engine |
Character scalar. Either "R", "R-lean" or "WildBootTests.jl".
Controls if |
floattype |
Float64 by default. Other option: Float32. Should floating point numbers in Julia be represented as 32 or 64 bit? Only relevant when 'engine = "WildBootTests.jl"' |
maxmatsize |
NULL by default = no limit. Else numeric scalar to set the maximum size of auxilliary weight matrix (v), in gigabytes. Only relevant when 'engine = "WildBootTests.jl"' |
bootstrapc |
Logical scalar, FALSE by default. TRUE to request bootstrap-c instead of bootstrap-t. Only relevant when 'engine = "WildBootTests.jl"' |
getauxweights |
Logical. Whether to save auxilliary weight matrix (v) |
... |
Further arguments passed to or from other methods. |
An object of class boottest
p_val |
The bootstrap p-value. |
conf_int |
The bootstrap confidence interval. |
param |
The tested parameter. |
N |
Sample size. Might differ from the regression sample size if the cluster variables contain NA values. |
boot_iter |
Number of Bootstrap Iterations. |
clustid |
Names of the cluster Variables. |
N_G |
Dimension of the cluster variables as used in boottest. |
sign_level |
Significance level used in boottest. |
type |
Distribution of the bootstrap weights. |
impose_null |
Whether the null was imposed on the bootstrap dgp or not. |
R |
The vector "R" in the null hypothesis of interest Rbeta = r. |
r |
The scalar "r" in the null hypothesis of interest Rbeta = r. |
point_estimate |
R'beta. A scalar: the constraints vector times the regression coefficients. |
grid_vals |
All t-statistics calculated while calculating the confidence interval. |
p_grid_vals |
All p-values calculated while calculating the confidence interval. |
t_stat |
The 'original' regression test statistics. |
t_boot |
All bootstrap t-statistics. |
regression |
The regression object used in boottest. |
call |
Function call of boottest. |
engine |
The employed bootstrap algorithm. |
nthreads |
The number of threads employed. |
To guarantee reproducibility, you need to set a global random seed via
set.seed()
when using
the lean algorithm (via engine = "R-lean"
) including the
heteroskedastic wild bootstrap
the wild cluster bootstrap via engine = "R"
with Mammen weights or
engine = "WildBootTests.jl"
dqrng::dqset.seed()
when using engine = "R"
for Rademacher, Webb
or Normal weights
boottest
computes confidence intervals by inverting p-values.
In practice, the following procedure is used:
Based on an initial guess for starting values, calculate p-values for 26 equal spaced points between the starting values.
Out of the 26 calculated p-values, find the two pairs of values x for which the corresponding p-values px cross the significance sign_level sign_level.
Feed the two pairs of x into an numerical root finding procedure
and solve for the root. boottest currently relies on
stats::uniroot
and sets an absolute tolerance of 1e-06 and
stops the procedure after 10 iterations.
boottest
does not calculate standard errors.
If your feols() model contains fixed effects, boottest() will internally convert all fixed
effects but the one specified via the fe
argument to dummy variables.
boottest
quietlyYou can suppress all warning and error messages by setting the following global
options:
options(rlib_warning_verbosity = "quiet")
options(rlib_message_verbosity = "quiet")
Note that this will turn off all warnings (messages) produced via rlang::warn()
and
rlang::inform()
, which might not be desirable if you use other software build on
rlang
, as e.g. the tidyverse
.
The fast wild cluster bootstrap algorithms are further implemented in the following software packages:
Stata:boottest
Julia:WildBootTests.jl
Python:wildboottest
Roodman et al., 2019, "Fast and wild: Bootstrap inference in STATA using boottest", The STATA Journal. (https://ideas.repec.org/p/qed/wpaper/1406.html)
MacKinnon, James G., Morten Ørregaard Nielsen, and Matthew D. Webb. Fast and reliable jackknife and bootstrap methods for cluster-robust inference. No. 1485. 2022.
Cameron, A. Colin, Jonah B. Gelbach, and Douglas L. Miller. "Bootstrap-based improvements for inference with clustered errors." The Review of Economics and Statistics 90.3 (2008): 414-427.
Cameron, A.Colin & Douglas L. Miller. "A practitioner's guide to cluster-robust inference" Journal of Human Resources (2015) doi:10.3368/jhr.50.2.317
Davidson & MacKinnon. "Wild Bootstrap Tests for IV regression" Journal of Economics and Business Statistics (2010) doi:10.1198/jbes.2009.07221
MacKinnon, James G., and Matthew D. Webb. "The wild bootstrap for few (treated) clusters. " The Econometrics Journal 21.2 (2018): 114-135.
MacKinnon, James G., and Matthew D. Webb. "Cluster-robust inference: A guide to empirical practice" Journal of Econometrics (2022) doi:10.1016/j.jeconom.2022.04.001
MacKinnon, James. "Wild cluster bootstrap confidence intervals." L'Actualite economique 91.1-2 (2015): 11-33.
Webb, Matthew D. Reworking wild bootstrap based inference for clustered errors. No. 1315. Queen's Economics Department Working Paper, 2013.
## Not run: requireNamespace("fixest") requireNamespace("fwildclusterboot") data(voters) feols_fit <- feols(proposition_vote ~ treatment + ideology1 + log_income, fixef = "Q1_immigration", data = voters ) boot1 <- boottest(feols_fit, B = 9999, param = "treatment", clustid = "group_id1" ) boot2 <- boottest(feols_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2") ) boot3 <- boottest(feols_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2"), fe = "Q1_immigration" ) boot4 <- boottest(feols_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2"), fe = "Q1_immigration", sign_level = 0.2, r = 2 ) # test treatment + ideology1 = 2 boot5 <- boottest(feols_fit, B = 9999, clustid = c("group_id1", "group_id2"), param = c("treatment", "ideology1"), R = c(1, 1), r = 2 ) summary(boot1) print(boot1) plot(boot1) nobs(boot1) pval(boot1) confint(boot1) generics::tidy(boot1) # run different bootstrap types following MacKinnon, Nielsen & Webb (2022): # default: the fnw algorithm boot_fnw11 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "fnw11" ) # WCR 31 boot_WCR31 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "31" ) # WCU33 boot_WCR31 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "33", impose_null = FALSE ) ## End(Not run)
## Not run: requireNamespace("fixest") requireNamespace("fwildclusterboot") data(voters) feols_fit <- feols(proposition_vote ~ treatment + ideology1 + log_income, fixef = "Q1_immigration", data = voters ) boot1 <- boottest(feols_fit, B = 9999, param = "treatment", clustid = "group_id1" ) boot2 <- boottest(feols_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2") ) boot3 <- boottest(feols_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2"), fe = "Q1_immigration" ) boot4 <- boottest(feols_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2"), fe = "Q1_immigration", sign_level = 0.2, r = 2 ) # test treatment + ideology1 = 2 boot5 <- boottest(feols_fit, B = 9999, clustid = c("group_id1", "group_id2"), param = c("treatment", "ideology1"), R = c(1, 1), r = 2 ) summary(boot1) print(boot1) plot(boot1) nobs(boot1) pval(boot1) confint(boot1) generics::tidy(boot1) # run different bootstrap types following MacKinnon, Nielsen & Webb (2022): # default: the fnw algorithm boot_fnw11 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "fnw11" ) # WCR 31 boot_WCR31 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "31" ) # WCU33 boot_WCR31 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "33", impose_null = FALSE ) ## End(Not run)
boottest.ivreg
is a S3 method that allows for fast wild cluster
bootstrap inference for objects of class ivreg by implementing
the fast wild bootstrap algorithm developed in Roodman et al., 2019
for instrumental variable models (WRE, Davidson & McKinnon, 2010)
## S3 method for class 'ivreg' boottest( object, clustid, param, B, bootcluster = "max", conf_int = TRUE, R = NULL, r = 0, sign_level = 0.05, type = "rademacher", impose_null = TRUE, p_val_type = "two-tailed", tol = 1e-06, floattype = "Float64", getauxweights = FALSE, maxmatsize = NULL, bootstrapc = FALSE, liml = FALSE, fuller = NULL, kappa = NULL, arubin = FALSE, ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), ... )
## S3 method for class 'ivreg' boottest( object, clustid, param, B, bootcluster = "max", conf_int = TRUE, R = NULL, r = 0, sign_level = 0.05, type = "rademacher", impose_null = TRUE, p_val_type = "two-tailed", tol = 1e-06, floattype = "Float64", getauxweights = FALSE, maxmatsize = NULL, bootstrapc = FALSE, liml = FALSE, fuller = NULL, kappa = NULL, arubin = FALSE, ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), ... )
object |
An object of class lm |
clustid |
A character vector or rhs formula containing the names of the cluster variables |
param |
A character vector or rhs formula of length one. The name of the regression coefficient for which the hypothesis is to be tested |
B |
Integer. The number of bootstrap iterations. When the number of clusters is low, increasing B adds little additional runtime |
bootcluster |
A character vector or rhs formula of length 1. Specifies
the bootstrap clustering variable or variables. If more
than one variable is specified, then bootstrapping is clustered
by the intersections of
clustering implied by the listed variables. To mimic the behavior
of stata's boottest command,
the default is to cluster by the intersection of all the variables
specified via the |
conf_int |
A logical vector. If TRUE, boottest computes confidence intervals by test inversion. If FALSE, only the p-value is returned. |
R |
Hypothesis Vector giving linear combinations of coefficients.
Must be either NULL or a vector of the same length as |
r |
A numeric. Shifts the null hypothesis H0: param = r vs H1: param != r |
sign_level |
A numeric between 0 and 1 which sets the significance level of the inference procedure. E.g. sign_level = 0.05 returns 0.95% confidence intervals. By default, sign_level = 0.05. |
type |
character or function. The character string specifies the type
of boostrap to use: One of "rademacher", "mammen", "norm", "gamma"
and "webb". Alternatively, type can be a function(n) for drawing
wild bootstrap factors. "rademacher" by default.
For the Rademacher and Mammen distribution, if the number of
replications B exceeds
the number of possible draw ombinations, 2^(#number of clusters),
then |
impose_null |
Logical. Controls if the null hypothesis is imposed on
the bootstrap dgp or not. Null imposed |
p_val_type |
Character vector of length 1. Type of p-value. By default "two-tailed". Other options include "equal-tailed", ">" and "<". |
tol |
Numeric vector of length 1. The desired accuracy (convergence tolerance) used in the root finding procedure to find the confidence interval. Relative tolerance of 1e-6 by default. |
floattype |
Float64 by default. Other option: Float32. Should floating point numbers in Julia be represented as 32 or 64 bit? |
getauxweights |
Logical. FALSE by default. Whether to save auxilliary weight matrix (v) |
maxmatsize |
NULL by default = no limit. Else numeric scalar to set the maximum size of auxilliary weight matrix (v), in gigabytes |
bootstrapc |
Logical scalar, FALSE by default. TRUE to request bootstrap-c instead of bootstrap-t |
liml |
Logical scalar. False by default. TRUE for liml or fuller liml |
fuller |
NULL by default. Numeric scalar. fuller liml factor |
kappa |
Null by default. fixed <U+03BA> for k-class estimation |
arubin |
False by default. Logical scalar. TRUE for Anderson-Rubin Test. |
ssc |
An object of class |
... |
Further arguments passed to or from other methods. |
An object of class boottest
p_val |
The bootstrap p-value. |
conf_int |
The bootstrap confidence interval. |
param |
The tested parameter. |
N |
Sample size. Might differ from the regression sample size if the cluster variables contain NA values. |
boot_iter |
Number of Bootstrap Iterations. |
clustid |
Names of the cluster Variables. |
N_G |
Dimension of the cluster variables as used in boottest. |
sign_level |
Significance level used in boottest. |
type |
Distribution of the bootstrap weights. |
impose_null |
Whether the null was imposed on the bootstrap dgp or not. |
R |
The vector "R" in the null hypothesis of interest Rbeta = r. |
r |
The scalar "r" in the null hypothesis of interest Rbeta = r. |
point_estimate |
R'beta. A scalar: the constraints vector times the regression coefficients. |
grid_vals |
All t-statistics calculated while calculating the confidence interval. |
p_grid_vals |
All p-values calculated while calculating the confidence interval. |
t_stat |
The 'original' regression test statistics. |
t_boot |
All bootstrap t-statistics. |
regression |
The regression object used in boottest. |
call |
Function call of boottest. |
engine |
The employed bootstrap algorithm. |
nthreads |
The number of threads employed. |
To guarantee reproducibility, you need to
set a global random seed via set.seed()
boottest
quietlyYou can suppress all warning and error messages by setting the following global
options:
options(rlib_warning_verbosity = "quiet")
options(rlib_message_verbosity = "quiet")
Not that this will turn off all warnings (messages) produced via rlang::warn()
and
rlang::inform()
, which might not be desirable if you use other software build on
rlang
, as e.g. the tidyverse
.
Roodman et al., 2019, "Fast and wild: Bootstrap inference in STATA using boottest", The STATA Journal. (https://ideas.repec.org/p/qed/wpaper/1406.html)
Cameron, A. Colin, Jonah B. Gelbach, and Douglas L. Miller. "Bootstrap-based improvements for inference with clustered errors." The Review of Economics and Statistics 90.3 (2008): 414-427.
Cameron, A.Colin & Douglas L. Miller. "A practitioner's guide to cluster-robust inference" Journal of Human Resources (2015) doi:10.3368/jhr.50.2.317
Davidson & MacKinnon. "Wild Bootstrap Tests for IV regression" Journal of Economics and Business Statistics (2010) doi:10.1198/jbes.2009.07221
MacKinnon, James G., and Matthew D. Webb. "The wild bootstrap for few (treated) clusters." The Econometrics Journal 21.2 (2018): 114-135.
MacKinnon, James G., and Matthew D. Webb. "Cluster-robust inference: A guide to empirical practice" Journal of Econometrics (2022) doi:10.1016/j.jeconom.2022.04.001
MacKinnon, James. "Wild cluster bootstrap confidence intervals." L'Actualite economique 91.1-2 (2015): 11-33.
Webb, Matthew D. Reworking wild bootstrap based inference for clustered errors. No. 1315. Queen's Economics Department Working Paper, 2013.
## Not run: requireNamespace("ivreg") requireNamespace("fwildclusterboot") # drop all NA values from SchoolingReturns SchoolingReturns <- na.omit(SchoolingReturns) ivreg_fit <- ivreg(log(wage) ~ education + age + ethnicity + smsa + south + parents14 | nearcollege + age + ethnicity + smsa + south + parents14, data = SchoolingReturns ) boot_ivreg <- boottest( object = ivreg_fit, B = 999, param = "education", clustid = "kww", type = "mammen", impose_null = TRUE ) summary(boot_ivreg) print(boot_ivreg) plot(boot_ivreg) nobs(boot_ivreg) pval(boot_ivreg) confint(boot_ivreg) generics::tidy(boot_ivreg) ## End(Not run)
## Not run: requireNamespace("ivreg") requireNamespace("fwildclusterboot") # drop all NA values from SchoolingReturns SchoolingReturns <- na.omit(SchoolingReturns) ivreg_fit <- ivreg(log(wage) ~ education + age + ethnicity + smsa + south + parents14 | nearcollege + age + ethnicity + smsa + south + parents14, data = SchoolingReturns ) boot_ivreg <- boottest( object = ivreg_fit, B = 999, param = "education", clustid = "kww", type = "mammen", impose_null = TRUE ) summary(boot_ivreg) print(boot_ivreg) plot(boot_ivreg) nobs(boot_ivreg) pval(boot_ivreg) confint(boot_ivreg) generics::tidy(boot_ivreg) ## End(Not run)
boottest.lm
is a S3 method that allows for fast wild cluster
bootstrap inference for objects of class lm by implementing
fast wild bootstrap algorithms as developed in Roodman et al., 2019
and MacKinnon, Nielsen & Webb (2022).
## S3 method for class 'lm' boottest( object, param, B, clustid = NULL, bootcluster = "max", conf_int = TRUE, R = NULL, r = 0, beta0 = NULL, sign_level = 0.05, type = "rademacher", impose_null = TRUE, bootstrap_type = "fnw11", p_val_type = "two-tailed", tol = 1e-06, maxiter = 10, sampling = "dqrng", nthreads = getBoottest_nthreads(), ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), engine = getBoottest_engine(), floattype = "Float64", maxmatsize = FALSE, bootstrapc = FALSE, getauxweights = FALSE, ... )
## S3 method for class 'lm' boottest( object, param, B, clustid = NULL, bootcluster = "max", conf_int = TRUE, R = NULL, r = 0, beta0 = NULL, sign_level = 0.05, type = "rademacher", impose_null = TRUE, bootstrap_type = "fnw11", p_val_type = "two-tailed", tol = 1e-06, maxiter = 10, sampling = "dqrng", nthreads = getBoottest_nthreads(), ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), engine = getBoottest_engine(), floattype = "Float64", maxmatsize = FALSE, bootstrapc = FALSE, getauxweights = FALSE, ... )
object |
An object of class lm |
param |
A character vector or rhs formula. The name of the regression coefficient(s) for which the hypothesis is to be tested |
B |
Integer. The number of bootstrap iterations. When the number of clusters is low, increasing B adds little additional runtime. |
clustid |
A character vector or rhs formula containing the names of the cluster variables. If NULL, a heteroskedasticity-robust (HC1) wild bootstrap is run. |
bootcluster |
A character vector or rhs formula of length 1. Specifies
the bootstrap clustering variable or variables. If more
than one variable is specified, then bootstrapping is clustered by
the intersections of
clustering implied by the listed variables. To mimic the behavior
of stata's boottest command,
the default is to cluster by the intersection of all the variables
specified via the |
conf_int |
A logical vector. If TRUE, boottest computes confidence intervals by test inversion. If FALSE, only the p-value is returned. |
R |
Hypothesis Vector giving linear combinations of coefficients.
Must be either NULL or a vector of the same length as |
r |
A numeric. Shifts the null hypothesis H0: param = r vs H1: param != r |
beta0 |
Deprecated function argument. Replaced by function argument 'r'. |
sign_level |
A numeric between 0 and 1 which sets the significance level of the inference procedure. E.g. sign_level = 0.05 returns 0.95% confidence intervals. By default, sign_level = 0.05. |
type |
character or function. The character string specifies the type
of boostrap to use: One of "rademacher", "mammen", "norm"
and "webb".
Alternatively, type can be a function(n) for drawing
wild bootstrap factors. "rademacher" by default.
For the Rademacher distribution, if the number of replications B
exceeds the number of possible draw ombinations, 2^(#number
of clusters), then |
impose_null |
Logical. Controls if the null hypothesis is imposed on
the bootstrap dgp or not. Null imposed |
bootstrap_type |
Determines which wild cluster bootstrap type should be run. Options are "fnw11","11", "13", "31" and "33" for the wild cluster bootstrap and "11" and "31" for the heteroskedastic bootstrap. For more information, see the details section. "fnw11" is the default for the cluster bootstrap, which runs a "11" type wild cluster bootstrap via the algorithm outlined in "fast and wild" (Roodman et al (2019)). "11" is the default for the heteroskedastic bootstrap. |
p_val_type |
Character vector of length 1. Type of p-value. By default "two-tailed". Other options include "equal-tailed", ">" and "<". |
tol |
Numeric vector of length 1. The desired accuracy (convergence tolerance) used in the root finding procedure to find the confidence interval. 1e-6 by default. |
maxiter |
Integer. Maximum number of iterations used in the root finding procedure to find the confidence interval. 10 by default. |
sampling |
'dqrng' or 'standard'. If 'dqrng', the 'dqrng' package is
used for random number generation (when available). If 'standard',
functions from the 'stats' package are used when available.
This argument is mostly a convenience to control random number generation in
a wrapper package around |
nthreads |
The number of threads. Can be: a) an integer lower than, or equal to, the maximum number of threads; b) 0: meaning all available threads will be used; c) a number strictly between 0 and 1 which represents the fraction of all threads to use. The default is to use 1 core. |
ssc |
An object of class |
engine |
Character scalar. Either "R", "R-lean" or "WildBootTests.jl".
Controls if |
floattype |
Float64 by default. Other option: Float32. Should floating point numbers in Julia be represented as 32 or 64 bit? Only relevant when 'engine= "WildBootTests.jl"' |
maxmatsize |
NULL by default = no limit. Else numeric scalar to set the maximum size of auxilliary weight matrix (v), in gigabytes. Only relevant when 'engine= "WildBootTests.jl"' |
bootstrapc |
Logical scalar, FALSE by default. TRUE to request bootstrap-c instead of bootstrap-t. Only relevant when 'engine = "WildBootTests.jl"' |
getauxweights |
Logical. Whether to save auxilliary weight matrix (v) |
... |
Further arguments passed to or from other methods. |
An object of class boottest
p_val |
The bootstrap p-value. |
conf_int |
The bootstrap confidence interval. |
param |
The tested parameter. |
N |
Sample size. Might differ from the regression sample size if the cluster variables contain NA values. |
boot_iter |
Number of Bootstrap Iterations. |
clustid |
Names of the cluster Variables. |
N_G |
Dimension of the cluster variables as used in boottest. |
sign_level |
Significance level used in boottest. |
type |
Distribution of the bootstrap weights. |
impose_null |
Whether the null was imposed on the bootstrap dgp or not. |
R |
The vector "R" in the null hypothesis of interest Rbeta = r. |
r |
The scalar "r" in the null hypothesis of interest Rbeta = r. |
point_estimate |
R'beta. A scalar: the constraints vector times the regression coefficients. |
grid_vals |
All t-statistics calculated while calculating the confidence interval. |
p_grid_vals |
All p-values calculated while calculating the confidence interval. |
t_stat |
The 'original' regression test statistics. |
t_boot |
All bootstrap t-statistics. |
regression |
The regression object used in boottest. |
call |
Function call of boottest. |
engine |
The employed bootstrap algorithm. |
nthreads |
The number of threads employed. |
To guarantee reproducibility, you need to set a global random seed via
set.seed()
when using
the lean algorithm (via engine = "R-lean"
) including the
heteroskedastic wild bootstrap
the wild cluster bootstrap via engine = "R"
with Mammen weights or
engine = "WildBootTests.jl"
dqrng::dqset.seed()
when using engine = "R"
for Rademacher,
Webb or Normal weights
Via the engine
function argument, it is possible to specify different
variants of the wild cluster bootstrap, and if the algorithm should
be run via R or WildBootTests.jl
.
boottest
computes confidence intervals by inverting p-values.
In practice, the following procedure is used:
Based on an initial guess for starting values, calculate p-values for 26 equal spaced points between the starting values.
Out of the 26 calculated p-values, find the two pairs of values x for which the corresponding p-values px cross the significance level sign_level.
Feed the two pairs of x into an numerical root finding procedure and
solve for the root. boottest currently relies on
stats::uniroot
and sets an absolute tolerance of 1e-06 and
stops the procedure after 10 iterations.
boottest
does not calculate standard errors.
boottest
quietlyYou can suppress all warning and error messages by setting the following global
options:
options(rlib_warning_verbosity = "quiet")
options(rlib_message_verbosity = "quiet")
Not that this will turn off all warnings (messages) produced via rlang::warn()
and
rlang::inform()
, which might not be desirable if you use other software build on
rlang
, as e.g. the tidyverse
.
The fast wild cluster bootstrap algorithms are further implemented in the following software packages:
Stata:boottest
Julia:WildBootTests.jl
Python:wildboottest
Roodman et al., 2019, "Fast and wild: Bootstrap inference in STATA using boottest", The STATA Journal. (https://ideas.repec.org/p/qed/wpaper/1406.html)
MacKinnon, James G., Morten Ørregaard Nielsen, and Matthew D. Webb. Fast and reliable jackknife and bootstrap methods for cluster-robust inference. No. 1485. 2022.
Cameron, A. Colin, Jonah B. Gelbach, and Douglas L. Miller. "Bootstrap-based improvements for inference with clustered errors." The Review of Economics and Statistics 90.3 (2008): 414-427.
Cameron, A.Colin & Douglas L. Miller. "A practitioner's guide to cluster-robust inference" Journal of Human Resources (2015) doi:10.3368/jhr.50.2.317
Davidson & MacKinnon. "Wild Bootstrap Tests for IV regression" Journal of Economics and Business Statistics (2010) doi:10.1198/jbes.2009.07221
MacKinnon, James G., and Matthew D. Webb. "The wild bootstrap for few (treated) clusters." The Econometrics Journal 21.2 (2018): 114-135.
MacKinnon, James G., and Matthew D. Webb. "Cluster-robust inference: A guide to empirical practice" Journal of Econometrics (2022) doi:10.1016/j.jeconom.2022.04.001
MacKinnon, James. "Wild cluster bootstrap confidence intervals." L'Actualite economique 91.1-2 (2015): 11-33.
Webb, Matthew D. Reworking wild bootstrap based inference for clustered errors. No. 1315. Queen's Economics Department Working Paper, 2013.
## Not run: requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm(proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot1 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) boot2 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2") ) boot3 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2"), sign_level = 0.2, r = 2 ) # test treatment + ideology1 = 2 boot4 <- boottest(lm_fit, B = 9999, clustid = c("group_id1", "group_id2"), param = c("treatment", "ideology1"), R = c(1, 1), r = 2 ) summary(boot1) print(boot1) plot(boot1) nobs(boot1) pval(boot1) confint(boot1) generics::tidy(boot1) # run different bootstrap types following MacKinnon, Nielsen & Webb (2022): # default: the fnw algorithm boot_fnw11 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "fnw11" ) # WCR 31 boot_WCR31 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "31" ) # WCU33 boot_WCR31 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "33", impose_null = FALSE ) ## End(Not run)
## Not run: requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm(proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot1 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) boot2 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2") ) boot3 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = c("group_id1", "group_id2"), sign_level = 0.2, r = 2 ) # test treatment + ideology1 = 2 boot4 <- boottest(lm_fit, B = 9999, clustid = c("group_id1", "group_id2"), param = c("treatment", "ideology1"), R = c(1, 1), r = 2 ) summary(boot1) print(boot1) plot(boot1) nobs(boot1) pval(boot1) confint(boot1) generics::tidy(boot1) # run different bootstrap types following MacKinnon, Nielsen & Webb (2022): # default: the fnw algorithm boot_fnw11 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "fnw11" ) # WCR 31 boot_WCR31 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "31" ) # WCU33 boot_WCR31 <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1", bootstrap_type = "33", impose_null = FALSE ) ## End(Not run)
S3 method to obtain wild cluster bootstrapped confidence intervals
## S3 method for class 'boottest' confint(object, ...)
## S3 method for class 'boottest' confint(object, ...)
object |
object of type boottest |
... |
Further arguments passed to or from other methods. |
A vector containing the boundaries of the wild cluster bootstrapped confidence interval
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) teststat(boot)
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) teststat(boot)
Based on Mauro Lepore's great suggestion https://github.com/ropensci/software-review/issues/546#issuecomment-1416728843
find_proglang(lang)
find_proglang(lang)
lang |
which language to check. Either 'julia' or 'python' |
logical. TRUE if lang is found on path, FALSE if not
## Not run: find_proglang(lang = "julia") ## End(Not run)
## Not run: find_proglang(lang = "julia") ## End(Not run)
S3 method to glance at objects of class boottest
## S3 method for class 'boottest' glance(x, ...)
## S3 method for class 'boottest' glance(x, ...)
x |
object of type boottest |
... |
Further arguments passed to or from other methods. |
A single row summary "glance" of an object of type boottest - lists characteristics of the input regression model
## Not run: requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) generics::glance(boot) ## End(Not run)
## Not run: requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) generics::glance(boot) ## End(Not run)
S3 method to glance at objects of class boottest
## S3 method for class 'mboottest' glance(x, ...)
## S3 method for class 'mboottest' glance(x, ...)
x |
object of type mboottest |
... |
Further arguments passed to or from other methods. |
A single row summary "glance" of an object of type boottest - lists characteristics of the input regression model
## Not run: requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) mboot <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) generics::glance(mboot) ## End(Not run)
## Not run: requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) mboot <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) generics::glance(mboot) ## End(Not run)
mboottest
is a S3 method that allows for arbitrary linear
hypothesis testing
for objects of class lm, fixest, felm
mboottest(object, ...)
mboottest(object, ...)
object |
An object of type lm, fixest or felm |
... |
other arguments |
An object of class mboottest
.
To guarantee reproducibility, you can either use boottest()'s
seed
function argument, or
set a global random seed via
set.seed()
when using
the lean algorithm (via engine = "R-lean"
),
the heteroskedastic wild bootstrap
the wild cluster bootstrap via engine = "R"
with Mammen weights or
engine = "WildBootTests.jl"
dqrng::dqset.seed()
when using engine = "R"
for Rademacher,
Webb or Normal weights
Roodman et al., 2019, "Fast and wild: Bootstrap inference in STATA using boottest", The STATA Journal. (https://ideas.repec.org/p/qed/wpaper/1406.html)
Cameron, A. Colin, Jonah B. Gelbach, and Douglas L. Miller. "Bootstrap-based improvements for inference with clustered errors." The Review of Economics and Statistics 90.3 (2008): 414-427.
Cameron, A.Colin & Douglas L. Miller. "A practitioner's guide to cluster-robust inference" Journal of Human Resources (2015) doi:10.3368/jhr.50.2.317
Davidson & MacKinnon. "Wild Bootstrap Tests for IV regression" Journal of Economics and Business Statistics (2010) doi:10.1198/jbes.2009.07221
MacKinnon, James G., and Matthew D. Webb. "The wild bootstrap for few (treated) clusters." The Econometrics Journal 21.2 (2018): 114-135.
MacKinnon, James G., and Matthew D. Webb. "Cluster-robust inference: A guide to empirical practice" Journal of Econometrics (2022) doi:10.1016/j.jeconom.2022.04.001
MacKinnon, James. "Wild cluster bootstrap confidence intervals." L'Actualite economique 91.1-2 (2015): 11-33.
Webb, Matthew D. "Reworking wild bootstrap based inference for clustered errors" . No. 1315. Queen's Economics Department Working Paper, 2013.
mboottest.lm mboottest.felm mboottest.fixest
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(wboottest) print(wboottest) nobs(wboottest) pval(wboottest) generics::tidy(wboottest) ## End(Not run)
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(wboottest) print(wboottest) nobs(wboottest) pval(wboottest) generics::tidy(wboottest) ## End(Not run)
mboottest.felm
is a S3 method that allows for fast wild cluster
bootstrap inference of multivariate hypotheses for objects of class felm by
implementing the fast wild bootstrap algorithm developed in
Roodman et al., 2019.
## S3 method for class 'felm' mboottest( object, clustid, B, R, r = rep(0, nrow(R)), bootcluster = "max", fe = NULL, type = "rademacher", impose_null = TRUE, p_val_type = "two-tailed", tol = 1e-06, floattype = "Float64", getauxweights = FALSE, maxmatsize = NULL, bootstrapc = FALSE, ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), ... )
## S3 method for class 'felm' mboottest( object, clustid, B, R, r = rep(0, nrow(R)), bootcluster = "max", fe = NULL, type = "rademacher", impose_null = TRUE, p_val_type = "two-tailed", tol = 1e-06, floattype = "Float64", getauxweights = FALSE, maxmatsize = NULL, bootstrapc = FALSE, ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), ... )
object |
An object of class felm |
clustid |
A character vector or rhs formula containing the names of the cluster variables |
B |
Integer. The number of bootstrap iterations. When the number of clusters is low, increasing B adds little additional runtime. |
R |
Hypothesis Vector or Matrix giving linear combinations of coefficients. Must be either a vector of length k or a matrix of dimension q x k, where q is the number of joint hypotheses and k the number of estimated coefficients. |
r |
A vector of length q, where q is the number of tested hypotheses. Shifts the null hypothesis H0: param = r vs H1: param != r. If not provided, a vector of zeros of length q. |
bootcluster |
A character vector or rhs formula of length 1. Specifies
the bootstrap clustering variable or variables. If more
than one variable is specified, then bootstrapping is clustered by
the intersections of
clustering implied by the listed variables. To mimic the behavior of
stata's boottest command,
the default is to cluster by the intersection of all the variables
specified via the |
fe |
A character vector or rhs formula of length one which contains the name of the fixed effect to be projected out in the bootstrap. Note: if regression weights are used, fe needs to be NULL. |
type |
character or function. The character string specifies the type
of boostrap to use: One of "rademacher", "mammen", "norm", "gamma"
and "webb". Alternatively, type can be a function(n) for drawing
wild bootstrap factors. "rademacher" by default.
For the Rademacher and Mammen distribution, if the number of
replications B exceeds
the number of possible draw ombinations, 2^(#number of clusters),
then |
impose_null |
Logical. Controls if the null hypothesis is imposed on
the bootstrap dgp or not. Null imposed |
p_val_type |
Character vector of length 1. Type of p-value. By default "two-tailed". Other options include "equal-tailed", ">" and "<". |
tol |
Numeric vector of length 1. The desired accuracy (convergence tolerance) used in the root finding procedure to find the confidence interval. Relative tolerance of 1e-6 by default. |
floattype |
Float64 by default. Other option: Float32. Should floating point numbers in Julia be represented as 32 or 64 bit? |
getauxweights |
Logical. FALSE by default. Whether to save auxilliary weight matrix (v) |
maxmatsize |
NULL by default = no limit. Else numeric scalar to set the maximum size of auxilliary weight matrix (v), in gigabytes |
bootstrapc |
Logical scalar, FALSE by default. TRUE to request bootstrap-c instead of bootstrap-t |
ssc |
An object of class |
... |
Further arguments passed to or from other methods. |
An object of class mboottest
p_val |
The bootstrap p-value. |
N |
Sample size. Might differ from the regression sample size if the cluster variables contain NA values. |
boot_iter |
Number of Bootstrap Iterations. |
clustid |
Names of the cluster Variables. |
N_G |
Dimension of the cluster variables as used in boottest. |
sign_level |
Significance level used in boottest. |
type |
Distribution of the bootstrap weights. |
impose_null |
Whether the null was imposed on the bootstrap dgp or not. |
R |
The vector "R" in the null hypothesis of interest Rbeta = r. |
r |
The scalar "r" in the null hypothesis of interest Rbeta = r. |
point_estimate |
R'beta. A scalar: the constraints vector times the regression coefficients. |
teststat_stat |
The 'original' regression test statistics. |
teststat_boot |
All bootstrap t-statistics. |
regression |
The regression object used in boottest. |
call |
Function call of boottest. |
To guarantee reproducibility, you need to
set a global random seed via set.seed()
when using
If your felm() model contains fixed effects, boottest() will internally convert
all fixed effects but the one specified via the fe
argument to dummy variables.
boottest
quietlyYou can suppress all warning and error messages by setting the following global
options:
options(rlib_warning_verbosity = "quiet")
options(rlib_message_verbosity = "quiet")
Not that this will turn off all warnings (messages) produced via rlang::warn()
and
rlang::inform()
, which might not be desirable if you use other software build on
rlang
, as e.g. the tidyverse
.
Roodman et al., 2019, "Fast and wild: Bootstrap inference in STATA using boottest", The STATA Journal. (https://ideas.repec.org/p/qed/wpaper/1406.html)
Cameron, A. Colin, Jonah B. Gelbach, and Douglas L. Miller. "Bootstrap-based improvements for inference with clustered errors." The Review of Economics and Statistics 90.3 (2008): 414-427.
Cameron, A.Colin & Douglas L. Miller. "A practitioner's guide to cluster-robust inference" Journal of Human Resources (2015) doi:10.3368/jhr.50.2.317
Davidson & MacKinnon. "Wild Bootstrap Tests for IV regression" Journal of Economics and Business Statistics (2010) doi:10.1198/jbes.2009.07221
MacKinnon, James G., and Matthew D. Webb. "The wild bootstrap for few (treated) clusters." The Econometrics Journal 21.2 (2018): 114-135.
MacKinnon, James G., and Matthew D. Webb. "Cluster-robust inference: A guide to empirical practice" Journal of Econometrics (2022) doi:10.1016/j.jeconom.2022.04.001
MacKinnon, James. "Wild cluster bootstrap confidence intervals." L'Actualite economique 91.1-2 (2015): 11-33.
Webb, Matthew D. "Reworking wild bootstrap based inference for clustered errors" . No. 1315. Queen's Economics Department Working Paper, 2013.
## Not run: requireNamespace("lfe") requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(wboottest) print(wboottest) nobs(wboottest) pval(wboottest) generics::tidy(wboottest) ## End(Not run)
## Not run: requireNamespace("lfe") requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(wboottest) print(wboottest) nobs(wboottest) pval(wboottest) generics::tidy(wboottest) ## End(Not run)
mboottest.fixest
is a S3 method that allows for fast wild cluster
bootstrap inference of multivariate hypotheses for objects of class
fixest by implementing the fast wild bootstrap algorithm developed
in Roodman et al., 2019.
## S3 method for class 'fixest' mboottest( object, clustid, B, R, r = rep(0, nrow(R)), bootcluster = "max", fe = NULL, type = "rademacher", impose_null = TRUE, p_val_type = "two-tailed", tol = 1e-06, floattype = "Float64", getauxweights = FALSE, maxmatsize = NULL, bootstrapc = FALSE, ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), ... )
## S3 method for class 'fixest' mboottest( object, clustid, B, R, r = rep(0, nrow(R)), bootcluster = "max", fe = NULL, type = "rademacher", impose_null = TRUE, p_val_type = "two-tailed", tol = 1e-06, floattype = "Float64", getauxweights = FALSE, maxmatsize = NULL, bootstrapc = FALSE, ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), ... )
object |
An object of class feols |
clustid |
A character vector or rhs formula containing the names of the cluster variables |
B |
Integer. The number of bootstrap iterations. When the number of clusters is low, increasing B adds little additional runtime. |
R |
Hypothesis Vector or Matrix giving linear combinations of coefficients. Must be either a vector of length k or a matrix of dimension q x k, where q is the number of joint hypotheses and k the number of estimated coefficients. |
r |
A vector of length q, where q is the number of tested hypotheses. Shifts the null hypothesis H0: param = r vs H1: param != r. If not provided, a vector of zeros of length q. |
bootcluster |
A character vector or rhs formula of length 1. Specifies
the bootstrap clustering variable or variables. If more
than one variable is specified, then bootstrapping is clustered by
the intersections of
clustering implied by the listed variables. To mimic the behavior of
stata's boottest command,
the default is to cluster by the intersection of all the variables
specified via the |
fe |
A character vector or rhs formula of length one which contains the name of the fixed effect to be projected out in the bootstrap. Note: if regression weights are used, fe needs to be NULL. |
type |
character or function. The character string specifies the type
of boostrap to use: One of "rademacher", "mammen", "norm", "gamma"
and "webb". Alternatively, type can be a function(n) for drawing
wild bootstrap factors. "rademacher" by default.
For the Rademacher and Mammen distribution, if the number of
replications B exceeds
the number of possible draw ombinations, 2^(#number of clusters),
then |
impose_null |
Logical. Controls if the null hypothesis is imposed on
the bootstrap dgp or not. Null imposed |
p_val_type |
Character vector of length 1. Type of p-value. By default "two-tailed". Other options include "equal-tailed", ">" and "<". |
tol |
Numeric vector of length 1. The desired accuracy (convergence tolerance) used in the root finding procedure to find the confidence interval. Relative tolerance of 1e-6 by default. |
floattype |
Float64 by default. Other option: Float32. Should floating point numbers in Julia be represented as 32 or 64 bit? |
getauxweights |
Logical. FALSE by default. Whether to save auxilliary weight matrix (v) |
maxmatsize |
NULL by default = no limit. Else numeric scalar to set the maximum size of auxilliary weight matrix (v), in gigabytes |
bootstrapc |
Logical scalar, FALSE by default. TRUE to request bootstrap-c instead of bootstrap-t |
ssc |
An object of class |
... |
Further arguments passed to or from other methods. |
An object of class mboottest
p_val |
The bootstrap p-value. |
N |
Sample size. Might differ from the regression sample size if the cluster variables contain NA values. |
boot_iter |
Number of Bootstrap Iterations. |
clustid |
Names of the cluster Variables. |
N_G |
Dimension of the cluster variables as used in boottest. |
sign_level |
Significance level used in boottest. |
type |
Distribution of the bootstrap weights. |
impose_null |
Whether the null was imposed on the bootstrap dgp or not. |
R |
The vector "R" in the null hypothesis of interest Rbeta = r. |
r |
The scalar "r" in the null hypothesis of interest Rbeta = r. |
point_estimate |
R'beta. A scalar: the constraints vector times the regression coefficients. |
teststat_stat |
The 'original' regression test statistics. |
teststat_boot |
All bootstrap t-statistics. |
regression |
The regression object used in boottest. |
call |
Function call of boottest. |
To guarantee reproducibility, you need to
set a global random seed viaset.seed()
If your feols() model contains fixed effects, boottest() will internally convert all fixed
effects but the one specified via the fe
argument to dummy variables.
boottest
quietlyYou can suppress all warning and error messages by setting the following global
options:
options(rlib_warning_verbosity = "quiet")
options(rlib_message_verbosity = "quiet")
Not that this will turn off all warnings (messages) produced via rlang::warn()
and
rlang::inform()
, which might not be desirable if you use other software build on
rlang
, as e.g. the tidyverse
.
Roodman et al., 2019, "Fast and wild: Bootstrap inference in STATA using boottest", The STATA Journal. (https://ideas.repec.org/p/qed/wpaper/1406.html)
Cameron, A. Colin, Jonah B. Gelbach, and Douglas L. Miller. "Bootstrap-based improvements for inference with clustered errors." The Review of Economics and Statistics 90.3 (2008): 414-427.
Cameron, A.Colin & Douglas L. Miller. "A practitioner's guide to cluster-robust inference" Journal of Human Resources (2015) doi:10.3368/jhr.50.2.317
Davidson & MacKinnon. "Wild Bootstrap Tests for IV regression" Journal of Economics and Business Statistics (2010) doi:10.1198/jbes.2009.07221
MacKinnon, James G., and Matthew D. Webb. "The wild bootstrap for few (treated) clusters." The Econometrics Journal 21.2 (2018): 114-135.
MacKinnon, James G., and Matthew D. Webb. "Cluster-robust inference: A guide to empirical practice" Journal of Econometrics (2022) doi:10.1016/j.jeconom.2022.04.001
MacKinnon, James. "Wild cluster bootstrap confidence intervals." L'Actualite economique 91.1-2 (2015): 11-33.
Webb, Matthew D. "Reworking wild bootstrap based inference for clustered errors" . No. 1315. Queen's Economics Department Working Paper, 2013.
## Not run: requireNamespace("fwildclusterboot") requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(wboottest) print(wboottest) nobs(wboottest) pval(wboottest) generics::tidy(wboottest) ## End(Not run)
## Not run: requireNamespace("fwildclusterboot") requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(wboottest) print(wboottest) nobs(wboottest) pval(wboottest) generics::tidy(wboottest) ## End(Not run)
mboottest.lm
is a S3 method that allows for fast wild cluster
bootstrap inference of multivariate hypotheses for objects of class lm by
implementing the fast wild bootstrap algorithm developed in
Roodman et al., 2019.
## S3 method for class 'lm' mboottest( object, clustid, B, R, r = rep(0, nrow(R)), bootcluster = "max", type = "rademacher", impose_null = TRUE, p_val_type = "two-tailed", tol = 1e-06, floattype = "Float64", getauxweights = FALSE, maxmatsize = NULL, bootstrapc = FALSE, ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), ... )
## S3 method for class 'lm' mboottest( object, clustid, B, R, r = rep(0, nrow(R)), bootcluster = "max", type = "rademacher", impose_null = TRUE, p_val_type = "two-tailed", tol = 1e-06, floattype = "Float64", getauxweights = FALSE, maxmatsize = NULL, bootstrapc = FALSE, ssc = boot_ssc(adj = TRUE, fixef.K = "none", cluster.adj = TRUE, cluster.df = "conventional"), ... )
object |
An object of class lm |
clustid |
A character vector or rhs formula containing the names of the cluster variables |
B |
Integer. The number of bootstrap iterations. When the number of clusters is low, increasing B adds little additional runtime. |
R |
Hypothesis Vector or Matrix giving linear combinations of coefficients. Must be either a vector of length k or a matrix of dimension q x k, where q is the number of joint hypotheses and k the number of estimated coefficients. |
r |
A vector of length q, where q is the number of tested hypotheses. Shifts the null hypothesis H0: param = r vs H1: param != r. If not provided, a vector of zeros of length q. |
bootcluster |
A character vector or rhs formula of length 1. Specifies
the bootstrap clustering variable or variables. If more
than one variable is specified, then bootstrapping is clustered by
the intersections of
clustering implied by the listed variables. To mimic the behavior of
stata's boottest command,
the default is to cluster by the intersection of all the variables
specified via the |
type |
character or function. The character string specifies the type
of boostrap to use: One of "rademacher", "mammen", "norm", "gamma"
and "webb". Alternatively, type can be a function(n) for drawing
wild bootstrap factors. "rademacher" by default.
For the Rademacher and Mammen distribution, if the number of
replications B exceeds
the number of possible draw ombinations, 2^(#number of clusters),
then |
impose_null |
Logical. Controls if the null hypothesis is imposed on
the bootstrap dgp or not. Null imposed |
p_val_type |
Character vector of length 1. Type of p-value. By default "two-tailed". Other options include "equal-tailed", ">" and "<". |
tol |
Numeric vector of length 1. The desired accuracy (convergence tolerance) used in the root finding procedure to find the confidence interval. Relative tolerance of 1e-6 by default. |
floattype |
Float64 by default. Other option: Float32. Should floating point numbers in Julia be represented as 32 or 64 bit? |
getauxweights |
Logical. FALSE by default. Whether to save auxilliary weight matrix (v) |
maxmatsize |
NULL by default = no limit. Else numeric scalar to set the maximum size of auxilliary weight matrix (v), in gigabytes |
bootstrapc |
Logical scalar, FALSE by default. TRUE to request bootstrap-c instead of bootstrap-t |
ssc |
An object of class |
... |
Further arguments passed to or from other methods. |
An object of class mboottest
p_val |
The bootstrap p-value. |
N |
Sample size. Might differ from the regression sample size if the cluster variables contain NA values. |
boot_iter |
Number of Bootstrap Iterations. |
clustid |
Names of the cluster Variables. |
N_G |
Dimension of the cluster variables as used in boottest. |
sign_level |
Significance level used in boottest. |
type |
Distribution of the bootstrap weights. |
impose_null |
Whether the null was imposed on the bootstrap dgp or not. |
R |
The vector "R" in the null hypothesis of interest Rbeta = r. |
r |
The scalar "r" in the null hypothesis of interest Rbeta = r. |
point_estimate |
R'beta. A scalar: the constraints vector times the regression coefficients. |
teststat_stat |
The 'original' regression test statistics. |
teststat_boot |
All bootstrap t-statistics. |
regression |
The regression object used in boottest. |
call |
Function call of boottest. |
To guarantee reproducibility, you need to
set a global random seed via set.seed()
boottest
quietlyYou can suppress all warning and error messages by setting the following global
options:
options(rlib_warning_verbosity = "quiet")
options(rlib_message_verbosity = "quiet")
Note that this will turn off all warnings (messages) produced via rlang::warn()
and
rlang::inform()
, which might not be desirable if you use other software build on
rlang
, as e.g. the tidyverse
.
Roodman et al., 2019, "Fast and wild: Bootstrap inference in STATA using boottest", The STATA Journal. (https://ideas.repec.org/p/qed/wpaper/1406.html)
Cameron, A. Colin, Jonah B. Gelbach, and Douglas L. Miller. "Bootstrap-based improvements for inference with clustered errors." The Review of Economics and Statistics 90.3 (2008): 414-427.
Cameron, A.Colin & Douglas L. Miller. "A practitioner's guide to cluster-robust inference" Journal of Human Resources (2015) doi:10.3368/jhr.50.2.317
Davidson & MacKinnon. "Wild Bootstrap Tests for IV regression" Journal of Economics and Business Statistics (2010) doi:10.1198/jbes.2009.07221
MacKinnon, James G., and Matthew D. Webb. "The wild bootstrap for few (treated) clusters." The Econometrics Journal 21.2 (2018): 114-135.
MacKinnon, James G., and Matthew D. Webb. "Cluster-robust inference: A guide to empirical practice" Journal of Econometrics (2022) doi:10.1016/j.jeconom.2022.04.001
MacKinnon, James. "Wild cluster bootstrap confidence intervals." L'Actualite economique 91.1-2 (2015): 11-33.
Webb, Matthew D. "Reworking wild bootstrap based inference for clustered errors" . No. 1315. Queen's Economics Department Working Paper, 2013.
## Not run: requireNamespace("clubSandwich") requireNamespace("fwildclusterboot") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(wboottest) print(wboottest) nobs(wboottest) pval(wboottest) generics::tidy(wboottest) ## End(Not run)
## Not run: requireNamespace("clubSandwich") requireNamespace("fwildclusterboot") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(wboottest) print(wboottest) nobs(wboottest) pval(wboottest) generics::tidy(wboottest) ## End(Not run)
boottest()
S3 method to obtain the effective number of observation used in boottest()
## S3 method for class 'boottest' nobs(object, ...)
## S3 method for class 'boottest' nobs(object, ...)
object |
object of type boottest |
... |
Further arguments passed to or from other methods. |
A scalar containing the effective number of observations
used in boottest()
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) nobs(boot)
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) nobs(boot)
mboottest()
S3 method to obtain the effective number of observation used
in mboottest()
## S3 method for class 'mboottest' nobs(object, ...)
## S3 method for class 'mboottest' nobs(object, ...)
object |
object of type mboottest |
... |
Further arguments passed to or from other methods. |
A scalar containing the effective number of observations
used in mboottest()
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) nobs(wboottest) ## End(Not run)
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) nobs(wboottest) ## End(Not run)
Plots bootstrapped p-values as a function of the hypothesized effect size r for a hypothesis test of the form R beta = r.The points where the p-values are 0.05 are the boundaries of the bootstrapped confidence interval.
## S3 method for class 'boottest' plot(x, ...)
## S3 method for class 'boottest' plot(x, ...)
x |
An object of type boottest |
... |
Further arguments passed to or from other methods. |
A plot of bootstrap t-statistics under different null hypotheses
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) plot(boot)
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) plot(boot)
bboottest
S3 method to print key information for objects of type bboottest
## S3 method for class 'boottest' print(x, ..., digits = 4)
## S3 method for class 'boottest' print(x, ..., digits = 4)
x |
object of type boottest |
... |
Further arguments passed to or from other methods. |
digits |
Number of rounding digits |
A scalar containing the effective number of observations
used in mboottest
#' requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) print(boot)
#' requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) print(boot)
mboottest
S3 method to print key information for objects of type mboottest
## S3 method for class 'mboottest' print(x, ..., digits = 4)
## S3 method for class 'mboottest' print(x, ..., digits = 4)
x |
object of type mboottest |
... |
Further arguments passed to or from other methods. |
digits |
Number of rounding digits |
A scalar containing the effective number of observations used
in mboottest
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) print(wboottest) ## End(Not run)
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) print(wboottest) ## End(Not run)
pval
is a S3 method to collect pvalues for objects
of type boottest
and mboottest
pval
is a S3 method to collect pvalues for objects
of type boottest
and mboottest
pval(object, ...)
pval(object, ...)
object |
An object of type lm, fixest, felm or ivreg |
... |
other arguments |
A scalar with the bootstrapped p-value.
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) pval(boot)
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) pval(boot)
S3 method to obtain the wild cluster bootstrapped p-value of an object of type boottest
## S3 method for class 'boottest' pval(object, ...)
## S3 method for class 'boottest' pval(object, ...)
object |
object of type boottest |
... |
Further arguments passed to or from other methods. |
A vector containing the boundaries of the wild cluster bootstrapped p-value
#' requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) confint(boot)
#' requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) confint(boot)
S3 method to obtain the wild cluster bootstrapped p-value of an object of type mboottest
## S3 method for class 'mboottest' pval(object, ...)
## S3 method for class 'mboottest' pval(object, ...)
object |
object of type mboottest |
... |
Further arguments passed to or from other methods. |
A vector containing the boundaries of the wild cluster bootstrapped p-value
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) pval(wboottest) ## End(Not run)
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) pval(wboottest) ## End(Not run)
boottest()
and mboottest()
Sets the default bootstrap algo for the current R session
to be run via boottest()
and mboottest()
setBoottest_engine(engine)
setBoottest_engine(engine)
engine |
Character scalar. Either 'R' or 'WildBootTests.jl'. Default is 'R' |
No return value
## Not run: setBoottest_engine(engine = "R") setBoottest_engine(engine = "WildBootTests.jl") ## End(Not run)
## Not run: setBoottest_engine(engine = "R") setBoottest_engine(engine = "WildBootTests.jl") ## End(Not run)
S3 method to summarize objects of class boottest
## S3 method for class 'boottest' summary(object, digits = 3, ...)
## S3 method for class 'boottest' summary(object, digits = 3, ...)
object |
object of type boottest |
digits |
rounding of output. 3 by default |
... |
Further arguments passed to or from other methods. |
Returns result summaries for objects of type boottest
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) summary(boot)
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) summary(boot)
S3 method to summarize objects of class mboottest
## S3 method for class 'mboottest' summary(object, digits = 3, ...)
## S3 method for class 'mboottest' summary(object, digits = 3, ...)
object |
object of type mboottest |
digits |
rounding of output. 3 by default |
... |
Further arguments passed to or from other methods. |
Returns result summaries for objects of type mboottest
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(wboottest) print(wboottest) nobs(wboottest) pval(wboottest) generics::tidy(wboottest) ## End(Not run)
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(wboottest) print(wboottest) nobs(wboottest) pval(wboottest) generics::tidy(wboottest) ## End(Not run)
teststat
is a S3 method to collect teststats for objects
of type boottest
and mboottest
teststat
is a S3 method to collect teststats for objects
of type boottest
and mboottest
teststat(object, ...)
teststat(object, ...)
object |
An object of type lm, fixest, felm or ivreg |
... |
other arguments |
A scalar with containing the non-bootstrapped test statistic of interest
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) teststat(boot)
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) teststat(boot)
boottest()
S3 method to obtain the non-bootstrapped t-statistic calculated
via boottest()
## S3 method for class 'boottest' teststat(object, ...)
## S3 method for class 'boottest' teststat(object, ...)
object |
An object of type boottest |
... |
Further arguments passed to or from other methods. |
A vector containing the non-bootstrapped t-statistic
calculated in boottest()
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) teststat(boot)
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) teststat(boot)
mboottest()
S3 method to obtain the non-bootstrapped test statistic calculated
via mboottest()
## S3 method for class 'mboottest' teststat(object, ...)
## S3 method for class 'mboottest' teststat(object, ...)
object |
An object of type 'mboottest' |
... |
Further arguments passed to or from other methods. |
A vector containing the non-bootstrapped t-statistic calculated
in mboottest()
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) teststat(wboottest) ## End(Not run)
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) teststat(wboottest) ## End(Not run)
S3 method to summarize objects of class boottest into tidy data.frame
## S3 method for class 'boottest' tidy(x, ...)
## S3 method for class 'boottest' tidy(x, ...)
x |
object of type boottest |
... |
Further arguments passed to or from other methods. |
A tidy data.frame with estimation results for objects of type boottest
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) generics::tidy(boot)
requireNamespace("fwildclusterboot") data(voters) lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) boot <- boottest(lm_fit, B = 9999, param = "treatment", clustid = "group_id1" ) generics::tidy(boot)
S3 method to summarize objects of class mboottest into tidy data.frame
## S3 method for class 'mboottest' tidy(x, ...)
## S3 method for class 'mboottest' tidy(x, ...)
x |
object of type mboottest |
... |
Further arguments passed to or from other methods. |
A tidy data.frame with estimation results for objects of type mboottest
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(wboottest) print(wboottest) nobs(wboottest) pval(wboottest) generics::tidy(wboottest) ## End(Not run)
## Not run: requireNamespace("clubSandwich") R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) wboottest <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(wboottest) print(wboottest) nobs(wboottest) pval(wboottest) generics::tidy(wboottest) ## End(Not run)
Random example data set
data(voters)
data(voters)
An object of class data.frame
with 300 rows and 13 columns.
data(voters)
data(voters)