Skip to content

Commit

Permalink
Merge pull request #128 from s3alfisc/dev
Browse files Browse the repository at this point in the history
Version 0.14.1
  • Loading branch information
s3alfisc authored Jul 8, 2023
2 parents add82ae + 728865f commit 56f84f8
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 76 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ S3method(mboottest,lm)
S3method(nobs,boottest)
S3method(nobs,mboottest)
S3method(plot,boottest)
S3method(print,boottest)
S3method(print,mboottest)
S3method(pval,boottest)
S3method(pval,mboottest)
S3method(summary,boottest)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# fwildclusterboot 0.14.1

- brings back the `print()` method, it had a use case after all
- some fixes to the documentation



# fwildclusterboot 0.14

## Breaking Changes
Expand Down
142 changes: 80 additions & 62 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -751,68 +751,86 @@ nobs.mboottest <- function(object, ...) {
}


# S3 method to print key information for objects of type `boottest`
# @param x object of type boottest
# @param ... Further arguments passed to or from other methods.
# @param digits Number of rounding digits
# @export
# @method print boottest
# @return A scalar containing the effective number of observations
# used in `mboottest`
# @examples
# #' 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)
#
# # print.boottest <- function(x, ..., digits = 4) {# stopifnot(inherits(x, "boottest"))## print(x$call)# cat("", "\n")## vals <- lapply(# c("p_val", "conf_int", "t_stat"),# function(y) {# ifelse(is.null(x[[y]]),# 'not computed',# round(x[[y]], digits = digits)# )# }# )## cat("p value:", vals[[1]], "\n")# cat("confidence interval:", vals[[2]], "\n")# cat("test statistic", vals[[3]], "\n")# }

# S3 method to print key information for objects of type `mboottest`
# @param x object of type mboottest
# @param ... Further arguments passed to or from other methods.
# @param digits Number of rounding digits
# @export
# @method print mboottest
# @return A scalar containing the effective number of observations used
# in `mboottest`
# @examples
# \dontrun{
# 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)
# }
#
# print.mboottest <- function(x, ..., digits = 4) {
# stopifnot(inherits(x, "mboottest"))
#
# print(x$call)
# cat("", "\n")
#
# vals <- lapply(
# c("p_val", "teststat"),
# function(y) {
# round(x[[y]], digits = digits)
# }
# )
#
# cat("p value:", vals[[1]], "\n")
# cat("test statistic", vals[[2]], "\n")
# }

#' S3 method to print key information for objects of type `bboottest`
#' @param x object of type boottest
#' @param ... Further arguments passed to or from other methods.
#' @param digits Number of rounding digits
#' @export
#' @method print boottest
#' @return A scalar containing the effective number of observations
#' used in `mboottest`
#' @examples
#' #' 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)
#'
print.boottest <- function(x, ..., digits = 4) {
stopifnot(inherits(x, "boottest"))

print(x$call)
cat("", "\n")

vals <- lapply(
c("p_val", "conf_int", "t_stat"),
function(y) {
round(x[[y]], digits = digits)
}
)

cat("p value:", vals[[1]], "\n")
cat("confidence interval:", vals[[2]], "\n")
cat("test statistic", vals[[3]], "\n")
}


#' S3 method to print key information for objects of type `mboottest`
#' @param x object of type mboottest
#' @param ... Further arguments passed to or from other methods.
#' @param digits Number of rounding digits
#' @export
#' @method print mboottest
#' @return A scalar containing the effective number of observations used
#' in `mboottest`
#' @examples
#' \dontrun{
#' 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)
#' }
#'
print.mboottest <- function(x, ..., digits = 4) {
stopifnot(inherits(x, "mboottest"))

print(x$call)
cat("", "\n")

vals <- lapply(
c("p_val", "teststat"),
function(y) {
round(x[[y]], digits = digits)
}
)

cat("p value:", vals[[1]], "\n")
cat("test statistic", vals[[2]], "\n")
}


tidy.mboottest <- function(x, ...) {
Expand Down
37 changes: 37 additions & 0 deletions man/print.boottest.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions man/print.mboottest.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Note that in a recent update of their working paper, MNW have renamed the new bo

To run all bootstrap types with the null hypothesis imposed on the bootstrap data generating process, you would have to specify the `bootstrap_type` function argument:

```{r setup, warnings = FALSE}
```{r setup, warnings = FALSE, message=FALSE}
library(fwildclusterboot)
library(modelsummary)
options(modelsummary_factory_default = "gt")
Expand Down
38 changes: 31 additions & 7 deletions vignettes/articles/Multiple-Estimations-with-fixest.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data(voters)

## Variables created via 'i()'

```{r}
```{r, warnings = FALSE, message=FALSE}
feols_fit <- feols(proposition_vote ~ i(treatment, ideology1) ,
data = voters
)
Expand All @@ -42,7 +42,7 @@ boot1

It is possible to loop through different regression specifications. For example, to run `boottest()` over a `fixest_multi` object created via the `sw()` function:

```{r, warning = FALSE}
```{r, warnings = FALSE, message=FALSE}
feols_fits <- fixest::feols(
proposition_vote ~ treatment | sw(Q1_immigration, Q2_defense),
data = voters
Expand All @@ -62,7 +62,7 @@ boot2

Similarly, it is possible to loop over objects of `fixest_multi` created by `subset` functionality:

```{r, warning = FALSE}
```{r, warnings = FALSE, message=FALSE}
voters$split <- sample(1:2, nrow(voters), TRUE)
feols_fits <- fixest::feols(
Expand All @@ -86,14 +86,14 @@ boot3

And of course it is also possible to combine multiple "syntactic sugar" features of `fixest`:

```{r, warning = FALSE}
```{r, warnings = FALSE, message=FALSE}
feols_fits <- fixest::feols(
proposition_vote ~ treatment | sw(Q1_immigration, Q2_defense),
split = ~split,
data = voters
)
boot_4 <- lapply(
boot4 <- lapply(
feols_fits,
\(x) boottest(
x,
Expand All @@ -103,14 +103,16 @@ boot_4 <- lapply(
)
)
boot_4
boot4
```

## What currently is not supported

As a rule of thumb, every transformation of fixed effects is not supported. This includes interaction via `^` and varying slopes syntax via `var1[var2]`. If you try this, you should receive an error message, and if not, please open an issue on github =) .

Fixed effect interactions via `^` lead to an error. Fixing this is on my backlog but currently not highest priortiy. Send me a message if this causes you large headaches!

```{r, warning = FALSE, eval = FALSE}
```{r, warnings = FALSE, message=FALSE, eval = FALSE}
feols_fit2 <- feols(proposition_vote ~ treatment | Q1_immigration^Q2_defense,
data = voters
)
Expand All @@ -121,8 +123,30 @@ boot1 <- boottest(feols_fit2,
param = "treatment",
clustid = "group_id1"
)
# Error in `check_boottest_args_plus()` at fwildclusterboot/R/boottest_fixest.R:514:2:
# ! Advanced formula notation in fixest / fixest via ^ to interact
# fixed effects is currently not supported in boottest().
```

Relatedly, varying slopes fixed effects syntax is not supported:

```{r, warnings = FALSE, message=FALSE, eval = FALSE}
feols_fit3 <- feols(proposition_vote ~ treatment | Q1_immigration[log_income],
data = voters
)
# leads to an error
boot <- boottest(feols_fit3,
B = 9999,
param = "treatment",
clustid = "group_id1"
)
# Error in `check_boottest_args_plus()` at fwildclusterboot/R/boottest_fixest.R:514:2:
# ! Varying slopes in fixest / fixest via [] to interact
# fixed effects is currently not supported in boottest().
```


13 changes: 7 additions & 6 deletions vignettes/articles/wild_bootstrap.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,15 @@ While inverting bootstrap tests is computationally more demanding, in the case o

#### Example: How to compute a CI by test inversion

Suppose we have a parameter $\theta \in \Theta$ and a test statistic $T(\theta)$. We also have a critical value $c$ so that to test the null hypothesis $H_0: \theta = \theta_0$ against $H_1: \theta \neq \theta_0$ at a level $\alpha$, we reject the null hypothesis if $T(\theta_0) > c$.
<!-- Suppose we have a parameter $\theta \in \Theta$ and a test statistic $T(\theta)$. We also have a critical value $c$ so that to test the null hypothesis $H_0: \theta = \theta_0$ against $H_1: \theta \neq \theta_0$ at a level $\alpha$, we reject the null hypothesis if $T(\theta_0) > c$. -->

Let's define a set that includes all values of $\theta$ for which the decision rule "reject the null hypothesis if $T(\theta)\geq c$" leads to an acceptance of the null hypothesis:
<!-- Let's define a set that includes all values of $\theta$ for which the decision rule "reject the null hypothesis if $T(\theta)\geq c$" leads to an acceptance of the null hypothesis: -->

$$
C = \{\theta \in \Theta: T(\theta)\leq c \}.
$$
Based on the definition of the p-value, we can alternatively define a confidence interval at significance level $\alpha$ as
<!-- $$ -->
<!-- C = \{\theta \in \Theta: T(\theta)\leq c \}. -->
<!-- $$ -->

Based on the definition of the p-value, we can define a confidence interval at significance level $\alpha$ as

$$
C = \{\theta \in \Theta: p(\theta) \geq \alpha \}.
Expand Down

0 comments on commit 56f84f8

Please sign in to comment.