Skip to content

Commit

Permalink
rename resampling iterations to 'reps' in all methods (#474)
Browse files Browse the repository at this point in the history
* rename resampling iterations to 'reps'

* fix test bug
  • Loading branch information
s3alfisc authored Jun 4, 2024
1 parent ad61e38 commit 37bfe0f
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 40 deletions.
Binary file modified .coverage
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@
],
"source": [
"fit2 = pf.feols(fml=\"Y ~ X1\", data=data, vcov={\"CRV1\": \"group_id\"})\n",
"fit2.wildboottest(param=\"X1\", B=999)"
"fit2.wildboottest(param=\"X1\", reps=999)"
]
},
{
Expand Down Expand Up @@ -1219,7 +1219,7 @@
}
],
"source": [
"pf.rwolf([fit, fit2], param=\"X1\", B=9999, seed=1234).round(3)"
"pf.rwolf([fit, fit2], param=\"X1\", reps=9999, seed=1234).round(3)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/replicating-the-effect.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@
],
"source": [
"fit = pf.feols(fml=\"inspection_score ~ Year + Weekend\", data=df)\n",
"fit.wildboottest(B=999, param=\"Year\")"
"fit.wildboottest(reps=999, param=\"Year\")"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions pyfixest/estimation/FixestMulti_.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def confint(self) -> pd.DataFrame:

def wildboottest(
self,
B: int,
reps: int,
cluster: Optional[str] = None,
param: Optional[str] = None,
weights_type: str = "rademacher",
Expand Down Expand Up @@ -642,7 +642,7 @@ def wildboottest(
fxst = self.all_fitted_models[x]

boot_res = fxst.wildboottest(
B,
reps,
cluster,
param,
weights_type,
Expand Down
4 changes: 2 additions & 2 deletions pyfixest/estimation/estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class for multiple models specified via `fml`.
For example, you can run a wild (cluster) bootstrap via the `wildboottest()` method:
```{python}
fit.wildboottest(param = "X1", B=1000)
fit.wildboottest(param = "X1", reps=1000)
```
would run a wild bootstrap test for the coefficient of `X1` with 1000
bootstrap repetitions.
Expand All @@ -279,7 +279,7 @@ class for multiple models specified via `fml`.
via the `cluster` argument:
```{python}
fit.wildboottest(param = "X1", B=1000, cluster="group_id")
fit.wildboottest(param = "X1", reps=1000, cluster="group_id")
```
The `ritest()` method can be used to conduct randomization inference:
Expand Down
16 changes: 8 additions & 8 deletions pyfixest/estimation/feols_.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ def wald_test(self, R=None, q=None, distribution="F") -> None:

def wildboottest(
self,
B: int,
reps: int,
cluster: Optional[str] = None,
param: Optional[str] = None,
weights_type: Optional[str] = "rademacher",
Expand All @@ -820,7 +820,7 @@ def wildboottest(
Parameters
----------
B : int
reps : int
The number of bootstrap iterations to run.
cluster : Union[str, None], optional
The variable used for clustering. Defaults to None. If None, then
Expand Down Expand Up @@ -953,7 +953,7 @@ def wildboottest(
if run_heteroskedastic:
inference = "HC"

boot = WildboottestHC(X=_X, Y=_Y, R=R, r=r, B=B, seed=seed)
boot = WildboottestHC(X=_X, Y=_Y, R=R, r=r, B=reps, seed=seed)
boot.get_adjustments(bootstrap_type=bootstrap_type)
boot.get_uhat(impose_null=impose_null)
boot.get_tboot(weights_type=weights_type)
Expand All @@ -971,7 +971,7 @@ def wildboottest(
Y=_Y,
cluster=cluster_array,
R=R,
B=B,
B=reps,
seed=seed,
parallel=parallel,
)
Expand Down Expand Up @@ -1536,7 +1536,7 @@ def confint(
exact_match: Optional[bool] = False,
joint: bool = False,
seed: Optional[int] = None,
nboot: int = 10_000,
reps: int = 10_000,
) -> pd.DataFrame:
r"""
Fitted model confidence intervals.
Expand Down Expand Up @@ -1568,7 +1568,7 @@ def confint(
Whether to use exact match for `keep` and `drop`. Default is False.
If True, the pattern will be matched exactly to the coefficient name
instead of using regular expressions.
nboot : int, optional
reps : int, optional
The number of bootstrap iterations to run for joint confidence intervals.
Defaults to 10_000. Only used if `joint` is True.
seed : int, optional
Expand All @@ -1590,7 +1590,7 @@ def confint(
data = get_data()
fit = feols("Y ~ C(f1)", data=data)
fit.confint(alpha=0.10).head()
fit.confint(alpha=0.10, joint=True, nboot=9999).head()
fit.confint(alpha=0.10, joint=True, reps=9999).head()
```
"""
if keep is None:
Expand Down Expand Up @@ -1629,7 +1629,7 @@ def confint(
D_inv = 1 / self._se[joint_indices]
V = self._vcov[np.ix_(joint_indices, joint_indices)]
C_coefs = (D_inv * V).T * D_inv
crit_val = simultaneous_crit_val(C_coefs, nboot, alpha=alpha, seed=seed)
crit_val = simultaneous_crit_val(C_coefs, reps, alpha=alpha, seed=seed)

ub = pd.Series(
self._beta_hat[joint_indices] + crit_val * self._se[joint_indices]
Expand Down
12 changes: 6 additions & 6 deletions pyfixest/estimation/multcomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def bonferroni(models: list[Union[Feols, Fepois]], param: str) -> pd.DataFrame:


def rwolf(
models: list[Union[Feols, Fepois]], param: str, B: int, seed: int
models: list[Union[Feols, Fepois]], param: str, reps: int, seed: int
) -> pd.DataFrame:
"""
Compute Romano-Wolf adjusted p-values for multiple hypothesis testing.
Expand All @@ -81,7 +81,7 @@ def rwolf(
Models of type `Feiv` or `Fepois` are not supported.
param : str
The parameter for which the p-values should be computed.
B : int
reps : int
The number of bootstrap replications.
seed : int
The seed for the random number generator.
Expand All @@ -101,11 +101,11 @@ def rwolf(
data = get_data().dropna()
fit = feols("Y ~ Y2 + X1 + X2", data=data)
rwolf(fit.to_list(), "X1", B=9999, seed=123)
rwolf(fit.to_list(), "X1", reps=9999, seed=123)
fit1 = feols("Y ~ X1", data=data)
fit2 = feols("Y ~ X1 + X2", data=data)
rwolf_df = rwolf([fit1, fit2], "X1", B=9999, seed=123)
rwolf_df = rwolf([fit1, fit2], "X1", reps=9999, seed=123)
rwolf_df
```
"""
Expand All @@ -125,14 +125,14 @@ def rwolf(

t_stats = all_model_stats.xs("t value").values
t_stats = np.zeros(S)
boot_t_stats = np.zeros((B, S))
boot_t_stats = np.zeros((reps, S))

for i in range(S):
model = models[i]

wildboot_res_df, bootstrapped_t_stats = model.wildboottest(
param=param,
B=B,
reps=reps,
return_bootstrapped_t_stats=True,
seed=seed, # all S iterations require the same bootstrap samples, hence seed needs to be reset
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_confint.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ def test_against_doubleml():
m = feols(
f"y ~ -1 + {'+'.join(['X_'+str(x) for x in range(n_vars)])}", df, vcov="hetero"
)
pyfixest_res = m.confint(keep="X_.$", nboot=10_000, joint=True)
pyfixest_res = m.confint(keep="X_.$", reps=10_000, joint=True)

assert np.all(np.abs(dml_res.values - pyfixest_res.values) < 1e-2)
10 changes: 5 additions & 5 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_iv_errors():
feols(fml="Y ~ 1 | Z1 ~ X1 ", vcov={"CRV3": "group_id"}, data=data)
# wild bootstrap
with pytest.raises(NotImplementedError):
feols(fml="Y ~ 1 | Z1 ~ X1 ", data=data).wildboottest(param="Z1", B=999)
feols(fml="Y ~ 1 | Z1 ~ X1 ", data=data).wildboottest(param="Z1", reps=999)
# multi estimation error
with pytest.raises(MultiEstNotSupportedError):
feols(fml="Y + Y2 ~ 1 | Z1 ~ X1 ", data=data)
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_wls_errors():
data.loc[0, "weights"] = np.nan
with pytest.raises(NotImplementedError):
feols("Y ~ X1", data=data, weights="weights").wildboottest(
cluster="f1", param="X1", B=999, seed=12
cluster="f1", param="X1", reps=999, seed=12
)

# test for ValueError when weights are not positive
Expand All @@ -175,7 +175,7 @@ def test_wls_errors():

data = get_data()
with pytest.raises(NotImplementedError):
feols("Y ~ X1", data=data, weights="weights", vcov="iid").wildboottest(B=999)
feols("Y ~ X1", data=data, weights="weights", vcov="iid").wildboottest(reps=999)


def test_multcomp_errors():
Expand All @@ -184,14 +184,14 @@ def test_multcomp_errors():
# param not in model
fit1 = feols("Y + Y2 ~ X1 | f1", data=data)
with pytest.raises(ValueError):
rwolf(fit1.to_list(), param="X2", B=999, seed=92)
rwolf(fit1.to_list(), param="X2", reps=999, seed=92)


def test_wildboottest_errors():
data = get_data()
fit = feols("Y ~ X1", data=data)
with pytest.raises(ValueError):
fit.wildboottest(param="X2", B=999, seed=213)
fit.wildboottest(param="X2", reps=999, seed=213)


def test_summary_errors():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_multcomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_wildrwolf():
fit2 = feols("Y2 ~ X1", data=data)
fit3 = feols("Y3 ~ X1", data=data)

rwolf_py = rwolf([fit1, fit2, fit3], "X1", B=9999, seed=12345)
rwolf_py = rwolf([fit1, fit2, fit3], "X1", reps=9999, seed=12345)

# R
fit_r = fixest.feols(ro.Formula("c(Y, Y2, Y3) ~ X1"), data=data)
Expand All @@ -81,7 +81,7 @@ def test_wildrwolf():
fit2 = feols("Y2 ~ X1 | f1 + f2", data=data)
fit3 = feols("Y3 ~ X1 | f1 + f2", data=data)

rwolf_py = rwolf([fit1, fit2, fit3], "X1", B=9999, seed=12345)
rwolf_py = rwolf([fit1, fit2, fit3], "X1", reps=9999, seed=12345)

# R
fit_r = fixest.feols(ro.Formula("c(Y, Y2, Y3) ~ X1 | f1 + f2"), data=data)
Expand Down
22 changes: 11 additions & 11 deletions tests/test_wildboottest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,39 @@ def data():
def test_hc_equivalence(data):
fixest = feols(fml="Y~X2", data=data, ssc=ssc(adj=False, cluster_adj=False))
tstat = fixest.tstat()
boot_tstat = fixest.wildboottest(param="X2", B=999, adj=False, cluster_adj=False)[
"t value"
]
boot_tstat = fixest.wildboottest(
param="X2", reps=999, adj=False, cluster_adj=False
)["t value"]

np.allclose(tstat, boot_tstat)

fixest = feols(fml="Y ~ X1 + X2 | f1 + f2", data=data, vcov="hetero")
tstat = fixest.tstat()
boot_tstat = fixest.wildboottest(param="X1", B=999, adj=False, cluster_adj=False)[
"t value"
]
boot_tstat = fixest.wildboottest(
param="X1", reps=999, adj=False, cluster_adj=False
)["t value"]

np.allclose(tstat, boot_tstat)


def test_crv1_equivalence(data):
fixest = feols(fml="Y~X1", data=data, vcov={"CRV1": "group_id"})
tstat = fixest.tstat()
boot_tstat = fixest.wildboottest(param="X1", B=999)["t value"]
boot_tstat = fixest.wildboottest(param="X1", reps=999)["t value"]

np.allclose(tstat, boot_tstat)

fixest = feols(fml="Y ~ X1 + X2 | f1 + f2", data=data)
tstat = fixest.tstat()
boot_tstat = fixest.wildboottest(param="X1", B=999, adj=False, cluster_adj=False)[
"t value"
]
boot_tstat = fixest.wildboottest(
param="X1", reps=999, adj=False, cluster_adj=False
)["t value"]

np.allclose(tstat, boot_tstat)

fixest = feols(fml="Y ~ X1 | f1", vcov="hetero", data=data)
boot_tstat = fixest.wildboottest(
param="X1", cluster="f1", B=999, adj=False, cluster_adj=False
param="X1", cluster="f1", reps=999, adj=False, cluster_adj=False
)["t value"]
tstat = fixest.vcov("hetero").tstat()

Expand Down

0 comments on commit 37bfe0f

Please sign in to comment.