logit-stream 0.3.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {logit_stream-0.3.0 → logit_stream-0.4.0}/CHANGELOG.md +50 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/CITATION.cff +2 -2
- {logit_stream-0.3.0 → logit_stream-0.4.0}/PKG-INFO +4 -7
- {logit_stream-0.3.0 → logit_stream-0.4.0}/README.md +2 -5
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/__init__.py +5 -2
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/_frontend.py +9 -10
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/api.py +85 -12
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/estimator.py +217 -14
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/fe.py +197 -11
- logit_stream-0.4.0/logit_stream/fe_kernels.py +726 -0
- logit_stream-0.4.0/logit_stream/meat_kernels.py +629 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/models.py +718 -6
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/newton.py +20 -4
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/results.py +167 -1
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/store.py +70 -5
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream.egg-info/PKG-INFO +4 -7
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream.egg-info/SOURCES.txt +6 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream.egg-info/requires.txt +1 -1
- {logit_stream-0.3.0 → logit_stream-0.4.0}/pyproject.toml +3 -3
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_api.py +5 -2
- logit_stream-0.4.0/tests/test_binary_logit.py +197 -0
- logit_stream-0.4.0/tests/test_fe_kernels.py +290 -0
- logit_stream-0.4.0/tests/test_kernels.py +295 -0
- logit_stream-0.4.0/tests/test_meat_kernels.py +189 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_multinomial.py +4 -2
- logit_stream-0.4.0/tests/test_own_covariates.py +190 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_profile.py +4 -2
- logit_stream-0.3.0/tests/test_kernels.py +0 -105
- {logit_stream-0.3.0 → logit_stream-0.4.0}/LICENSE.md +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/MANIFEST.in +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/_choice.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/_limits.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/device/__init__.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/device/_common.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/device/fe.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/device/meat.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/device/mixed.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/device/models.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/device/nested.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/device/random_effects.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/device/store.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/mixed.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/multi_fe.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/nested.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/optimize.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/profile.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/py.typed +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/random_effects/__init__.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/random_effects/fit.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/random_effects/linalg.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/random_effects/model.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/random_effects/sigma.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream/simulate.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream.egg-info/dependency_links.txt +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/logit_stream.egg-info/top_level.txt +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/setup.cfg +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_cfelogit.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_clustering.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_conditional.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_device.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_firth_and_fit.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_fixed_effects.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_headroom.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_index_dtype.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_mixed.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_multi_fe.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_nested.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_offset_start.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_ordered.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_probit.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_random.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_resources.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_simulate.py +0 -0
- {logit_stream-0.3.0 → logit_stream-0.4.0}/tests/test_weights_scale.py +0 -0
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
New
|
|
6
|
+
- **`mlogit_stream(own_covariates=...)`: covariates that enter only their own level's equation.**
|
|
7
|
+
For example, each group's baseline share can predict that group alone, leaving out the other
|
|
8
|
+
groups' shares. This drops the off-diagonal coefficients, which are often poorly determined
|
|
9
|
+
where the groups are segregated, and fits fewer parameters.
|
|
10
|
+
- **`logit_stream` and `probit_stream` have their own engine** for no fixed effect or one, about
|
|
11
|
+
2 times faster than hdfe-stream's. They fit the two-level ordered logit or probit with this
|
|
12
|
+
package's Newton iterations and return a `BinaryLogitResult` or `BinaryProbitResult` (new
|
|
13
|
+
classes; `predict(type="class")` is new). Estimates are at the maximum to machine precision
|
|
14
|
+
(Newton's decrement judges convergence; `iwls_tol` and `iwls_maxiter` still work). Coefficients,
|
|
15
|
+
variances, degrees of freedom, fit statistics, `fixef`, `predict`, `resid` and `sample` agree
|
|
16
|
+
with `feglm_stream`'s; the probit's variances use the expected information, as its iteratively
|
|
17
|
+
reweighted fit does. Several fixed effects, `bias_correction=True`, `bootcluster=`, CRV3,
|
|
18
|
+
`separation_check=False` and `profile=True` still run `feglm_stream` and return its
|
|
19
|
+
`HDFEResult`.
|
|
20
|
+
|
|
21
|
+
Faster (estimates unchanged)
|
|
22
|
+
- **Multinomial logit** without fixed effects: about 5 times on dense designs, 1.3-1.8 times on
|
|
23
|
+
designs of indicators. **Ordered logit and probit** without fixed effects: about 4 times. Each
|
|
24
|
+
pass over the data is now one fused parallel kernel.
|
|
25
|
+
- **Multinomial and ordered logit with an absorbed fixed effect:** 2-4 times. The first pass
|
|
26
|
+
writes the rows grouped by the fixed effect, so each thread owns whole groups. Fixed effects
|
|
27
|
+
with many small groups are a further 1.5-2 times faster, and the ordered logit and probit no
|
|
28
|
+
longer slow down with many groups (100,000 groups: 47 s, now 2 s).
|
|
29
|
+
- **Robust and clustered variances:** 3-18 times faster for the multinomial and ordered logit, and
|
|
30
|
+
2.5-7 times for the conditional logit and `cfelogit_stream`, from a fused kernel that forms each
|
|
31
|
+
score in a thread.
|
|
32
|
+
- `fit.diagnostics["information"]` says how the information matrix was formed.
|
|
33
|
+
|
|
34
|
+
Fixed
|
|
35
|
+
- Cluster counts `G` and degrees of freedom count only clusters with rows used, and analytic
|
|
36
|
+
weights are rescaled over the rows used after a fixed effect's separation drops some, in the
|
|
37
|
+
binary, multinomial and ordered logit, as hdfe-stream does. Before, the multinomial and ordered
|
|
38
|
+
logit counted clusters whose rows were all dropped (variances slightly small) and scaled the
|
|
39
|
+
weights over all rows read (iid variance and log-likelihoods).
|
|
40
|
+
- Sorting rows by a fixed effect respects `max_memory_gb`: rows not already grouped are
|
|
41
|
+
partitioned in memory to sort them, and when that would not fit they stay in their order and the
|
|
42
|
+
passes are slower.
|
|
43
|
+
- `resid()` of a result fitted with an offset works.
|
|
44
|
+
- The within pseudo R-squared is nan for an ordered or multinomial fit with an offset and an
|
|
45
|
+
absorbed fixed effect (the fixed-effect-only log-likelihood it came from ignored the offset).
|
|
46
|
+
|
|
47
|
+
## 0.3.1
|
|
48
|
+
|
|
49
|
+
- **Works with pyfixest 0.60 and 0.70.** Formulas are read through hdfe-stream's own formula
|
|
50
|
+
parser, so either pyfixest version can be installed.
|
|
51
|
+
- Requires hdfe-stream 0.10.0 or later.
|
|
52
|
+
|
|
3
53
|
## 0.3.0
|
|
4
54
|
|
|
5
55
|
- **The conditional logit is 2.3-2.8 times faster.** Its log-likelihood, gradient and information
|
|
@@ -7,8 +7,8 @@ authors:
|
|
|
7
7
|
- family-names: Tucker
|
|
8
8
|
given-names: Lee
|
|
9
9
|
email: lee.c.tucker@census.gov
|
|
10
|
-
version: 0.
|
|
11
|
-
date-released: 2026-11-
|
|
10
|
+
version: 0.4.0
|
|
11
|
+
date-released: 2026-11-11
|
|
12
12
|
license: MIT
|
|
13
13
|
repository-code: "https://github.com/leetucker/logit-stream"
|
|
14
14
|
url: "https://github.com/leetucker/logit-stream"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: logit-stream
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Out-of-core logit models by streamed Newton: binary, multinomial, ordered and conditional logit, with absorbed fixed effects
|
|
5
5
|
Author: Lee Tucker
|
|
6
6
|
License-Expression: MIT
|
|
@@ -25,7 +25,7 @@ Classifier: Typing :: Typed
|
|
|
25
25
|
Requires-Python: >=3.10
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
License-File: LICENSE.md
|
|
28
|
-
Requires-Dist: hdfe-stream[formula]>=0.
|
|
28
|
+
Requires-Dist: hdfe-stream[formula]>=0.10.0
|
|
29
29
|
Requires-Dist: stream-limits>=0.1.1
|
|
30
30
|
Requires-Dist: polars!=1.41.*,>=1.37
|
|
31
31
|
Requires-Dist: numpy>=1.24
|
|
@@ -77,7 +77,7 @@ fit.predict("people/*.parquet").sink_parquet("imputed.parquet") # lazily
|
|
|
77
77
|
|
|
78
78
|
| | |
|
|
79
79
|
|---|---|
|
|
80
|
-
| `logit_stream`, `probit_stream` | binary logit and probit with any number of fixed effects ([hdfe-stream](https://github.com/leetucker/hdfe-stream)'s `feglm_stream`) |
|
|
80
|
+
| `logit_stream`, `probit_stream` | binary logit and probit with any number of fixed effects (with at most one through this package's own engine, otherwise [hdfe-stream](https://github.com/leetucker/hdfe-stream)'s `feglm_stream`) |
|
|
81
81
|
| `mlogit_stream` | multinomial logit (any number of fixed effects; several through a Poisson regression) |
|
|
82
82
|
| `ologit_stream`, `oprobit_stream` | ordered logit and probit |
|
|
83
83
|
| `clogit_stream` | conditional (McFadden) logit on long-format choice data |
|
|
@@ -109,10 +109,7 @@ data.
|
|
|
109
109
|
pip install logit-stream
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
Python 3.10 or later.
|
|
113
|
-
formula extra brings in) has no wheels yet: it builds from source with a Rust
|
|
114
|
-
toolchain and `PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1` set; everything else
|
|
115
|
-
installs from wheels.
|
|
112
|
+
Python 3.10 or later.
|
|
116
113
|
|
|
117
114
|
## Benchmarks
|
|
118
115
|
|
|
@@ -20,7 +20,7 @@ fit.predict("people/*.parquet").sink_parquet("imputed.parquet") # lazily
|
|
|
20
20
|
|
|
21
21
|
| | |
|
|
22
22
|
|---|---|
|
|
23
|
-
| `logit_stream`, `probit_stream` | binary logit and probit with any number of fixed effects ([hdfe-stream](https://github.com/leetucker/hdfe-stream)'s `feglm_stream`) |
|
|
23
|
+
| `logit_stream`, `probit_stream` | binary logit and probit with any number of fixed effects (with at most one through this package's own engine, otherwise [hdfe-stream](https://github.com/leetucker/hdfe-stream)'s `feglm_stream`) |
|
|
24
24
|
| `mlogit_stream` | multinomial logit (any number of fixed effects; several through a Poisson regression) |
|
|
25
25
|
| `ologit_stream`, `oprobit_stream` | ordered logit and probit |
|
|
26
26
|
| `clogit_stream` | conditional (McFadden) logit on long-format choice data |
|
|
@@ -52,10 +52,7 @@ data.
|
|
|
52
52
|
pip install logit-stream
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
Python 3.10 or later.
|
|
56
|
-
formula extra brings in) has no wheels yet: it builds from source with a Rust
|
|
57
|
-
toolchain and `PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1` set; everything else
|
|
58
|
-
installs from wheels.
|
|
55
|
+
Python 3.10 or later.
|
|
59
56
|
|
|
60
57
|
## Benchmarks
|
|
61
58
|
|
|
@@ -45,6 +45,8 @@ from .api import (
|
|
|
45
45
|
probit_stream,
|
|
46
46
|
)
|
|
47
47
|
from .results import (
|
|
48
|
+
BinaryLogitResult,
|
|
49
|
+
BinaryProbitResult,
|
|
48
50
|
ConditionalFELogitResult,
|
|
49
51
|
ConditionalLogitResult,
|
|
50
52
|
LogitMulti,
|
|
@@ -62,7 +64,7 @@ def _version():
|
|
|
62
64
|
from importlib.metadata import version
|
|
63
65
|
return version("logit-stream")
|
|
64
66
|
except Exception: # noqa: BLE001 -- not installed
|
|
65
|
-
return "0.
|
|
67
|
+
return "0.4.0"
|
|
66
68
|
|
|
67
69
|
|
|
68
70
|
__version__ = _version()
|
|
@@ -70,7 +72,8 @@ __version__ = _version()
|
|
|
70
72
|
__all__ = [
|
|
71
73
|
"logit_stream", "probit_stream", "mlogit_stream", "ologit_stream", "oprobit_stream",
|
|
72
74
|
"clogit_stream", "cfelogit_stream", "mixlogit_stream", "nlogit_stream",
|
|
73
|
-
"LogitResult", "
|
|
75
|
+
"LogitResult", "BinaryLogitResult", "BinaryProbitResult", "MultinomialLogitResult",
|
|
76
|
+
"OrderedLogitResult", "OrderedProbitResult",
|
|
74
77
|
"ConditionalLogitResult", "ConditionalFELogitResult",
|
|
75
78
|
"MixedLogitResult", "NestedLogitResult",
|
|
76
79
|
"LogitMulti", "etable", "bonferroni", "holm", "__version__",
|
|
@@ -19,7 +19,7 @@ from hdfe_stream.core.formula import (
|
|
|
19
19
|
categorical_vars,
|
|
20
20
|
compile_design,
|
|
21
21
|
numeric_expr,
|
|
22
|
-
|
|
22
|
+
parse_formula,
|
|
23
23
|
)
|
|
24
24
|
|
|
25
25
|
|
|
@@ -52,27 +52,26 @@ def _plan(fml: str, lf: pl.LazyFrame, intercept: bool, collect) -> list[_Spec]:
|
|
|
52
52
|
categorical coding is still reduced rank, as with it.
|
|
53
53
|
`collect(lf, what)` runs a query (so that the GPU engine applies).
|
|
54
54
|
"""
|
|
55
|
-
Formula, _ = pyfixest_formula_api()
|
|
56
55
|
schema = lf.collect_schema()
|
|
57
|
-
specs =
|
|
56
|
+
specs = parse_formula(fml)
|
|
58
57
|
cats = set()
|
|
59
58
|
for s in specs:
|
|
60
|
-
if s.
|
|
61
|
-
raise ValueError(f"{s.
|
|
62
|
-
cats |= categorical_vars(s.
|
|
59
|
+
if s.iv is not None:
|
|
60
|
+
raise ValueError(f"{s.key}: IV formulas are not available for logit models")
|
|
61
|
+
cats |= categorical_vars(s.rhs, schema)
|
|
63
62
|
levels = {}
|
|
64
63
|
for v in sorted(cats):
|
|
65
64
|
u = collect(lf.select(pl.col(v).drop_nulls().unique().sort()), f"levels of {v}")
|
|
66
65
|
levels[v] = u[v].to_list()
|
|
67
66
|
out = []
|
|
68
67
|
for s in specs:
|
|
69
|
-
dep, rhs =
|
|
70
|
-
fe = tuple(parse_fe(s.
|
|
68
|
+
dep, rhs = s.dep, s.rhs
|
|
69
|
+
fe = tuple(parse_fe(s.fe))
|
|
71
70
|
for d in fe:
|
|
72
71
|
if "[" in d:
|
|
73
|
-
raise ValueError(f"{s.
|
|
72
|
+
raise ValueError(f"{s.key}: varying slopes are not available for logit models")
|
|
74
73
|
_, cols = compile_design(dep, rhs, schema, levels, intercept=intercept and not fe)
|
|
75
74
|
if not intercept:
|
|
76
75
|
cols = [(nm, ex) for nm, ex in cols if nm != "Intercept"]
|
|
77
|
-
out.append(_Spec(fml=s.
|
|
76
|
+
out.append(_Spec(fml=s.key, depvar=dep, y=_outcome_expr(dep, schema), x=cols, fe=fe))
|
|
78
77
|
return out
|
|
@@ -184,18 +184,80 @@ def logit_stream(fml: str, data: Source, workdir: PathLike | None = None,
|
|
|
184
184
|
|
|
185
185
|
Notes
|
|
186
186
|
-----
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
With no fixed effect or one, and none of hdfe-stream's options that have
|
|
188
|
+
no counterpart here (``bias_correction``, ``bootcluster``, a CRV3
|
|
189
|
+
variance, the separation check switched off, ...), the fit is this
|
|
190
|
+
package's: the two-level ordered logit's Newton iterations over the
|
|
191
|
+
stored blocks (see `ologit_stream`), reported as a `BinaryLogitResult`
|
|
192
|
+
with hdfe-stream's conventions for the variance (the iid vcov has the
|
|
193
|
+
factor (N - 1) / (N - K)) and for the coefficients (``Intercept`` first).
|
|
194
|
+
It converges on the Newton decrement (``iwls_tol``, if given, is that
|
|
195
|
+
tolerance; default 1e-8), so the estimates are at the maximum to machine
|
|
196
|
+
precision. Otherwise the fit is hdfe-stream's, `feglm_stream`, whose
|
|
197
|
+
convergence is judged on the relative change in deviance.
|
|
190
198
|
A two-level `mlogit_stream` fits the same model, with this package's
|
|
191
|
-
conventions
|
|
192
|
-
|
|
199
|
+
conventions for the variance; it is also the way to Firth's penalized
|
|
200
|
+
likelihood for a binary outcome (``firth=True``).
|
|
193
201
|
"""
|
|
202
|
+
return _binary_fit("logit", fml, data, workdir, vcov, cluster, options)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def _binary_fit(family, fml, data, workdir, vcov, cluster, options):
|
|
206
|
+
"""A binary logit or probit: this package's fit where it can, else
|
|
207
|
+
hdfe-stream's `feglm_stream`."""
|
|
208
|
+
route = _binary_route(vcov, cluster, options)
|
|
209
|
+
if route is not None:
|
|
210
|
+
from .estimator import _fit, _NeedsHdfe
|
|
211
|
+
try:
|
|
212
|
+
return _fit("ologit", fml, data, workdir=workdir, vcov=vcov, cluster=cluster,
|
|
213
|
+
_binary=True, link=family, **route)
|
|
214
|
+
except _NeedsHdfe:
|
|
215
|
+
pass
|
|
194
216
|
from hdfe_stream import feglm_stream
|
|
195
|
-
return feglm_stream(fml, data,
|
|
217
|
+
return feglm_stream(fml, data, family, workdir=workdir, vcov=vcov, cluster=cluster,
|
|
196
218
|
**options)
|
|
197
219
|
|
|
198
220
|
|
|
221
|
+
# options of hdfe-stream's `feglm_stream` that the fit here ignores (it has no
|
|
222
|
+
# row files, it counts a single fixed effect's parameters without `fe_dof`, and
|
|
223
|
+
# it reports the within pseudo R-squared whenever there is a fixed effect)
|
|
224
|
+
_BINARY_IGNORED = {"save_resid", "within_pseudo_r2", "fe_dof"}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _binary_route(vcov, cluster, options):
|
|
228
|
+
"""The options for this package's fit of a binary logit, or None when only
|
|
229
|
+
hdfe-stream's does it: an option it has no counterpart of
|
|
230
|
+
(``bias_correction``, ``bootcluster``, ...), the separation check
|
|
231
|
+
switched off, or CRV3."""
|
|
232
|
+
import inspect
|
|
233
|
+
|
|
234
|
+
from .estimator import _fit
|
|
235
|
+
known = set(inspect.signature(_fit).parameters) - {
|
|
236
|
+
"kind", "fml", "data", "workdir", "vcov", "cluster", "levels", "case", "l2", "random",
|
|
237
|
+
"random_cov", "random_tol", "random_method", "firth", "device", "link", "altwise",
|
|
238
|
+
"poisson_options", "profile", "own_covariates", "_binary"}
|
|
239
|
+
opts = dict(options)
|
|
240
|
+
for k in _BINARY_IGNORED:
|
|
241
|
+
opts.pop(k, None)
|
|
242
|
+
if opts.pop("separation_check", True) is not True:
|
|
243
|
+
return None
|
|
244
|
+
for off, default in (("bias_correction", False), ("bootcluster", None)):
|
|
245
|
+
if off in opts and opts[off] == default: # switched off: as not given
|
|
246
|
+
del opts[off]
|
|
247
|
+
if "iwls_tol" in opts:
|
|
248
|
+
opts["tol"] = opts.pop("iwls_tol")
|
|
249
|
+
if "iwls_maxiter" in opts:
|
|
250
|
+
opts["maxiter"] = opts.pop("iwls_maxiter")
|
|
251
|
+
if any(k not in known for k in opts):
|
|
252
|
+
return None
|
|
253
|
+
vs = [vcov] + ([cluster] if isinstance(cluster, str) else list(cluster or []))
|
|
254
|
+
if any("CRV3" in (v if isinstance(v, str) else " ".join(map(str, v))) for v in vs):
|
|
255
|
+
return None
|
|
256
|
+
if options.get("fe_dof", "exact") not in ("exact", "pyfixest"):
|
|
257
|
+
return None
|
|
258
|
+
return opts
|
|
259
|
+
|
|
260
|
+
|
|
199
261
|
def mlogit_stream(fml: str, data: Source, workdir: PathLike | None = None,
|
|
200
262
|
vcov: Vcov = "iid", cluster: Sequence[str] | str = (),
|
|
201
263
|
levels: Sequence | None = None, **options: Any):
|
|
@@ -221,12 +283,12 @@ def probit_stream(fml: str, data: Source, workdir: PathLike | None = None,
|
|
|
221
283
|
vcov: Vcov = "iid", cluster: Sequence[str] | str = (),
|
|
222
284
|
**options: Any):
|
|
223
285
|
"""Out-of-core binary probit, with any number of high-dimensional fixed
|
|
224
|
-
effects:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
286
|
+
effects: as `logit_stream` (see there: the options, the routing, the
|
|
287
|
+
bias correction), with the standard normal in place of the logistic. With
|
|
288
|
+
no fixed effect or one the fit is this package's, the two-level ordered
|
|
289
|
+
probit's Newton iterations, reported as a `BinaryProbitResult`; its
|
|
290
|
+
variances use the expected information, as `feglm_stream`'s do."""
|
|
291
|
+
return _binary_fit("probit", fml, data, workdir, vcov, cluster, options)
|
|
230
292
|
|
|
231
293
|
|
|
232
294
|
def cfelogit_stream(fml: str, data: Source, workdir: PathLike | None = None,
|
|
@@ -340,6 +402,17 @@ mlogit_stream.__doc__ = """Out-of-core multinomial logit by streamed Newton.
|
|
|
340
402
|
levels : sequence, optional
|
|
341
403
|
The outcome's levels in the order wanted, base first. Default: the
|
|
342
404
|
distinct values, sorted.
|
|
405
|
+
own_covariates : dict, optional
|
|
406
|
+
Covariates that enter only one level's equation: ``{level: column}``
|
|
407
|
+
(or a list of columns), such as each group's baseline share
|
|
408
|
+
predicting that group alone, ``{"Black": "share_black", "Asian":
|
|
409
|
+
"share_asian"}``. A column named here is not a coefficient in the
|
|
410
|
+
other levels' equations, so ``k - 1`` shares add ``k - 1``
|
|
411
|
+
parameters rather than ``(k - 1)^2``. Name the non-base levels; the
|
|
412
|
+
columns must not also be in the formula. The coefficients are named
|
|
413
|
+
``"<level>:<column>"``, and `predict` takes the columns from the new
|
|
414
|
+
data. Not available with fixed or random effects, ``firth=``,
|
|
415
|
+
``profile=`` or ``device="cuda"``.
|
|
343
416
|
poisson_options : dict, optional
|
|
344
417
|
With several fixed effects: further options of hdfe-stream's
|
|
345
418
|
`fepois_stream` (``solver``, ``precond``, ``max_memory_gb``,
|