### Run mboottest example Source: https://s3alfisc.github.io/fwildclusterboot/reference/mboottest.lm.html Example usage of mboottest with clubSandwich constraints. ```R if (FALSE) { 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) } ``` -------------------------------- ### Example Usage of mboottest Source: https://s3alfisc.github.io/fwildclusterboot/reference/mboottest.lm.html An example demonstrating how to use the mboottest function and interact with its output. ```APIDOC ## Examples __``` if (FALSE) { 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) } ``` ``` -------------------------------- ### Example of boottest and print usage Source: https://s3alfisc.github.io/fwildclusterboot/reference/print.boottest.html Demonstrates how to perform wild cluster bootstrap inference using 'boottest' and then print the results. Ensure the 'fwildclusterboot' package is available. The example uses a linear model fit and specifies the parameter and clustering ID. ```R 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) ``` -------------------------------- ### Example Workflow for mboottest Source: https://s3alfisc.github.io/fwildclusterboot/reference/summary.mboottest.html Demonstrates the creation of an mboottest object and the application of various summary and extraction methods. ```R if (FALSE) { 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) } ``` -------------------------------- ### Install Development Dependencies Source: https://s3alfisc.github.io/fwildclusterboot/CONTRIBUTING.html Installs all necessary development dependencies for the package. Ensure this is run before proceeding with other development tasks. ```r devtools::install_dev_deps() ``` -------------------------------- ### Example Usage of mboottest Source: https://s3alfisc.github.io/fwildclusterboot/reference/mboottest.felm.html Demonstrates how to use the mboottest function for wild bootstrap inference. Requires the lfe and clubSandwich packages. The example shows setting up constraints and running the bootstrap test. ```R if (FALSE) { 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) } ``` -------------------------------- ### Example: Summarizing a boottest object Source: https://s3alfisc.github.io/fwildclusterboot/reference/summary.boottest.html Demonstrates running a wild cluster bootstrap on a linear model and summarizing the resulting object. ```R 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) ``` -------------------------------- ### Handle formula sugar errors in feols with boottest Source: https://s3alfisc.github.io/fwildclusterboot/news/index.html This example demonstrates a scenario where certain formula sugar in feols might lead to errors when used with boottest. It shows the feols model setup that can cause issues. ```R feols_fit2 <- feols(proposition_vote ~ treatment | Q1_immigration^Q2_defense, data = voters ) boot1 <- boottest(feols_fit2, B = 9999, param = "treatment", clustid = "group_id1" ) ``` -------------------------------- ### Example of mboottest printing Source: https://s3alfisc.github.io/fwildclusterboot/reference/print.mboottest.html Demonstrates how to run a bootstrap test and print the resulting object. ```R if (FALSE) { 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) } ``` -------------------------------- ### Example usage of glance.mboottest Source: https://s3alfisc.github.io/fwildclusterboot/reference/glance.mboottest.html Demonstrates how to run a wild cluster bootstrap and then extract a summary using the glance generic. ```R if (FALSE) { 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) } ``` -------------------------------- ### Install fwildclusterboot Package Source: https://s3alfisc.github.io/fwildclusterboot/index.html Install compiled versions of fwildclusterboot from CRAN, R-universe, or the development version from GitHub. Ensure Rtools is installed for GitHub installation. ```R install.packages("fwildclusterboot") ``` ```R install.packages('fwildclusterboot', repos ='https://s3alfisc.r-universe.dev') ``` ```R library(devtools) install_github("s3alfisc/fwildclusterboot") ``` -------------------------------- ### Example of tidying a boottest object Source: https://s3alfisc.github.io/fwildclusterboot/reference/tidy.boottest.html Demonstrates how to run a cluster bootstrap using boottest and convert the results into a tidy data frame. ```R 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) ``` -------------------------------- ### Install JuliaConnectoR.utils and Connect R to Julia Source: https://s3alfisc.github.io/fwildclusterboot/articles/WildBootTests.html Installs the JuliaConnectoR.utils package from GitHub and establishes a connection between R and Julia. This is a prerequisite for using Julia-based functionalities. ```R devtools::install_github("s3alfisc/JuliaConnectoR.utils") library(JuliaConnectoR.utils) connect_julia_r() # instructions to connect Julia and R install_julia_packages("WildBootTests.jl") # install WildBootTests.jl ``` -------------------------------- ### boot_aggregate() Source: https://s3alfisc.github.io/fwildclusterboot/reference/index.html Aggregates CATT coefficients in staggered difference-in-difference setups. ```APIDOC ## boot_aggregate() ### Description Simple tool that aggregates the value of CATT coefficients in staggered difference-in-difference setups with inference based on a wild cluster bootstrap. ``` -------------------------------- ### Load Example Data Set Source: https://s3alfisc.github.io/fwildclusterboot/reference/voters.html Loads the example 'voters' data set, which is an object of class data.frame with 300 rows and 13 columns. ```R data(voters) ``` -------------------------------- ### Performing wild cluster bootstrap with boottest Source: https://s3alfisc.github.io/fwildclusterboot/reference/pval.boottest.html Example demonstrating the estimation of a linear model and subsequent wild cluster bootstrap using the boottest function. ```R 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) ``` -------------------------------- ### Example of extracting observations from boottest Source: https://s3alfisc.github.io/fwildclusterboot/reference/nobs.boottest.html Demonstrates fitting a linear model, running a bootstrap, and retrieving the effective observation count. ```R 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) #> [1] 300 ``` -------------------------------- ### Define Starting Values for Root Finding Source: https://s3alfisc.github.io/fwildclusterboot/articles/wild_bootstrap.html Creates two sets of initial values for the root-finding algorithm by perturbing the boundaries of the confidence interval obtained from `confint()`. This is a crucial step for the bisection method to converge correctly. ```R epsilon <- 0.01 startset1 <- confint(fit)("X", )[1] + c(-epsilon, epsilon) startset2 <- confint(fit)("X", )[2] + c(-epsilon, epsilon) ``` -------------------------------- ### Check Julia System Requirements Source: https://s3alfisc.github.io/fwildclusterboot/articles/WildBootTests.html Verifies if the installed Julia and WildBootTests.jl versions meet the system requirements for fwildclusterboot. Run this after installing Julia and the necessary packages. ```R check_julia_system_requirements("fwildclusterboot") ``` -------------------------------- ### Load fwildclusterboot Package Source: https://s3alfisc.github.io/fwildclusterboot/articles/WildBootTests.html Loads the fwildclusterboot package and displays citation information. Ensure the package is installed before running. ```R library(fwildclusterboot) #> #> Please cite as: #> Fischer & Roodman. (2021). fwildclusterboot: Fast Wild Cluster. #> Bootstrap Inference for Linear Regression Models. #> Available from https://cran.r-project.org/package=fwildclusterboot/. set.seed(12312) ``` -------------------------------- ### Running boottest with IV Regression Source: https://s3alfisc.github.io/fwildclusterboot/reference/boottest.ivreg.html This example demonstrates how to perform bootstrap inference on an instrumental variable (IV) regression model using the boottest function. It includes data preparation, model fitting with ivreg, and subsequent bootstrap analysis with summary, print, plot, nobs, pval, confint, and tidy methods. ```R if (FALSE) { 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) } ``` -------------------------------- ### R: Reproducibility Example with set.seed Source: https://s3alfisc.github.io/fwildclusterboot/news/index.html Demonstrates how setting a global seed affects subsequent random number generation in R. This illustrates the behavior that led to the deprecation of the internal 'seed' argument in fwildclusterboot. ```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 ``` -------------------------------- ### Perform wild cluster bootstrap test Source: https://s3alfisc.github.io/fwildclusterboot/reference/mboottest.fixest.html Example workflow for running a bootstrap test using mboottest and accessing results. ```R if (FALSE) { 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) } ``` -------------------------------- ### Example: Extracting t-statistic from boottest Source: https://s3alfisc.github.io/fwildclusterboot/reference/teststat.boottest.html Demonstrates fitting a linear model, performing a wild cluster bootstrap, and extracting the original t-statistic. ```R 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) #> [1] 3.709435 ``` -------------------------------- ### Check for language installation Source: https://s3alfisc.github.io/fwildclusterboot/reference/find_proglang.html Use this function to verify if Julia or Python is available on the system path before attempting to call them. ```R find_proglang(lang) ``` ```R if (FALSE) { find_proglang(lang = "julia") } ``` -------------------------------- ### Run Bootstrap Using WildBootTests.jl Engine Source: https://s3alfisc.github.io/fwildclusterboot/articles/fwildclusterboot.html Execute the bootstrap procedure using the WildBootTests.jl package from Julia. This requires Julia and WildBootTests.jl to be installed and configured. ```R boot_lm <- boottest( lm_fit, clustid = "group_id1", param = "treatment", B = 9999, engine = "WildBootTests.jl" ) tidy(boot_lm) ``` -------------------------------- ### Check Programming Language Installation Source: https://s3alfisc.github.io/fwildclusterboot/reference/find_proglang.html This function checks if a specified programming language (Julia or Python) is installed and accessible on the system's PATH. ```APIDOC ## find_proglang ### Description Checks if julia or python are installed / can be found on the PATH. ### Method N/A (This is a utility function, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (logical) - **TRUE**: if the specified language is found on the PATH. - **FALSE**: if the specified language is not found on the PATH. #### Response Example ``` find_proglang(lang = "julia") # Returns TRUE or FALSE ``` ### Arguments - **lang** (character) - Required - Specifies which language to check. Either 'julia' or 'python'. ``` -------------------------------- ### Run boottest with R-lean bootstrap algorithm Source: https://s3alfisc.github.io/fwildclusterboot/news/index.html Utilize the R-lean implementation of the wild cluster bootstrap, which is a loop-based alternative to the memory-intensive vectorized 'fast' algorithm. This is suitable for larger problems where memory might be a constraint. ```R boot_lm <- boottest( lm_fit, clustid = "group_id1", param = "treatment", B = 9999, boot_algo = "R-lean" ) ``` -------------------------------- ### Configuration and Reproducibility Source: https://s3alfisc.github.io/fwildclusterboot/reference/boottest.ivreg.html Guidelines for setting random seeds and managing verbosity for the boottest function. ```APIDOC ## Configuration ### Reproducibility To guarantee reproducibility, set a global random seed using `set.seed()` before running `boottest`. ### Quiet Mode To suppress warning and error messages, set the following global options: - `options(rlib_warning_verbosity = "quiet")` - `options(rlib_message_verbosity = "quiet")` *Note: This will suppress all warnings/messages produced via rlang::warn() and rlang::inform().* ``` -------------------------------- ### Usage of summary.boottest Source: https://s3alfisc.github.io/fwildclusterboot/reference/summary.boottest.html Standard syntax for invoking the summary method on a boottest object. ```R # S3 method for boottest summary(object, digits = 3, ...) ``` -------------------------------- ### Example of pval usage Source: https://s3alfisc.github.io/fwildclusterboot/reference/pval.mboottest.html Demonstrates calculating a p-value from an mboottest object using the pval function. ```R if (FALSE) { 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) } ``` -------------------------------- ### Example usage of nobs with mboottest Source: https://s3alfisc.github.io/fwildclusterboot/reference/nobs.mboottest.html Demonstrates how to extract the effective number of observations after running a bootstrap test. ```R if (FALSE) { 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) } ``` -------------------------------- ### Run boottest with formula arguments for param and clustid Source: https://s3alfisc.github.io/fwildclusterboot/news/index.html Utilize formula notation for the 'param' and 'clustid' arguments in boottest. This approach can be more readable and less error-prone for complex model specifications. ```R data(voters) feols_fit <- feols(proposition_vote ~ treatment , data = voters ) boot <- boottest(feols_fit, B = 9999, param = ~ treatment, clustid = ~ group_id1 ) ``` -------------------------------- ### boot_aggregate Function Source: https://s3alfisc.github.io/fwildclusterboot/reference/boot_aggregate.html Aggregates CATT coefficients in staggered difference-in-difference setups with wild cluster bootstrap inference. ```APIDOC ## boot_aggregate ### Description Aggregates the value of CATT coefficients in staggered difference-in-difference setups with inference based on a wild cluster bootstrap. This function is designed to replicate the estimator from Sun and Abraham (2021). ### Parameters - **x** (object) - Required - The estimation object containing cohort and relative period dummies. - **agg** (formula/list) - Required - Specification for how to aggregate the CATT. - **full** (boolean) - Optional - Whether to return the full object. - **use_weights** (boolean) - Optional - Whether to use weights. - **clustid** (vector) - Optional - Cluster identifiers. - **B** (integer) - Required - Number of bootstrap iterations. - **bootstrap_type** (string) - Optional - Type of bootstrap (default: "fnw11"). - **bootcluster** (string) - Optional - Cluster definition for the bootstrap (default: "max"). - **fe** (vector) - Optional - Fixed effects. - **sign_level** (numeric) - Optional - Significance level (default: 0.05). - **beta0** (numeric) - Optional - Null hypothesis value. - **type** (string) - Optional - Type of bootstrap distribution (default: "rademacher"). - **impose_null** (boolean) - Optional - Whether to impose the null hypothesis. - **p_val_type** (string) - Optional - Type of p-value calculation (default: "two-tailed"). - **nthreads** (integer) - Optional - Number of threads to use. - **tol** (numeric) - Optional - Tolerance for convergence. - **maxiter** (integer) - Optional - Maximum number of iterations. - **ssc** (object) - Optional - Small sample correction settings. - **engine** (string) - Optional - Computational engine. - **floattype** (string) - Optional - Floating point precision (default: "Float64"). - **maxmatsize** (boolean) - Optional - Maximum matrix size. - **bootstrapc** (boolean) - Optional - Whether to use bootstrap-c. - **getauxweights** (boolean) - Optional - Whether to return auxiliary weights. - **sampling** (string) - Optional - Sampling method (default: "dqrng"). ``` -------------------------------- ### Run multiple wild cluster bootstrap variants Source: https://s3alfisc.github.io/fwildclusterboot/articles/Different-Variants-of-the-Wild-Cluster-Bootstrap.html Demonstrates how to execute different bootstrap types by iterating over a vector of algorithm names using boottest(). ```R library(fwildclusterboot) library(modelsummary) options(modelsummary_factory_default = "gt") N <- 1000 N_G1 <- 17 data <- fwildclusterboot:::create_data( N = N, N_G1 = N_G1, icc1 = 0.8, N_G2 = N_G1, icc2 = 0.8, numb_fe1 = 10, numb_fe2 = 5, seed = 41224, weights = 1:N / N ) lm_fit <- lm( proposition_vote ~ treatment + log_income, data = data ) wcr_algos <- c("fnw11","11", "13", "31", "33") run_all <- lapply(wcr_algos, function(x){ res <- boottest( lm_fit, param = ~treatment, clustid = ~group_id1, B = 9999, impose_null = TRUE, bootstrap_type = x ) }) names(run_all) <- paste("WCR", c("11 F&W", "11 F&R", "13 F&R", "31 F&R", "33 F&R")) msummary( run_all, estimate = "{estimate} ({p.value})", statistic = "[{conf.low}, {conf.high}]" ) ``` -------------------------------- ### Get fwildclusterboot Citation Source: https://s3alfisc.github.io/fwildclusterboot/index.html Retrieve the BibTeX citation for the fwildclusterboot package in R. This can be used for academic referencing. ```R citation("fwildclusterboot") ``` -------------------------------- ### S3 method: summary.boottest Source: https://s3alfisc.github.io/fwildclusterboot/reference/summary.boottest.html Summarizes objects of class boottest, providing statistical results such as estimates, statistics, p-values, and confidence intervals. ```APIDOC ## S3 method: summary.boottest ### Description Summarizes objects of class boottest to display results from wild cluster bootstrap inference. ### Usage summary(object, digits = 3, ...) ### Arguments - **object** (boottest) - Required - An object of type boottest. - **digits** (integer) - Optional - Number of digits for rounding output. Defaults to 3. - **...** (dots) - Optional - Further arguments passed to or from other methods. ### Value Returns result summaries for objects of type boottest. ### Request Example summary(boot, digits = 3) ### Response - **term** (string) - The hypothesis tested. - **estimate** (numeric) - The estimated coefficient. - **statistic** (numeric) - The test statistic. - **p.value** (numeric) - The calculated p-value. - **conf.low** (numeric) - Lower bound of the confidence interval. - **conf.high** (numeric) - Upper bound of the confidence interval. ``` -------------------------------- ### Example of extracting test statistics Source: https://s3alfisc.github.io/fwildclusterboot/reference/teststat.mboottest.html Demonstrates how to compute a wild cluster bootstrap test and retrieve the original test statistic. ```R if (FALSE) { 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) } ``` -------------------------------- ### Run boottest with WildBootTests.jl algorithm Source: https://s3alfisc.github.io/fwildclusterboot/news/index.html Execute the wild cluster bootstrap using the fast WildBootTests.jl implementation. Specify 'WildBootTests.jl' for the boot_algo argument to leverage this external package. ```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" ) ``` -------------------------------- ### boottest Function Parameters Source: https://s3alfisc.github.io/fwildclusterboot/reference/boottest.fixest.html Configuration parameters for the boottest function. ```APIDOC ## boottest Parameters ### Parameters #### Request Body - **engine** (character) - Optional - Either "R", "R-lean" or "WildBootTests.jl". Controls the bootstrap implementation. - **floattype** (string) - Optional - Float64 or Float32. Only relevant when engine = "WildBootTests.jl". - **maxmatsize** (numeric) - Optional - Maximum size of auxiliary weight matrix in gigabytes. Only relevant when engine = "WildBootTests.jl". - **bootstrapc** (logical) - Optional - TRUE to request bootstrap-c instead of bootstrap-t. Only relevant when engine = "WildBootTests.jl". - **getauxweights** (logical) - Optional - Whether to save auxiliary weight matrix (v). ``` -------------------------------- ### fwildclusterboot Arguments Source: https://s3alfisc.github.io/fwildclusterboot/reference/boot_aggregate.html Detailed explanation of the arguments used in the fwildclusterboot package functions. ```APIDOC ## Arguments ### x An object of type fixest estimated using `sunab()`. ### 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 `"(root)"`, the parentheses must be there and the resulting variable name will be `"root"`. You can add another root with parentheses: `"(root1)regex(root2)"`, in which case the resulting name is `"root1::root2"`. To name the resulting variable differently you can pass a named vector: `c("name" = "pattern")` or `c("name" = "pattern(root2)")`. It's a bit intricate sorry, please see the examples. ### full Logical scalar, defaults to `FALSE`. If `TRUE`, then all coefficients are returned, not only the aggregated coefficients. ### use_weights Logical, default is `TRUE`. If the estimation was weighted, whether the aggregation should take into account the weights. Basically if the weights reflected frequency it should be `TRUE`. ### 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 `clustid` argument, even though that is not necessarily recommended (see the paper by Roodman et al cited below, section 4.2). Other options include "min", where bootstrapping is clustered by the cluster variable with the fewest clusters. Further, the subcluster bootstrap (MacKinnon & Webb, 2018) is supported - see the `vignette("fwildclusterboot", package = "fwildclusterboot")` for details. ### 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 `boottest()` will use each possible combination once (enumeration). ### impose_null Logical. Controls if the null hypothesis is imposed on the bootstrap dgp or not. Null imposed `(WCR)` by default. If FALSE, the null is not imposed `(WCU)`. ### 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 `boot_ssc.type` obtained with the function `boot_ssc()`. Represents how the small sample adjustments are computed. The defaults are `adj = TRUE, fixef.K = "none", cluster.adj = "TRUE", cluster.df = "conventional"`. You can find more details in the help file for `boot_ssc()`. The function is purposefully designed to mimic fixest's `fixest::ssc()` function. ### engine ``` -------------------------------- ### Specify Wild Bootstrap Engine with WildBootTests.jl Source: https://s3alfisc.github.io/fwildclusterboot/news/index.html Use the 'engine' argument to specify the WildBootTests.jl engine for wild bootstrap tests. This requires the WildBootTests.jl package to be installed. ```R boottest( lm_fit, param = ~treatment, clustid = ~group_id1, B = 9999, impose_null = TRUE, engine = "WildBootTests.jl", bootstrap_type = "11" ) ``` -------------------------------- ### boottest() Source: https://s3alfisc.github.io/fwildclusterboot/reference/index.html Performs fast wild cluster bootstrap inference for regression models. ```APIDOC ## boottest() ### Description Fast wild cluster bootstrap inference for regression models. Supports objects of class felm, fixest, and lm. ### Method Function Call ### Parameters - **object** (felm/fixest/lm) - Required - The regression model object to perform inference on. ``` -------------------------------- ### Get Estimated Confidence Interval Source: https://s3alfisc.github.io/fwildclusterboot/articles/wild_bootstrap.html Computes the confidence interval for the coefficients of a linear model fit using estimated standard errors. This serves as a baseline for comparison. ```R confint(fit) ``` -------------------------------- ### Reproducibility and Quiet Execution Source: https://s3alfisc.github.io/fwildclusterboot/reference/mboottest.lm.html Instructions on how to ensure reproducibility by setting random seeds and how to suppress warning and error messages during the execution of boottest. ```APIDOC ## Setting Seeds To guarantee reproducibility, you need to set a global random seed via `set.seed()` ## Run `boottest` quietly You 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`. ``` -------------------------------- ### Specify New Bootstrap Type in R Source: https://s3alfisc.github.io/fwildclusterboot/news/index.html Use the 'bootstrap_type' argument to select new wild cluster bootstrap variants like 'WCR13'. This example uses the 'R' engine. ```R boottest( lm_fit, param = ~treatment, clustid = ~group_id1, B = 9999, impose_null = TRUE, engine = "R", bootstrap_type = "31" ) ``` -------------------------------- ### Obtain Wild Cluster Bootstrapped Confidence Intervals Source: https://s3alfisc.github.io/fwildclusterboot/reference/confint.boottest.html This S3 method is used to obtain wild cluster bootstrapped confidence intervals from a boottest object. Ensure the fwildclusterboot package is installed and loaded. ```R 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) #> [1] 3.709435 ``` -------------------------------- ### Print S3 method for boottest objects Source: https://s3alfisc.github.io/fwildclusterboot/reference/print.boottest.html This S3 method prints key information for objects of type 'bboottest'. It requires the 'fwildclusterboot' package to be loaded. The 'digits' argument controls the rounding of displayed values. ```R print(x, ..., digits = 4) ``` -------------------------------- ### Sanity Check: Create Sample Data Source: https://s3alfisc.github.io/fwildclusterboot/articles/fwildclusterboot.html Generate synthetic data for testing the functionality of fwildclusterboot::boottest(). This function allows customization of sample size, group structures, ICCs, and fixed effects. ```R data <- fwildclusterboot:::create_data( N = 1000, N_G1 = 20, icc1 = 0.81, N_G2 = 10, icc2 = 0.01, numb_fe1 = 10, numb_fe2 = 10, seed = 8769 ) ``` -------------------------------- ### Handling Multiple Fixed Effects Source: https://s3alfisc.github.io/fwildclusterboot/reference/mboottest.fixest.html Explanation of how multiple fixed effects are handled within the `boottest` function. ```APIDOC ## Multiple Fixed Effects 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. ``` -------------------------------- ### Numerical Inversion of p-value Function using Bisection Source: https://s3alfisc.github.io/fwildclusterboot/articles/wild_bootstrap.html Implements a bisection method to find the roots of the function (p_val(r) - alpha), effectively inverting the p-value function to find the confidence interval boundaries. Requires predictor (X), response (y), starting value sets, and significance level (alpha). ```R invert_p_val <- function(X, y, startset1, startset2, alpha){ # p-val - sign_level p_val_x_sign_level <- function(r) { p_val(X = X, y = y, r) - alpha } # bisection for both startset1, startset2 res <- lapply(list(startset1, startset2), function(x){ tmp <- suppressWarnings(stats::uniroot(f = p_val_x_sign_level, lower = min(x), upper = max(x), tol = 1e-08, ``` -------------------------------- ### Load Libraries and Data Source: https://s3alfisc.github.io/fwildclusterboot/articles/Multiple-Estimations-with-fixest.html Loads the necessary fwildclusterboot and fixest libraries, and sets the random seed for reproducibility. Also loads the 'voters' dataset. ```r library(fwildclusterboot) library(fixest) set.seed(34345) dqrng::dqset.seed(123) data(voters) ``` -------------------------------- ### boottest Function Configuration Source: https://s3alfisc.github.io/fwildclusterboot/reference/boottest.felm.html Configuration parameters for the boottest function, controlling the engine, floating point precision, and memory management. ```APIDOC ## boottest Configuration ### Description Configures the algorithm and execution parameters for the cluster bootstrap. ### Parameters - **engine** (character) - Optional - Either "R" or "WildBootTests.jl". Defaults to "R". - **floattype** (string) - Optional - "Float64" or "Float32". Only relevant when engine is "WildBootTests.jl". - **maxmatsize** (numeric) - Optional - Maximum size of auxiliary weight matrix in gigabytes. - **bootstrapc** (logical) - Optional - TRUE to request bootstrap-c instead of bootstrap-t. - **getauxweights** (logical) - Optional - Whether to save the auxiliary weight matrix (v). ``` -------------------------------- ### R S3 Method for Glance on Boottest Objects Source: https://s3alfisc.github.io/fwildclusterboot/reference/glance.boottest.html This S3 method provides a one-row summary of a boottest object, listing characteristics of the input regression model. Ensure the 'fwildclusterboot' package is loaded and a boottest object is created before using. ```R glance(x, ...) ``` ```R 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) ``` -------------------------------- ### Run boottest with split-sample feols objects Source: https://s3alfisc.github.io/fwildclusterboot/news/index.html Execute boottest on feols models created with split-sample formulas. This is useful for analyzing data split into multiple parts. Ensure the parameter and cluster ID are correctly specified. ```R 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")) ``` -------------------------------- ### Run boottest with Default WildBootTests.jl Engine Source: https://s3alfisc.github.io/fwildclusterboot/articles/WildBootTests.html Executes the `boottest` function using the default engine, which has been set to WildBootTests.jl. This call will automatically use the Julia implementation without explicit engine specification. ```R # after setting setBoottest_engine("WildBootTests.jl"), # the code below runs WildBootTests.jl without # specifying 'engine = "WildBootTests.jl"' boottest( lm_fit, clustid = "group_id1", param = "treatment", B = 9999 ) ```