### Install fwildclusterboot development version from GitHub Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/README.md Install the latest development version of fwildclusterboot directly from GitHub. This requires Rtools to be installed. ```r library(devtools) install_github("s3alfisc/fwildclusterboot") ``` -------------------------------- ### Install fwildclusterboot from CRAN Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/README.md Install the stable version of the fwildclusterboot package from CRAN. This is the recommended method for most users. ```r install.packages("fwildclusterboot") ``` -------------------------------- ### Configure boottest with R engine and bootstrap_type '11' Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/NEWS.md Illustrates the updated syntax for the boottest function, reflecting the renaming of 'boot_algo' to 'engine' and 'setBoottest_boot_algo()' to 'setBoottest_engine()'. This example uses the 'R' engine with bootstrap_type '11', demonstrating the current standard configuration. ```R boottest( lm_fit, param = ~treatment, clustid = ~group_id1, B = 9999, impose_null = TRUE, engine = "R", bootstrap_type = "11" ) ``` -------------------------------- ### Add GNU GPL Source File Header Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/LICENSE.md Include this notice at the start of each source file to state the exclusion of warranty and provide license information. ```text Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ``` -------------------------------- ### Install fwildclusterboot from r-universe Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/README.md Install a compiled version of the fwildclusterboot package from the r-universe repository. Requires R version 4.0 or higher. ```r install.packages('fwildclusterboot', repos ='https://s3alfisc.r-universe.dev') ``` -------------------------------- ### Handle formula sugar errors in boottest Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/NEWS.md Example of a configuration that may lead to errors when using formula sugar with fixest models. ```R feols_fit2 <- feols(proposition_vote ~ treatment | Q1_immigration^Q2_defense, data = voters ) boot1 <- boottest(feols_fit2, B = 9999, param = "treatment", clustid = "group_id1" ) ``` -------------------------------- ### Add Interactive Terminal License Notice Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/LICENSE.md Display this notice when a program starts in interactive mode to inform users about warranty and redistribution conditions. ```text Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free software, and you are welcome to redistribute it under certain conditions; type 'show c' for details. ``` -------------------------------- ### Use formulas for boottest arguments Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/NEWS.md Shows how to pass param and clustid arguments as formulas to boottest(). ```R data(voters) feols_fit <- feols(proposition_vote ~ treatment , data = voters ) boot <- boottest(feols_fit, B = 9999, param = ~ treatment, clustid = ~ group_id1 ) ``` -------------------------------- ### Configure boottest with WildBootTests.jl engine Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/NEWS.md Demonstrates how to specify the 'WildBootTests.jl' engine for the boottest function, enabling the use of Julia-based wild bootstrap algorithms. This is useful for leveraging advanced features or performance improvements offered by the Julia ecosystem. ```R boottest( lm_fit, param = ~treatment, clustid = ~group_id1, B = 9999, impose_null = TRUE, engine = "WildBootTests.jl", bootstrap_type = "11" ) ``` -------------------------------- ### Execute WildBootTests.jl algorithm Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/NEWS.md Configures boottest() to use the fast Julia-based WildBootTests.jl implementation. ```R # load data set voters included in fwildclusterboot data(voters) # estimate the regression model via lm lm_fit <- lm(proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration , data = voters) boot_lm <- boottest( lm_fit, clustid = "group_id1", param = "treatment", B = 9999, boot_algo = "WildBootTests.jl" ) ``` -------------------------------- ### Run boottest with fixest models Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/NEWS.md Demonstrates using boottest() with fixest objects, including support for syntactic sugar and split-sample models. ```R library(fwildclusterboot) library(fixest) data(voters) feols_fit <- feols(proposition_vote ~ i(treatment, ideology1) , data = voters ) boot1 <- boottest(feols_fit, B = 9999, param = "treatment::0:ideology1", clustid = "group_id1" ) feols_fits <- fixest::feols(proposition_vote ~ treatment | sw(Q1_immigration, Q2_defense), data = voters) res <- lapply(feols_fits, \(x) boottest(x, B = 999, param = "treatment", clustid = "group_id1")) voters$split <- sample(1:2, nrow(voters), TRUE) feols_fits <- fixest::feols(proposition_vote ~ treatment, split = ~split, data = voters) res <- lapply(feols_fits, \(x) boottest(x, B = 999, param = "treatment", clustid = "group_id1")) ``` -------------------------------- ### Load fwildclusterboot and set seeds Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/README.md Load the fwildclusterboot library and set random seeds for reproducibility. Uses dqset.seed for specific algorithms and set.seed for others. ```r library(fwildclusterboot) # set seed via dqset.seed for engine = "R" & Rademacher, Webb & Normal weights dqrng::dqset.seed(2352342) # set 'familiar' seed for all other algorithms and weight types set.seed(23325) ``` -------------------------------- ### boottest() - Multiway Clustering Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Demonstrates how to perform wild cluster bootstrap inference with multiple levels of clustering. ```APIDOC ## POST /boottest/multiway ### Description Performs wild cluster bootstrap inference with multiway clustering. ### Method POST ### Endpoint /boottest/multiway ### Parameters #### Request Body - **model** (object) - Required - The fitted linear model object. - **param** (string) - Required - The parameter to test. - **clustid** (array of strings) - Required - A list of cluster ID variables for multiway clustering. - **B** (integer) - Optional - Number of bootstrap iterations. Defaults to 9999. - **bootcluster** (string) - Optional - Specifies the clustering level for bootstrapping ('min' or 'max'). ### Request Example ```json { "model": "lm_fit", "param": "treatment", "clustid": ["group_id1", "group_id2"], "B": 9999 } ``` ### Response #### Success Response (200) - **p_value** (numeric) - The bootstrap p-value. - **conf_low** (numeric) - The lower bound of the confidence interval. - **conf_high** (numeric) - The upper bound of the confidence interval. - **statistic** (numeric) - The test statistic. - **estimate** (numeric) - The estimated coefficient. #### Response Example ```json { "p_value": 0.001, "conf_low": 0.039, "conf_high": 0.119, "statistic": 3.983, "estimate": 0.079 } ``` ``` -------------------------------- ### Run R-lean bootstrap algorithm Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/NEWS.md Use the 'R-lean' algorithm to perform a memory-efficient wild cluster bootstrap. ```r boot_lm <- boottest( lm_fit, clustid = "group_id1", param = "treatment", B = 9999, boot_algo = "R-lean" ) ``` -------------------------------- ### Configure boottest with R engine and bootstrap_type Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/NEWS.md Shows how to configure the boottest function using the default 'R' engine while specifying a particular bootstrap type, such as '31' (WCR13). This allows for testing specific wild cluster bootstrap variants as described in MacKinnon, Nielsen & Webb (2022). Note that this configuration has limitations regarding regression weights, fixed effects, and confidence intervals. ```R boottest( lm_fit, param = ~treatment, clustid = ~group_id1, B = 9999, impose_null = TRUE, engine = "R", bootstrap_type = "31" ) ``` -------------------------------- ### boottest() - Basic Usage Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Performs wild cluster bootstrap inference on linear regression models. Tests univariate hypotheses and returns p-values with confidence intervals. ```APIDOC ## POST /boottest ### Description Performs wild cluster bootstrap inference on linear regression models. ### Method POST ### Endpoint /boottest ### Parameters #### Request Body - **model** (object) - Required - The fitted linear model object (e.g., from lm(), feols(), felm(), ivreg()). - **param** (string or vector) - Required - The parameter(s) to test. - **clustid** (string or vector) - Required - The cluster ID variable(s). - **B** (integer) - Optional - Number of bootstrap iterations. Defaults to 9999. - **r** (numeric) - Optional - The value to test against for the hypothesis R*beta = r. Defaults to 0. - **R** (matrix or vector) - Optional - The matrix or vector for testing linear combinations of parameters. - **bootcluster** (string) - Optional - Specifies the clustering level for bootstrapping ('min' or 'max'). - **bootstrap_type** (string) - Optional - The type of wild bootstrap algorithm (e.g., 'fnw11', '31', '33'). - **impose_null** (boolean) - Optional - Whether to impose the null hypothesis during bootstrapping. Defaults to TRUE for WCR types. - **type** (string) - Optional - The type of bootstrap weight distribution ('rademacher', 'mammen', 'webb', 'normal'). Defaults to 'rademacher'. ### Request Example ```json { "model": "lm_fit", "param": "treatment", "clustid": "group_id1", "B": 9999 } ``` ### Response #### Success Response (200) - **p_value** (numeric) - The bootstrap p-value. - **conf_low** (numeric) - The lower bound of the confidence interval. - **conf_high** (numeric) - The upper bound of the confidence interval. - **statistic** (numeric) - The test statistic. - **estimate** (numeric) - The estimated coefficient. #### Response Example ```json { "p_value": 0.001, "conf_low": 0.039, "conf_high": 0.119, "statistic": 3.983, "estimate": 0.079 } ``` ``` -------------------------------- ### Using WildBootTests.jl Engine for Bootstrap Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Run the bootstrap through the high-performance Julia implementation of WildBootTests.jl. Set the engine using `setBoottest_engine("WildBootTests.jl")` for subsequent calls to automatically use Julia. ```r # Single bootstrap via Julia boot_julia <- boottest( lm_fit, param = "treatment", clustid = "group_id1", B = 9999, engine = "WildBootTests.jl" ) # Set Julia as default engine for session setBoottest_engine("WildBootTests.jl") # Subsequent calls automatically use Julia boot_auto <- boottest( lm_fit, param = "treatment", clustid = "group_id1", B = 9999 ) ``` -------------------------------- ### Set Default Bootstrap Engine with setBoottest_engine Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Set the default bootstrap algorithm for the R session using `setBoottest_engine`. Options include 'R' (native), 'R-lean' (memory-efficient), and 'WildBootTests.jl' (Julia implementation). Use `getBoottest_engine()` to check the current setting. ```r # Use native R implementation (default) setBoottest_engine("R") # Use memory-efficient R implementation setBoottest_engine("R-lean") # Use Julia implementation (fastest, requires Julia + WildBootTests.jl) setBoottest_engine("WildBootTests.jl") # Get current engine setting getBoottest_engine() ``` -------------------------------- ### boottest() - Testing Linear Combinations Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Tests hypotheses involving linear combinations of multiple model parameters. ```APIDOC ## POST /boottest/linear_combination ### Description Tests hypotheses involving linear combinations of model parameters. ### Method POST ### Endpoint /boottest/linear_combination ### Parameters #### Request Body - **model** (object) - Required - The fitted linear model object. - **param** (array of strings) - Required - The parameters involved in the linear combination. - **R** (matrix or vector) - Required - The coefficients for the linear combination. - **r** (numeric) - Required - The value the linear combination is tested against. - **clustid** (string) - Required - The cluster ID variable. - **B** (integer) - Optional - Number of bootstrap iterations. Defaults to 9999. ### Request Example ```json { "model": "lm_fit", "param": ["treatment", "ideology1"], "R": [0.6, 0.2], "r": 0.02, "clustid": "group_id1", "B": 9999 } ``` ### Response #### Success Response (200) - **p_value** (numeric) - The bootstrap p-value for the linear combination. - **conf_low** (numeric) - The lower bound of the confidence interval. - **conf_high** (numeric) - The upper bound of the confidence interval. - **statistic** (numeric) - The test statistic. #### Response Example ```json { "p_value": 0.01, "conf_low": -0.01, "conf_high": 0.05, "statistic": 2.5 } ``` ``` -------------------------------- ### boottest() - Bootstrap Weight Types Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Allows selection of different bootstrap weight distributions. ```APIDOC ## POST /boottest/weight_type ### Description Performs wild cluster bootstrap inference using specified bootstrap weight distributions. ### Method POST ### Endpoint /boottest/weight_type ### Parameters #### Request Body - **model** (object) - Required - The fitted linear model object. - **param** (string) - Required - The parameter to test. - **clustid** (string) - Required - The cluster ID variable. - **B** (integer) - Optional - Number of bootstrap iterations. Defaults to 9999. - **type** (string) - Required - The type of bootstrap weight distribution ('rademacher', 'mammen', 'webb', 'normal'). ### Request Example ```json { "model": "lm_fit", "param": "treatment", "clustid": "group_id1", "B": 9999, "type": "webb" } ``` ### Response #### Success Response (200) - **p_value** (numeric) - The bootstrap p-value. - **conf_low** (numeric) - The lower bound of the confidence interval. - **conf_high** (numeric) - The upper bound of the confidence interval. - **statistic** (numeric) - The test statistic. - **estimate** (numeric) - The estimated coefficient. #### Response Example ```json { "p_value": 0.002, "conf_low": 0.04, "conf_high": 0.12, "statistic": 3.8, "estimate": 0.08 } ``` ``` -------------------------------- ### boottest() - Bootstrap Types Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Allows selection of different wild bootstrap algorithm types. ```APIDOC ## POST /boottest/bootstrap_type ### Description Performs wild cluster bootstrap inference using specified bootstrap algorithm types. ### Method POST ### Endpoint /boottest/bootstrap_type ### Parameters #### Request Body - **model** (object) - Required - The fitted linear model object. - **param** (string) - Required - The parameter to test. - **clustid** (string) - Required - The cluster ID variable. - **B** (integer) - Optional - Number of bootstrap iterations. Defaults to 9999. - **bootstrap_type** (string) - Required - The type of wild bootstrap algorithm (e.g., 'fnw11', '31', '33'). - **impose_null** (boolean) - Optional - Whether to impose the null hypothesis during bootstrapping. ### Request Example ```json { "model": "lm_fit", "param": "treatment", "clustid": "group_id1", "B": 9999, "bootstrap_type": "31", "impose_null": true } ``` ### Response #### Success Response (200) - **p_value** (numeric) - The bootstrap p-value. - **conf_low** (numeric) - The lower bound of the confidence interval. - **conf_high** (numeric) - The upper bound of the confidence interval. - **statistic** (numeric) - The test statistic. - **estimate** (numeric) - The estimated coefficient. #### Response Example ```json { "p_value": 0.005, "conf_low": 0.02, "conf_high": 0.10, "statistic": 3.5, "estimate": 0.06 } ``` ``` -------------------------------- ### Demonstrate Global Seed Reseeding Behavior Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/NEWS.md Illustrates how internal function reseeding affects subsequent random number generation in the global environment. Use this to understand why explicit global seeding is now required. ```r fn_reseed <- function(x){set.seed(x)} set.seed(123) rnorm(1) # [1] -0.5604756 fn_reseed(1) rnorm(1) # [1] -0.6264538 set.seed(123) rnorm(1); rnorm(1) # [1] -0.5604756 # [1] -0.2301775 ``` -------------------------------- ### Select Bootstrap Weight Distributions Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Choose between different weight distributions for the bootstrap process using the type argument. ```r # Rademacher weights (default) boot_rade <- boottest( lm_fit, param = "treatment", clustid = "group_id1", B = 9999, type = "rademacher" ) # Webb weights (6-point distribution) boot_webb <- boottest( lm_fit, param = "treatment", clustid = "group_id1", B = 9999, type = "webb" ) # Mammen weights boot_mammen <- boottest( lm_fit, param = "treatment", clustid = "group_id1", B = 9999, type = "mammen" ) ``` -------------------------------- ### Retrieve Package Citation Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/README.md Generates the BibTeX citation for the fwildclusterboot package within an R session. ```R citation("fwildclusterboot") ``` -------------------------------- ### Parallel Execution for Bootstrap Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Speed up bootstrap computation using multiple threads for large problems by setting the `nthreads` argument in `boottest` or globally using `setBoottest_nthreads()`. ```r # Use 4 threads for parallel execution boot_parallel <- boottest( lm_fit, param = "treatment", clustid = "group_id1", B = 9999, nthreads = 4 # Use multiple threads ) # Set default threads globally setBoottest_nthreads(4) ``` -------------------------------- ### Perform Bootstrap Inference with boottest Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/README.md Executes a wild cluster bootstrap on a linear model fit. Requires a fitted model object and specification of cluster IDs and parameters. ```R lm_boot <- boottest(lm_fit, clustid = c("group_id1"), B = 9999, param = "treatment") summary(lm_boot) ``` -------------------------------- ### Bootstrap Models with Fixed Effects Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Use boottest.fixest() to handle models estimated with fixest::feols(). ```r library(fixest) # Estimate model with fixed effects feols_fit <- feols( proposition_vote ~ treatment + ideology1 + log_income | Q1_immigration, data = voters ) ``` -------------------------------- ### Configure Bootstrap Types Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Specify the bootstrap algorithm variant using the bootstrap_type argument and control null imposition with impose_null. ```r # Default: Fast and Wild algorithm (fnw11) boot_fnw11 <- boottest( lm_fit, param = "treatment", clustid = "group_id1", B = 9999, bootstrap_type = "fnw11" ) # WCR-31 variant boot_wcr31 <- boottest( lm_fit, param = "treatment", clustid = "group_id1", B = 9999, bootstrap_type = "31", impose_null = TRUE # WCR (null imposed) ) # WCU-33 variant (null not imposed) boot_wcu33 <- boottest( lm_fit, param = "treatment", clustid = "group_id1", B = 9999, bootstrap_type = "33", impose_null = FALSE # WCU (null not imposed) ) ``` -------------------------------- ### boottest.fixest() - Bootstrap with Fixed Effects Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Performs wild cluster bootstrap inference on models fitted with `fixest::feols()`, supporting fixed effects projection. ```APIDOC ## POST /boottest/fixest ### Description Performs wild cluster bootstrap inference on `fixest::feols()` models. ### Method POST ### Endpoint /boottest/fixest ### Parameters #### Request Body - **model** (object) - Required - The fitted `fixest::feols()` model object. - **param** (string) - Required - The parameter to test. - **clustid** (string or vector) - Required - The cluster ID variable(s). - **B** (integer) - Optional - Number of bootstrap iterations. Defaults to 9999. ### Request Example ```json { "model": "feols_fit", "param": "treatment", "clustid": "group_id1", "B": 9999 } ``` ### Response #### Success Response (200) - **p_value** (numeric) - The bootstrap p-value. - **conf_low** (numeric) - The lower bound of the confidence interval. - **conf_high** (numeric) - The upper bound of the confidence interval. - **statistic** (numeric) - The test statistic. - **estimate** (numeric) - The estimated coefficient. #### Response Example ```json { "p_value": 0.001, "conf_low": 0.039, "conf_high": 0.119, "statistic": 3.983, "estimate": 0.079 } ``` ``` -------------------------------- ### Perform Basic Wild Cluster Bootstrap Inference Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Use boottest() to perform inference on a linear model with one-way clustering. Ensure the model is fitted with lm() before passing it to the function. ```r library(fwildclusterboot) # Set seeds for reproducibility dqrng::dqset.seed(2352342) set.seed(23325) # Load example data data(voters) # Fit a linear model lm_fit <- lm( proposition_vote ~ treatment + ideology1 + log_income + Q1_immigration, data = voters ) # Basic bootstrap test with one-way clustering boot_result <- boottest( lm_fit, param = "treatment", clustid = "group_id1", B = 9999 ) # View results summary(boot_result) #> boottest.lm(object = lm_fit, param = "treatment", B = 9999, clustid = "group_id1") #> #> Hypothesis: 1*treatment = 0 #> Observations: 300 #> Bootstr. Type: rademacher #> Clustering: 1-way #> Confidence Sets: 95% #> Number of Clusters: 40 #> #> term estimate statistic p.value conf.low conf.high #> 1 1*treatment = 0 0.079 3.983 0.001 0.039 0.119 # Extract specific results pval(boot_result) # Bootstrap p-value confint(boot_result) # Confidence interval generics::tidy(boot_result) # Tidy data frame output ``` -------------------------------- ### Wild Restricted Efficient Bootstrap for IV Models Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Perform Wild Restricted Efficient (WRE) bootstrap for instrumental variables (IV) models using `boottest`. Requires the `ivreg` package for fitting the IV model. Ensure `type` is set to 'mammen' for WRE bootstrap. ```r library(ivreg) data("SchoolingReturns", package = "ivreg") SchoolingReturns <- na.omit(SchoolingReturns) # Fit IV model ivreg_fit <- ivreg( log(wage) ~ education + age + ethnicity + smsa + south + parents14 | nearcollege + age + ethnicity + smsa + south + parents14, data = SchoolingReturns ) # WRE bootstrap for IV boot_ivreg <- boottest( object = ivreg_fit, B = 999, param = "education", clustid = "kww", type = "mammen", impose_null = TRUE ) summary(boot_ivreg) generics::tidy(boot_ivreg) ``` -------------------------------- ### Visualize Bootstrap Results with plot.boottest Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Plot bootstrapped p-values as a function of the hypothesized effect size to visualize confidence interval boundaries. The points where p = 0.05 indicate the CI boundaries. ```r boot_result <- boottest( lm_fit, param = "treatment", clustid = "group_id1", B = 9999 ) # Plot p-values vs hypothesized effect size # Points where p = 0.05 are the CI boundaries plot(boot_result) ``` -------------------------------- ### Aggregate CATT Coefficients with boot_aggregate Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Aggregate Counterfactual Average Treatment Effect on the Treated (CATT) coefficients in staggered difference-in-differences models using wild cluster bootstrap inference. Requires the `fixest` package. ```r library(fixest) data(base_stagg) # Sun-Abraham DiD estimation res_sunab <- feols( y ~ x1 + sunab(year_treated, year) | id + year, data = base_stagg ) # Bootstrap aggregation for ATT boot_att <- boot_aggregate( res_sunab, B = 9999, agg = "ATT", clustid = "id" ) head(boot_att) ``` -------------------------------- ### Configure Small Sample Corrections with boot_ssc Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Configure small sample adjustments for the bootstrap procedure using `boot_ssc`. Adjustments include `adj` for (N-1)/(N-k) and `cluster.adj` for G/(G-1). `cluster.df` can be set to 'conventional' or 'min'. ```r # Default small sample corrections ssc_default <- boot_ssc( adj = TRUE, # Apply (N-1)/(N-k) adjustment fixef.K = "none", # Don't count FE in k cluster.adj = TRUE, # Apply G/(G-1) cluster adjustment cluster.df = "conventional" # Standard cluster df ) # Custom small sample corrections boot_custom <- boottest( lm_fit, param = "treatment", clustid = "group_id1", B = 9999, ssc = boot_ssc( adj = TRUE, cluster.adj = TRUE, cluster.df = "min" # Use min(G) for multiway ) ) ``` -------------------------------- ### Perform WRE bootstrap for IV models Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/NEWS.md Uses the WRE bootstrap for instrumental variables estimation via ivreg and WildBootTests.jl. ```R library(ivreg) data("SchoolingReturns", package = "ivreg") # 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 ) generics::tidy(boot_ivreg) # term estimate statistic p.value conf.low conf.high # 1 1*education = 0 0.0638822 1.043969 0.2482482 -0.03152655 0.2128746 ``` -------------------------------- ### Heteroskedastic Wild Bootstrap (HC1) Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Run heteroskedasticity-robust wild bootstrap (HC1) without clustering. This is the default behavior when `clustid` is not specified. ```r # Heteroskedastic bootstrap (no clustering) boot_hc <- boottest( lm_fit, param = "treatment", B = 9999 # No clustid = heteroskedastic bootstrap ) summary(boot_hc) boot_hc$engine # Uses "R-lean" algorithm ``` -------------------------------- ### Run heteroskedasticity-robust wild bootstrap Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/NEWS.md Perform a heteroskedasticity-robust wild bootstrap (HC1) by omitting the clustid argument. ```r boot_hc1 <- boottest(lm_fit, param = "treatment", B = 9999) summary(boot_hc1) ``` -------------------------------- ### Fit OLS model using lm Source: https://github.com/s3alfisc/fwildclusterboot/blob/master/README.md Fit an Ordinary Least Squares (OLS) model using the `lm` function from the stats package. This model can then be used with `boottest()`. ```r data(voters) # fit the model via fixest::feols(), lfe::felm() or stats::lm() lm_fit <- lm(proposition_vote ~ treatment + log_income + as.factor(Q1_immigration) + as.factor(Q2_defense), data = voters) ``` -------------------------------- ### Weighted Least Squares Bootstrap Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Incorporate regression weights into bootstrap inference by fitting a weighted least squares model first and then passing the weighted model object to `boottest`. ```r # Fit weighted regression lm_weighted <- lm( proposition_vote ~ treatment + ideology1 + log_income, weights = voters$weights, data = voters ) # Bootstrap with weights boot_weighted <- boottest( lm_weighted, param = "treatment", clustid = "group_id1", B = 9999 ) summary(boot_weighted) ``` -------------------------------- ### Joint Hypothesis Testing with mboottest Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Test multiple joint hypotheses (q > 1) using the `mboottest` function. Requires a constraint matrix `R` created with `clubSandwich::constrain_zero`. ```r library(clubSandwich) # Create constraint matrix for testing treatment = 0 AND ideology1 = 0 R <- clubSandwich::constrain_zero(2:3, coef(lm_fit)) # Joint hypothesis test mboot_result <- mboottest( object = lm_fit, clustid = "group_id1", B = 999, R = R ) summary(mboot_result) generics::tidy(mboot_result) ``` -------------------------------- ### Perform Multiway Clustering Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Pass a vector of cluster IDs to the clustid argument to perform multiway clustering. The bootcluster argument allows specifying which cluster level to use for the bootstrap. ```r # Two-way clustering boot_twoway <- boottest( lm_fit, param = "treatment", clustid = c("group_id1", "group_id2"), B = 9999 ) summary(boot_twoway) # Control bootstrap clustering level boot_min_cluster <- boottest( lm_fit, param = "treatment", clustid = c("group_id1", "group_id2"), B = 9999, bootcluster = "min" # Use cluster with fewest groups ) ``` -------------------------------- ### Bootstrap Fixed Effects Projection Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Project out fixed effects during bootstrap inference for clustered standard errors. Ensure the fixed effect is specified in the `fe` argument. ```r boot_feols <- boottest( feols_fit, param = "treatment", clustid = "group_id1", B = 9999, fe = "Q1_immigration" # Project out this FE in bootstrap ) summary(boot_feols) ``` -------------------------------- ### Test Linear Combinations of Coefficients Source: https://context7.com/s3alfisc/fwildclusterboot/llms.txt Test complex hypotheses by providing a vector of parameters and their corresponding weights in the R argument. ```r # Test hypothesis: 0.6*treatment + 0.2*ideology1 = 0.02 boot_multi <- boottest( lm_fit, param = c("treatment", "ideology1"), R = c(0.6, 0.2), r = 0.02, clustid = "group_id1", B = 9999 ) summary(boot_multi) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.