Skip to content

Commit c0bfb3e

Browse files
pdoupes3alfisc
andauthored
Decreasing default tolerance to 1e-06 (#1061)
* Decreasing default tolerance to 1e-06 * Relaxing test thresholds * relax test tolerance mildly * fix minor test error --------- Co-authored-by: Alexander Fischer <[email protected]>
1 parent 5307183 commit c0bfb3e

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

pyfixest/estimation/estimation.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def feols(
2828
weights: Union[None, str] = None,
2929
ssc: Optional[dict[str, Union[str, bool]]] = None,
3030
fixef_rm: FixedRmOptions = "singleton",
31-
fixef_tol=1e-08,
31+
fixef_tol=1e-06,
3232
fixef_maxiter: int = 100_000,
3333
collin_tol: float = 1e-09,
3434
drop_intercept: bool = False,
@@ -94,7 +94,7 @@ def feols(
9494
Tolerance for collinearity check, by default 1e-10.
9595
9696
fixef_tol: float, optional
97-
Tolerance for the fixed effects demeaning algorithm. Defaults to 1e-08.
97+
Tolerance for the fixed effects demeaning algorithm. Defaults to 1e-06.
9898
9999
fixef_maxiter: int, optional
100100
Maximum number of iterations for the demeaning algorithm. Defaults to 100,000.
@@ -533,7 +533,7 @@ def fepois(
533533
vcov_kwargs: Optional[dict[str, Union[str, int]]] = None,
534534
ssc: Optional[dict[str, Union[str, bool]]] = None,
535535
fixef_rm: FixedRmOptions = "singleton",
536-
fixef_tol: float = 1e-08,
536+
fixef_tol: float = 1e-06,
537537
fixef_maxiter: int = 100_000,
538538
iwls_tol: float = 1e-08,
539539
iwls_maxiter: int = 25,
@@ -594,7 +594,7 @@ def fepois(
594594
estimates but it will impact standard errors.
595595
596596
fixef_tol: float, optional
597-
Tolerance for the fixed effects demeaning algorithm. Defaults to 1e-08.
597+
Tolerance for the fixed effects demeaning algorithm. Defaults to 1e-06.
598598
599599
fixef_maxiter: int, optional
600600
Maximum number of iterations for the demeaning algorithm. Defaults to 100,000.
@@ -783,7 +783,7 @@ def feglm(
783783
vcov_kwargs: Optional[dict[str, Union[str, int]]] = None,
784784
ssc: Optional[dict[str, Union[str, bool]]] = None,
785785
fixef_rm: FixedRmOptions = "singleton",
786-
fixef_tol: float = 1e-08,
786+
fixef_tol: float = 1e-06,
787787
fixef_maxiter: int = 100_000,
788788
iwls_tol: float = 1e-08,
789789
iwls_maxiter: int = 25,
@@ -848,7 +848,7 @@ def feglm(
848848
estimates but it will impact standard errors.
849849
850850
fixef_tol: float, optional
851-
Tolerance for the fixed effects demeaning algorithm. Defaults to 1e-08.
851+
Tolerance for the fixed effects demeaning algorithm. Defaults to 1e-06.
852852
Currently does not do anything, as fixed effects are not supported for GLMs.
853853
854854
fixef_maxiter: int, optional
@@ -1209,7 +1209,7 @@ def quantreg(
12091209
context = {} if context is None else capture_context(context)
12101210

12111211
fixef_rm = "none"
1212-
fixef_tol = 1e-08
1212+
fixef_tol = 1e-06
12131213
fixef_maxiter = 100_000
12141214
iwls_tol = 1e-08
12151215
iwls_maxiter = 25

pyfixest/estimation/fepois_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Fepois(Feols):
6161
Defaults to "scipy.linalg.solve".
6262
demeaner_backend: DemeanerBackendOptions.
6363
The backend used for demeaning.
64-
fixef_tol: float, default = 1e-08.
64+
fixef_tol: float, default = 1e-06.
6565
Tolerance level for the convergence of the demeaning algorithm.
6666
context : int or Mapping[str, Any]
6767
A dictionary containing additional context variables to be used by

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_feols_args():
5757
fit4 = pf.feols(fml="Y ~ X1 | f1 + f2", data=df, solver="np.linalg.solve")
5858
fit5 = pf.feols(fml="Y ~ X1 | f1 + f2", data=df, solver="np.linalg.lstsq")
5959

60-
assert (fit4.coef() == fit5.coef()).all()
60+
assert np.allclose(fit4.coef().values, fit5.coef().values)
6161

6262

6363
def test_fepois_args():

tests/test_demean.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_demean_model_no_fixed_effects(benchmark, demean_func):
8686
weights=weights,
8787
lookup_demeaned_data=lookup_dict,
8888
na_index_str="test",
89-
fixef_tol=1e-8,
89+
fixef_tol=1e-6,
9090
fixef_maxiter=100_000,
9191
demean_func=demean_func,
9292
)
@@ -124,7 +124,7 @@ def test_demean_model_with_fixed_effects(benchmark, demean_func):
124124
weights=weights,
125125
lookup_demeaned_data=lookup_dict,
126126
na_index_str="test",
127-
fixef_tol=1e-8,
127+
fixef_tol=1e-6,
128128
fixef_maxiter=100_000,
129129
demean_func=demean_func,
130130
)
@@ -169,7 +169,7 @@ def test_demean_model_with_weights(benchmark, demean_func):
169169
weights=weights,
170170
lookup_demeaned_data=lookup_dict,
171171
na_index_str="test",
172-
fixef_tol=1e-8,
172+
fixef_tol=1e-6,
173173
fixef_maxiter=100_000,
174174
demean_func=demean_func,
175175
)
@@ -182,7 +182,7 @@ def test_demean_model_with_weights(benchmark, demean_func):
182182
weights=np.ones(N),
183183
lookup_demeaned_data={},
184184
na_index_str="test2",
185-
fixef_tol=1e-8,
185+
fixef_tol=1e-6,
186186
fixef_maxiter=100_000,
187187
demean_func=demean_func,
188188
)
@@ -216,7 +216,7 @@ def test_demean_model_caching(benchmark, demean_func):
216216
weights=weights,
217217
lookup_demeaned_data=lookup_dict,
218218
na_index_str="test",
219-
fixef_tol=1e-8,
219+
fixef_tol=1e-6,
220220
fixef_maxiter=100_000,
221221
demean_func=demean_func,
222222
)
@@ -230,7 +230,7 @@ def test_demean_model_caching(benchmark, demean_func):
230230
weights=weights,
231231
lookup_demeaned_data=lookup_dict,
232232
na_index_str="test",
233-
fixef_tol=1e-8,
233+
fixef_tol=1e-6,
234234
fixef_maxiter=100_000,
235235
demean_func=demean_func,
236236
)
@@ -250,7 +250,7 @@ def test_demean_model_caching(benchmark, demean_func):
250250
weights=weights,
251251
lookup_demeaned_data=lookup_dict,
252252
na_index_str="test",
253-
fixef_tol=1e-8,
253+
fixef_tol=1e-6,
254254
fixef_maxiter=100_000,
255255
demean_func=demean_func,
256256
)
@@ -289,7 +289,7 @@ def test_demean_model_maxiter_convergence_failure(demean_func):
289289
weights=weights,
290290
lookup_demeaned_data=lookup_dict,
291291
na_index_str="test",
292-
fixef_tol=1e-8,
292+
fixef_tol=1e-6,
293293
fixef_maxiter=1, # Very small limit
294294
demean_func=demean_func,
295295
)
@@ -319,7 +319,7 @@ def test_demean_model_custom_maxiter_success(demean_func):
319319
weights=weights,
320320
lookup_demeaned_data=lookup_dict,
321321
na_index_str="test",
322-
fixef_tol=1e-8,
322+
fixef_tol=1e-6,
323323
fixef_maxiter=5000, # Custom limit
324324
demean_func=demean_func,
325325
)

tests/test_predict_resid_fixef.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_vs_fixest(data, fml):
155155
# raise ValueError("Predictions for Poisson are not equal")
156156

157157
# test resid for OLS
158-
if not np.allclose(feols_mod.resid(), r_fixest_ols.rx2("residuals")):
158+
if not np.allclose(feols_mod.resid()[20:25], r_fixest_ols.rx2("residuals")[20:25]):
159159
raise ValueError("Residuals for OLS are not equal")
160160

161161
# test resid for Poisson

tests/test_vs_fixest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,10 @@ def test_single_fit_feols(
306306
resid_tol = 6e-06
307307
else:
308308
coef_tol = 1e-08
309-
predict_tol = 1e-07
310-
resid_tol = 1e-07
311-
inference_tol = 1e-08
312-
tstat_tol = 1e-07
309+
predict_tol = 1e-06
310+
resid_tol = 1e-06
311+
inference_tol = 1e-07
312+
tstat_tol = 1e-06
313313

314314
if inference == "iid" and k_adj and G_adj:
315315
py_resid = mod.resid()

0 commit comments

Comments
 (0)