|
118 | 118 | "Y2 ~ X2| f2 | X1 ~ Z1 + Z2", |
119 | 119 | ] |
120 | 120 |
|
| 121 | +gml_fmls = [ |
| 122 | + "Y ~ X1 + X2", |
| 123 | + "Y ~ X1*X2", |
| 124 | + # "Y ~ X1 + C(f2)", |
| 125 | + # "Y ~ X1 + i(f1, ref = 1)", |
| 126 | + "Y ~ X1:X2", |
| 127 | +] |
| 128 | + |
121 | 129 |
|
122 | 130 | @pytest.fixture |
123 | 131 | def data_feols(N=1000, seed=76540251, beta_type="2", error_type="2"): |
@@ -584,6 +592,39 @@ def test_single_fit_iv( |
584 | 592 | check_absolute_diff(py_confint, r_confint, 1e-06, "py_confint != r_confint") |
585 | 593 |
|
586 | 594 |
|
| 595 | +@pytest.mark.slow |
| 596 | +@pytest.mark.parametrize("N", [1000]) |
| 597 | +@pytest.mark.parametrize("seed", [170]) |
| 598 | +@pytest.mark.parametrize("dropna", [True, False]) |
| 599 | +@pytest.mark.parametrize("fml", gml_fmls) |
| 600 | +def test_glm_vs_fixest(N, seed, dropna, fml): |
| 601 | + data = pf.get_data(N=N, seed=seed) |
| 602 | + data["Y"] = np.where(data["Y"] > 0, 1, 0) |
| 603 | + if dropna: |
| 604 | + data = data.dropna() |
| 605 | + |
| 606 | + fit_logit = pf.feglm(fml=fml, data=data, family="logit") |
| 607 | + # fit_probit = pf.feglm(fml = fml, data=data, family="probit") |
| 608 | + |
| 609 | + r_fml = _py_fml_to_r_fml(fml) |
| 610 | + data_r = get_data_r(fml, data) |
| 611 | + |
| 612 | + fit_logit_r = fixest.feglm( |
| 613 | + ro.Formula(r_fml), data=data_r, family=stats.binomial(link="logit") |
| 614 | + ) |
| 615 | + # fit_probit_r = fixest.feglm(ro.Formula(r_fml), data=data_r, family=stats.binomial(link="probit")) |
| 616 | + |
| 617 | + py_logit_coefs = fit_logit.coef() |
| 618 | + # py_probit_coefs = fit_probit.coef() |
| 619 | + r_logit_coefs = stats.coef(fit_logit_r) |
| 620 | + # r_probit_coefs = stats.coef(fit_probit_r) |
| 621 | + |
| 622 | + check_absolute_diff( |
| 623 | + py_logit_coefs, r_logit_coefs, 1e-08, "py_logit_coefs != r_logit_coefs" |
| 624 | + ) |
| 625 | + # check_absolute_diff(py_probit_coefs, r_probit_coefs, 1e-08, "py_probit_coefs != r_probit_coefs") |
| 626 | + |
| 627 | + |
587 | 628 | @pytest.mark.slow |
588 | 629 | @pytest.mark.parametrize("N", [100]) |
589 | 630 | @pytest.mark.parametrize("seed", [17021]) |
|
0 commit comments