Regression Adapters¶
Every adapter below returns the same normalized type - AdapterStats - so mi_ses_from_function treats any of them identically (it requires a StatCalculator, which AdapterStats is). Each also has a matching mi_ses_from_<package>(...) shortcut that runs it across multiple-imputation implicates directly, taking the adapter's own arguments as keywords instead of an arguments={} dict - see Using the Regression Adapters for a walkthrough.
AdapterStats¶
The shared return type - a StatCalculator subclass built directly from df_estimates/df_ses (plus df_vcov/df_tidy when available), with no raw microdata or replicate weights involved. Use this directly if you're wiring up your own delegate for a package with no named adapter below (see Rolling Your Own) - build one from your own df_estimates/df_ses and it's already a valid mi_ses_from_function delegate.
AdapterStats ¶
Bases: StatCalculator
A StatCalculator built directly from an already-computed set of estimates + standard errors - e.g. a regression adapter's own analytic output (see survey_kit.statistics.adapters, every one of which returns this) - rather than from raw microdata. No replicate-weight recomputation at all; use StatCalculator.from_function instead if you want SEs derived from the spread across replicate weights rather than df_ses's own values.
Matches StatCalculator's own API and function surface exactly (comparisons, printing, save/load, and - since MultipleImputation's own combination code reads whatever a delegate returns generically - mi_ses_from_function/MultipleImputation work with this the same way they do a plain StatCalculator) since it IS one, just constructed differently - StatCalculator.copy() (which every chainable method starts from) preserves the real subclass rather than rebuilding a plain StatCalculator, so this stays an AdapterStats through filter()/select()/sort()/rename()/with_columns()/scale_by()/etc.
filter()/rename() are additionally extended here to keep df_vcov in
sync - the base class's versions only ever touch
df_estimates/df_ses/df_replicates (df_vcov didn't exist before this
class), so a plain filter()/rename() would otherwise just drop it
(with a warning) rather than correctly narrow/rename it.
with_columns()/drop()/pipe() operate on value columns or arbitrary
user logic, where there's no safe, generic way to know whether/how
df_vcov/df_tidy (tied to one specific coefficient column, or to the
source package's own unrelated shape) should follow along - rather
than silently dropping either one, these raise ValueError instead
when df_vcov/df_tidy is set, so a caller finds out immediately
rather than discovering it missing later. Clear the one(s) you
don't need first (e.g. obj.replicate_stats.df_vcov = None) to use
these methods anyway. select() doesn't touch df_vcov/df_tidy at all
(for the same reason as those three - not because it was
overlooked) but also doesn't raise, since narrowing which
estimate columns are kept has no "selected columns" concept for
either one to begin with.
concat_with() also raises for df_tidy (same reasoning as above) and for df_vcov on a horizontal concat (it adds a new value column, breaking df_vcov's single-value-column precondition) - but on a vertical concat with both sides carrying a df_vcov over disjoint terms, it stacks them block-diagonally instead of dropping either one, logging a warning that cross-object covariance is assumed zero/unknown (the same independence assumption .compare() already makes between two separate objects).
.compare() (inherited from StatCalculator) computes a difference/ ratio SE from df_ses under an independence assumption between the two objects being compared, but always clears the result's df_vcov (it described the original fit's own term-by-term covariance, which doesn't carry over to a cross-object difference/ratio without more information than either object has).
Source code in src/survey_kit/statistics/adapter_stats.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
Pure Python (statsmodels, linearmodels, pyfixest, polars_ds)¶
No R/Stata/rpy2/pystata needed - these four wrap packages already available in Python.
statsmodels_adapter ¶
statsmodels_adapter(
df,
y: str,
x: list[str] | str,
weight: str | None = None,
add_constant: bool = True,
join_on_name: str = "Variable",
value_name: str = "estimate",
cov_type: str = "HC3",
cov_kwds: dict | None = None,
model_kwargs: dict | None = None,
fit_kwargs: dict | None = None,
) -> AdapterStats
Fit an OLS/WLS regression with statsmodels and return its coefficient table in survey_kit's normalized (df_estimates, df_ses, df_vcov, df_tidy) shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
the merged implicate data (supplied by mi_ses_from_function).
|
|
required |
y
|
dependent variable column name.
|
|
required |
x
|
predictor column name(s).
|
|
required |
weight
|
column name for weighted least squares (WLS), or None for
|
unweighted OLS. Default is None. |
None
|
add_constant
|
whether to add an intercept term (named "const"). Default
|
is True. |
True
|
join_on_name
|
name of the term-identifier column in the output.
|
Default is "Variable". |
'Variable'
|
value_name
|
name of the coefficient/SE/covariance value column in the
|
output. Default is "estimate". |
'estimate'
|
cov_type
|
passed to `.fit()`. Defaults to "HC3" (heteroskedasticity-
|
robust) rather than statsmodels' own classical default, since HC3 performs well even in small-to-moderate samples and there's rarely a reason to assume homoskedasticity for survey/implicate data. Pass "nonrobust" to opt back into classical SEs. |
'HC3'
|
cov_kwds
|
extra keywords for the covariance estimator (e.g.
|
|
None
|
model_kwargs
|
extra keywords forwarded to the model constructor
|
( |
None
|
fit_kwargs
|
extra keywords forwarded to `.fit()` besides cov_type/
|
cov_kwds (e.g. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterStats
|
(df_estimates, df_ses, df_vcov, df_tidy) - df_vcov is always
populated here since statsmodels computes it for free alongside
.bse. df_tidy is statsmodels' own coefficient table
( |
Source code in src/survey_kit/statistics/adapters.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
mi_ses_from_statsmodels ¶
mi_ses_from_statsmodels(
df_implicates,
y: str,
x: list[str] | str,
weight: str | None = None,
add_constant: bool = True,
join_on_name: str = "Variable",
value_name: str = "estimate",
cov_type: str = "HC3",
cov_kwds: dict | None = None,
model_kwargs: dict | None = None,
fit_kwargs: dict | None = None,
replicates=None,
path_srmi: str = "",
index: list | None = None,
df_noimputes=None,
parallel: bool = False,
parallel_inputs=None,
rounding=None,
round_output: bool = True,
)
mi_ses_from_function(delegate=statsmodels_adapter, ...), with
statsmodels_adapter's own arguments taken directly as keyword
arguments instead of packed into an arguments={} dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_implicates
|
parallel_inputs, rounding, round_output : see
|
required | |
path_srmi
|
parallel_inputs, rounding, round_output : see
|
required | |
index
|
parallel_inputs, rounding, round_output : see
|
required | |
df_noimputes
|
parallel_inputs, rounding, round_output : see
|
required | |
parallel
|
parallel_inputs, rounding, round_output : see
|
required | |
y
|
str
|
cov_kwds, model_kwargs, fit_kwargs : see |
required |
x
|
str
|
cov_kwds, model_kwargs, fit_kwargs : see |
required |
weight
|
str
|
cov_kwds, model_kwargs, fit_kwargs : see |
required |
add_constant
|
str
|
cov_kwds, model_kwargs, fit_kwargs : see |
required |
join_on_name
|
str
|
cov_kwds, model_kwargs, fit_kwargs : see |
required |
value_name
|
str
|
cov_kwds, model_kwargs, fit_kwargs : see |
required |
cov_type
|
str
|
cov_kwds, model_kwargs, fit_kwargs : see |
required |
replicates
|
`survey_kit.statistics.replicates.Replicates`, optional.
|
When given, per-implicate SEs come from resampling across
replicate weights instead of statsmodels' own cov_type/cov_kwds -
|
None
|
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
See Also
statsmodels_adapter : the delegate this wraps.
Source code in src/survey_kit/statistics/adapters.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
linearmodels_adapter ¶
linearmodels_adapter(
df,
formula: str,
weight: str | None = None,
model: str = "IV2SLS",
join_on_name: str = "Variable",
value_name: str = "estimate",
cov_type: str = "robust",
cov_kwds: dict | None = None,
model_kwargs: dict | None = None,
fit_kwargs: dict | None = None,
) -> AdapterStats
Fit a linearmodels model (IV/panel) and return its coefficient table in survey_kit's normalized (df_estimates, df_ses, df_vcov, df_tidy) shape.
Unlike statsmodels_adapter/polars_ds_adapter, this takes a formula
string rather than y/x lists - linearmodels' bracket syntax
("y ~ 1 + x1 + [x2 ~ z1 + z2]" for instrumenting x2 with z1/z2) is how
IV/panel specifications are expressed, and there's no y/x-list
equivalent for that.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
the merged implicate data (supplied by mi_ses_from_function).
|
|
required |
formula
|
linearmodels formula string, e.g. "y ~ 1 + x1 + x2" for plain
|
OLS via IV2SLS, or with a bracketed |
required |
weight
|
column name for weighted estimation, or None. Default is None.
|
|
None
|
model
|
one of "IV2SLS", "PanelOLS", "PooledOLS", "RandomEffects",
|
"BetweenOLS". Default is "IV2SLS" (also covers plain OLS, with no
instruments in the formula). Panel models require df to have the
entity/time MultiIndex they expect - set that up before calling
mi_ses_from_function (e.g. via a |
'IV2SLS'
|
join_on_name
|
name of the term-identifier column in the output.
|
Default is "Variable". |
'Variable'
|
value_name
|
name of the coefficient/SE/covariance value column in the
|
output. Default is "estimate". |
'estimate'
|
cov_type
|
passed to `.fit()`. Defaults to "robust" - linearmodels' own
|
vocabulary for heteroskedasticity-consistent SEs ("HC0-3" is a statsmodels-specific term with no direct equivalent here); "robust" is the closest counterpart to statsmodels_adapter's HC3 default, for the same reason (rarely safe to assume homoskedasticity). |
'robust'
|
cov_kwds
|
extra keywords for the covariance estimator (e.g.
|
|
None
|
model_kwargs
|
extra keywords forwarded to the model constructor.
|
Default is None. |
None
|
fit_kwargs
|
extra keywords forwarded to `.fit()` besides cov_type/
|
cov_kwds. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterStats
|
(df_estimates, df_ses, df_vcov, df_tidy) - df_vcov is always populated here since linearmodels computes it for free alongside .std_errors. df_tidy assembles estimate/std_error/statistic/ p_value/conf_low/conf_high from linearmodels' own .params/ .std_errors/.tstats/.pvalues/.conf_int() (linearmodels has no single ready-made tidy table the way statsmodels/pyfixest do) - a diagnostic snapshot only, never combined across implicates. |
Source code in src/survey_kit/statistics/adapters.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
mi_ses_from_linearmodels ¶
mi_ses_from_linearmodels(
df_implicates,
formula: str,
weight: str | None = None,
model: str = "IV2SLS",
join_on_name: str = "Variable",
value_name: str = "estimate",
cov_type: str = "robust",
cov_kwds: dict | None = None,
model_kwargs: dict | None = None,
fit_kwargs: dict | None = None,
replicates=None,
path_srmi: str = "",
index: list | None = None,
df_noimputes=None,
parallel: bool = False,
parallel_inputs=None,
rounding=None,
round_output: bool = True,
)
mi_ses_from_function(delegate=linearmodels_adapter, ...), with
linearmodels_adapter's own arguments taken directly as keyword
arguments instead of packed into an arguments={} dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_implicates
|
parallel_inputs, rounding, round_output : see
|
required | |
path_srmi
|
parallel_inputs, rounding, round_output : see
|
required | |
index
|
parallel_inputs, rounding, round_output : see
|
required | |
df_noimputes
|
parallel_inputs, rounding, round_output : see
|
required | |
parallel
|
parallel_inputs, rounding, round_output : see
|
required | |
formula
|
str
|
model_kwargs, fit_kwargs : see |
required |
weight
|
str
|
model_kwargs, fit_kwargs : see |
required |
model
|
str
|
model_kwargs, fit_kwargs : see |
required |
join_on_name
|
str
|
model_kwargs, fit_kwargs : see |
required |
value_name
|
str
|
model_kwargs, fit_kwargs : see |
required |
cov_type
|
str
|
model_kwargs, fit_kwargs : see |
required |
cov_kwds
|
str
|
model_kwargs, fit_kwargs : see |
required |
replicates
|
`survey_kit.statistics.replicates.Replicates`, optional.
|
When given, per-implicate SEs come from resampling across
replicate weights instead of linearmodels' own cov_type/cov_kwds -
|
None
|
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
See Also
linearmodels_adapter : the delegate this wraps.
Source code in src/survey_kit/statistics/adapters.py
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | |
pyfixest_adapter ¶
pyfixest_adapter(
df,
formula: str,
func: str = "feols",
family: str | None = None,
weight: str | None = None,
vcov: str | dict | None = "hetero",
join_on_name: str = "Variable",
value_name: str = "estimate",
**kwargs,
) -> AdapterStats
Fit a pyfixest regression and return its coefficient table in
survey_kit's normalized (df_estimates, df_ses, df_vcov, df_tidy) shape.
pyfixest mirrors R's fixest syntax/functionality (fixed effects via formula,
e.g. "y ~ x1 | firm", robust/clustered SEs, OLS/GLM/Poisson) natively in
Python - no R/rpy2 needed, and generally the better default over
r_feols/r_feglm/r_fepois/r_fixest_adapter unless you specifically
need something pyfixest doesn't cover (those pull in a full R + rpy2 +
rpy2-arrow dependency chain for no extra benefit if pyfixest already
does the job).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
the merged implicate data (supplied by mi_ses_from_function).
|
|
required |
formula
|
fixest-syntax formula string, e.g. "y ~ x1 + x2 | firm" for a
|
fit with a firm fixed effect. |
required |
func
|
which pyfixest estimator to call - "feols" (default), "feglm",
|
or "fepois". Called as |
'feols'
|
family
|
passed to feglm as its required `family=` argument (e.g.
|
"logit", "probit", "poisson"). Not used for feols/fepois - leave as None. |
None
|
weight
|
column name for weighted estimation, or None. Passed straight
|
through as pyfixest's own |
None
|
vcov
|
pyfixest's own `vcov=` argument - a string like "hetero" (robust,
|
the default here for the same reason statsmodels_adapter defaults
to HC3: rarely safe to assume homoskedasticity), "iid" (classical),
or a dict for clustering, e.g. |
'hetero'
|
join_on_name
|
name of the term-identifier column in the output.
|
Default is "Variable". |
'Variable'
|
value_name
|
name of the coefficient/SE/covariance value column in the
|
output. Default is "estimate". |
'estimate'
|
**kwargs
|
any other argument the chosen estimator takes (`ssc`,
|
|
{}
|
Returns:
| Type | Description |
|---|---|
AdapterStats
|
(df_estimates, df_ses, df_vcov, df_tidy). df_vcov is populated from
the fitted model's internal covariance matrix when its shape
matches the coefficient vector, else None (with a warning) rather
than risking a silent term misalignment - pyfixest doesn't expose
this as public API, so this reads a private attribute defensively.
df_tidy is pyfixest's own |
Source code in src/survey_kit/statistics/adapters.py
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 | |
mi_ses_from_pyfixest ¶
Namespace for per-estimator mi_ses_from_function(delegate=
pyfixest_adapter, ...) wrappers - mi_ses_from_pyfixest.feols(...),
.fepois(...), .feglm(...) - each naming the common pyfixest_adapter
arguments (fml, weight, vcov, family) explicitly instead of
picking the estimator via a func="..." string, so IDEs show the right
parameters for the one you're actually calling. Everything else
pyfixest.feols/fepois/feglm accepts still flows through **kwargs
exactly as in pyfixest_adapter.
feglm
staticmethod
¶
feglm(
df_implicates,
fml: str,
family: str,
vcov: str | dict | None = "hetero",
join_on_name: str = "Variable",
value_name: str = "estimate",
path_srmi: str = "",
index: list | None = None,
df_noimputes=None,
parallel: bool = False,
parallel_inputs=None,
rounding=None,
round_output: bool = True,
**kwargs,
)
mi_ses_from_function(delegate=pyfixest_adapter, ...) for
pyfixest.feglm specifically - GLM with fixed effects (family=
required, e.g. "logit", "probit", "poisson"). No replicates=
option here (unlike .feols/.fepois) - pyfixest's feglm() has
no weights= argument to substitute a replicate weight column
into.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_implicates
|
parallel_inputs, rounding, round_output : see
|
required | |
path_srmi
|
parallel_inputs, rounding, round_output : see
|
required | |
index
|
parallel_inputs, rounding, round_output : see
|
required | |
df_noimputes
|
parallel_inputs, rounding, round_output : see
|
required | |
parallel
|
parallel_inputs, rounding, round_output : see
|
required | |
fml
|
see
|
|
required |
family
|
see
|
|
required |
vcov
|
see
|
|
required |
join_on_name
|
see
|
|
required |
value_name
|
see
|
|
required |
**kwargs
|
any other `pyfixest.feglm` argument (`ssc`,
|
|
{}
|
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
See Also
pyfixest_adapter : the delegate this wraps.
feols
staticmethod
¶
feols(
df_implicates,
fml: str,
weight: str | None = None,
vcov: str | dict | None = "hetero",
join_on_name: str = "Variable",
value_name: str = "estimate",
replicates=None,
path_srmi: str = "",
index: list | None = None,
df_noimputes=None,
parallel: bool = False,
parallel_inputs=None,
rounding=None,
round_output: bool = True,
**kwargs,
)
mi_ses_from_function(delegate=pyfixest_adapter, ...) for
pyfixest.feols specifically - OLS/IV with fixed effects, fixest
formula syntax (e.g. "y ~ x1 + x2 | firm").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_implicates
|
parallel_inputs, rounding, round_output : see
|
required | |
path_srmi
|
parallel_inputs, rounding, round_output : see
|
required | |
index
|
parallel_inputs, rounding, round_output : see
|
required | |
df_noimputes
|
parallel_inputs, rounding, round_output : see
|
required | |
parallel
|
parallel_inputs, rounding, round_output : see
|
required | |
fml
|
see
|
|
required |
weight
|
see
|
|
required |
vcov
|
see
|
|
required |
join_on_name
|
see
|
|
required |
value_name
|
see
|
|
required |
replicates
|
`survey_kit.statistics.replicates.Replicates`,
|
optional. When given, per-implicate SEs come from resampling
across replicate weights instead of |
None
|
**kwargs
|
any other `pyfixest.feols` argument (`ssc`, `fixef_rm`,
|
|
{}
|
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
See Also
pyfixest_adapter : the delegate this wraps.
fepois
staticmethod
¶
fepois(
df_implicates,
fml: str,
weight: str | None = None,
vcov: str | dict | None = "hetero",
join_on_name: str = "Variable",
value_name: str = "estimate",
replicates=None,
path_srmi: str = "",
index: list | None = None,
df_noimputes=None,
parallel: bool = False,
parallel_inputs=None,
rounding=None,
round_output: bool = True,
**kwargs,
)
mi_ses_from_function(delegate=pyfixest_adapter, ...) for
pyfixest.fepois specifically - Poisson regression with fixed
effects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_implicates
|
parallel_inputs, rounding, round_output : see
|
required | |
path_srmi
|
parallel_inputs, rounding, round_output : see
|
required | |
index
|
parallel_inputs, rounding, round_output : see
|
required | |
df_noimputes
|
parallel_inputs, rounding, round_output : see
|
required | |
parallel
|
parallel_inputs, rounding, round_output : see
|
required | |
fml
|
see
|
|
required |
weight
|
see
|
|
required |
vcov
|
see
|
|
required |
join_on_name
|
see
|
|
required |
value_name
|
see
|
|
required |
replicates
|
see `mi_ses_from_pyfixest.feols` - same
|
replicate-weight-bootstrap option, |
None
|
**kwargs
|
any other `pyfixest.fepois` argument (`ssc`,
|
|
{}
|
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
See Also
pyfixest_adapter : the delegate this wraps.
polars_ds_adapter ¶
polars_ds_adapter(
df,
y: str,
x: list[str] | str,
weight: str | None = None,
add_bias: bool = True,
join_on_name: str = "Variable",
value_name: str = "estimate",
std_err: str = "hc3",
null_policy: str = "raise",
) -> AdapterStats
Fit an OLS/WLS regression with polars_ds's lin_reg_report and return
its coefficient table in survey_kit's normalized (df_estimates, df_ses,
None, df_tidy) shape. Stays entirely in polars/narwhals - no pandas
conversion.
polars_ds doesn't expose a coefficient covariance matrix, so df_vcov is
always None here: contrasts between two terms of the same fit
(.compare(other, compare_list_variables=[...])) aren't calculable from
this adapter's output alone. Use statsmodels_adapter or
linearmodels_adapter if you need that.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
the merged implicate data (supplied by mi_ses_from_function).
|
|
required |
y
|
dependent variable column name.
|
|
required |
x
|
predictor column name(s).
|
|
required |
weight
|
column name for weighted least squares, or None. **Note**: when
|
weight is given, polars_ds always falls back to homoskedastic
standard errors regardless of |
None
|
add_bias
|
whether to add an intercept term (named "__bias__", polars_ds's
|
own naming). Default is True. |
True
|
join_on_name
|
name of the term-identifier column in the output.
|
Default is "Variable". |
'Variable'
|
value_name
|
name of the coefficient/SE value column in the output.
|
Default is "estimate". |
'estimate'
|
std_err
|
one of "se" (classical/homoskedastic), "hc0", "hc1", "hc2",
|
"hc3". Defaults to "hc3", for the same reason statsmodels_adapter defaults there - rarely safe to assume homoskedasticity. Silently ignored (falls back to "se") when weight is given - see the weight parameter above. |
'hc3'
|
null_policy
|
how to handle nulls in the predictors, passed straight to
|
polars_ds. Default is "raise". |
'raise'
|
Returns:
| Type | Description |
|---|---|
AdapterStats
|
df_vcov is always None here - df_tidy is polars_ds's full
|
Source code in src/survey_kit/statistics/adapters.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 | |
mi_ses_from_polars_ds ¶
mi_ses_from_polars_ds(
df_implicates,
y: str,
x: list[str] | str,
weight: str | None = None,
add_bias: bool = True,
join_on_name: str = "Variable",
value_name: str = "estimate",
std_err: str = "hc3",
null_policy: str = "raise",
replicates=None,
path_srmi: str = "",
index: list | None = None,
df_noimputes=None,
parallel: bool = False,
parallel_inputs=None,
rounding=None,
round_output: bool = True,
)
mi_ses_from_function(delegate=polars_ds_adapter, ...), with
polars_ds_adapter's own arguments taken directly as keyword
arguments instead of packed into an arguments={} dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_implicates
|
parallel_inputs, rounding, round_output : see
|
required | |
path_srmi
|
parallel_inputs, rounding, round_output : see
|
required | |
index
|
parallel_inputs, rounding, round_output : see
|
required | |
df_noimputes
|
parallel_inputs, rounding, round_output : see
|
required | |
parallel
|
parallel_inputs, rounding, round_output : see
|
required | |
y
|
str
|
see |
required |
x
|
str
|
see |
required |
weight
|
str
|
see |
required |
add_bias
|
str
|
see |
required |
join_on_name
|
str
|
see |
required |
value_name
|
str
|
see |
required |
std_err
|
str
|
see |
required |
null_policy
|
str
|
see |
required |
replicates
|
`survey_kit.statistics.replicates.Replicates`, optional.
|
When given, per-implicate SEs come from resampling across
replicate weights instead of |
None
|
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
See Also
polars_ds_adapter : the delegate this wraps.
Source code in src/survey_kit/statistics/adapters.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 | |
R (rpy2)¶
Requires R itself plus rpy2/rpy2-arrow (pip install survey-kit[r]). r_feols/r_feglm/r_fepois/r_femlm (and their mi_ses_from_r_fixest shortcuts) cover fixest's four estimators with named arguments; r_fixest_adapter is the fully generic func= escape hatch for anything else fixest offers (feNmlm, feglm.fit, ...); r_lm_adapter covers base R's lm()/glm(). For any other R package/function entirely, see _r_interop and r_arbitrary_estimators.py.
r_lm_adapter ¶
r_lm_adapter(
df,
formula: str,
weight: str | None = None,
family: str | None = None,
join_on_name: str = "Variable",
value_name: str = "estimate",
**r_kwargs,
) -> AdapterStats
Fit a base-R lm()/glm() model and return its coefficient table in
survey_kit's normalized (df_estimates, df_ses, df_vcov, df_tidy) shape.
Needs only R itself (no extra R packages) plus rpy2/rpy2-arrow on the
Python side - see survey_kit.statistics._r_interop.check_r_setup().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
the merged implicate data (supplied by mi_ses_from_function).
|
|
required |
formula
|
R formula string, e.g. "y ~ x1 + x2".
|
|
required |
weight
|
column name for weighted least squares, or None. Default is
|
None. Passed as lm()/glm()'s |
None
|
family
|
a plain R family name (e.g. "binomial", "poisson") to fit via
|
glm() instead of lm() - base R resolves the string to the family
function itself. For a non-default link function, wrap the full
expression in |
None
|
join_on_name
|
name of the term-identifier column in the output.
|
Default is "Variable". |
'Variable'
|
value_name
|
name of the coefficient/SE/covariance value column in the
|
output. Default is "estimate". |
'estimate'
|
**r_kwargs
|
any other lm()/glm() argument (e.g. `subset=`, `na.action=`,
|
|
{}
|
Returns:
| Type | Description |
|---|---|
AdapterStats
|
(df_estimates, df_ses, df_vcov, df_tidy) - df_vcov is always
populated here since vcov() is free alongside coef() in R. df_tidy
is R's own |
Notes
Base R's lm()/glm() only provide classical (non-robust) standard errors
- there's no HC0-3 equivalent without the 'sandwich' package, which this
adapter deliberately doesn't pull in (keeping the R-side dependency at
just R itself). Use r_fixest_adapter for built-in robust/cluster SEs.
Source code in src/survey_kit/statistics/adapters.py
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 | |
r_fixest_adapter ¶
r_fixest_adapter(
df,
formula: str,
func: str = "feols",
weight: str | None = None,
family: str | None = None,
vcov: str | None = None,
join_on_name: str = "Variable",
value_name: str = "estimate",
**r_kwargs,
) -> AdapterStats
Fit any fixest regression and return its coefficient table in
survey_kit's normalized (df_estimates, df_ses, df_vcov, df_tidy) shape.
fixest supports fixed effects directly in the formula (e.g. "y ~ x1 |
firm + year") and computes robust/clustered SEs natively - no 'sandwich'
needed. Requires the R 'fixest' package - see
survey_kit.statistics._r_interop.check_r_setup(["fixest"]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
the merged implicate data (supplied by mi_ses_from_function).
|
|
required |
formula
|
fixest formula string, e.g. "y ~ x1 + x2 | firm" for a fit
|
with a firm fixed effect. |
required |
func
|
which fixest estimator to call, e.g. "feols" (default), "feglm",
|
"fepois", "femlm", "feNmlm", "feglm.fit" - anything in the fixest
namespace. Called as |
'feols'
|
weight
|
column name for weighted estimation, or None. Default is None.
|
Passed as fixest's |
None
|
family
|
a plain R family name (e.g. "binomial", "poisson") - only
|
meaningful for func="feglm"/"femlm". For a non-default link
function, wrap the full expression in |
None
|
vcov
|
fixest's own `vcov=` argument - a string like "hetero" (robust)
|
or "iid" (classical), or a one-sided formula string like "~firm"
for cluster-robust SEs. Defaults to "hetero" for the same reason
statsmodels_adapter defaults to HC3 - rarely safe to assume
homoskedasticity - unless you pass |
None
|
join_on_name
|
name of the term-identifier column in the output.
|
Default is "Variable". |
'Variable'
|
value_name
|
name of the coefficient/SE/covariance value column in the
|
output. Default is "estimate". |
'estimate'
|
**r_kwargs
|
any other argument any fixest estimator takes - `cluster`,
|
|
{}
|
Returns:
| Type | Description |
|---|---|
AdapterStats
|
(df_estimates, df_ses, df_vcov) - df_vcov is always populated here since vcov() is free alongside coef() in fixest's results. |
Source code in src/survey_kit/statistics/adapters.py
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 | |
r_feols ¶
r_feols(
df,
formula: str,
weight: str | None = None,
vcov: str | None = None,
cluster=None,
panel_id=None,
ssc=None,
fixef=None,
lean: bool | None = None,
notes: bool | None = None,
verbose: int | None = None,
join_on_name: str = "Variable",
value_name: str = "estimate",
**r_kwargs,
) -> AdapterStats
fixest::feols() (linear regression, with fixed effects) with arguments
mirroring fixest's own. See `r_fixest_adapter` for the fully generic
`func=` version (feNmlm, feglm.fit, ...) and the general conversion
rules; this is the same thing with feols's common arguments spelled out.
Parameters
Parameters
df : the merged implicate data (supplied by mi_ses_from_function).
formula : fixest formula string, e.g. "y ~ x1 + x2 | firm" for a fit
with a firm fixed effect.
weight : column name for weighted estimation, or None. Passed as
`weights=~column` (fixest needs a formula here, not a plain string).
vcov : "hetero" (robust, the default), "iid" (classical), or a one-sided
formula string like "~firm" for cluster-robust SEs.
{params} join_on_name : name of the term-identifier column in the output. Default is "Variable". value_name : name of the coefficient/SE/covariance value column in the output. Default is "estimate".
Returns
Returns
AdapterStats
(df_estimates, df_ses, df_vcov, df_tidy) - df_tidy is fixest's own
coeftable() (Estimate/Std. Error/t value/Pr(>|t|)), a diagnostic
snapshot only, never combined across implicates.
Source code in src/survey_kit/statistics/adapters.py
r_feglm ¶
r_feglm(
df,
formula: str,
family: str = "gaussian",
weight: str | None = None,
vcov: str | None = None,
cluster=None,
panel_id=None,
ssc=None,
fixef=None,
lean: bool | None = None,
notes: bool | None = None,
verbose: int | None = None,
join_on_name: str = "Variable",
value_name: str = "estimate",
**r_kwargs,
) -> AdapterStats
fixest::feglm() (GLM, with fixed effects) with arguments mirroring
fixest's own. See `r_fixest_adapter` for the fully generic `func=`
version and the general conversion rules.
Parameters
Parameters
df : the merged implicate data (supplied by mi_ses_from_function).
formula : fixest formula string, e.g. "y ~ x1 + x2 | firm".
family : a plain R family name, e.g. "binomial", "poisson" - passed as a
quoted string (fixest resolves it to the family function itself).
For a non-default link function, wrap the full expression in
[`RRaw`][survey_kit.statistics._r_interop.RRaw], e.g.
`family=RRaw('binomial(link="probit")')`. Default is "gaussian"
(matching feglm's own default) - for a pure Poisson fit,
`r_fepois` is faster and doesn't need this.
weight : column name for weighted estimation, or None. Passed as
`weights=~column`.
vcov : "hetero" (robust, the default), "iid" (classical), or a one-sided
formula string like "~firm" for cluster-robust SEs.
{params} join_on_name : name of the term-identifier column in the output. Default is "Variable". value_name : name of the coefficient/SE/covariance value column in the output. Default is "estimate".
Returns
Returns
AdapterStats
(df_estimates, df_ses, df_vcov, df_tidy) - df_tidy is fixest's own
coeftable() (Estimate/Std. Error/t value/Pr(>|t|)), a diagnostic
snapshot only, never combined across implicates.
Source code in src/survey_kit/statistics/adapters.py
r_fepois ¶
r_fepois(
df,
formula: str,
weight: str | None = None,
vcov: str | None = None,
cluster=None,
panel_id=None,
ssc=None,
fixef=None,
lean: bool | None = None,
notes: bool | None = None,
verbose: int | None = None,
join_on_name: str = "Variable",
value_name: str = "estimate",
**r_kwargs,
) -> AdapterStats
fixest::fepois() (Poisson regression, with fixed effects) with arguments
mirroring fixest's own. See `r_fixest_adapter` for the fully generic
`func=` version and the general conversion rules.
Parameters
Parameters
df : the merged implicate data (supplied by mi_ses_from_function).
formula : fixest formula string, e.g. "y ~ x1 + x2 | firm".
weight : column name for weighted estimation, or None. Passed as
`weights=~column`.
vcov : "hetero" (robust, the default), "iid" (classical), or a one-sided
formula string like "~firm" for cluster-robust SEs.
{params} join_on_name : name of the term-identifier column in the output. Default is "Variable". value_name : name of the coefficient/SE/covariance value column in the output. Default is "estimate".
Returns
Returns
AdapterStats
(df_estimates, df_ses, df_vcov, df_tidy) - df_tidy is fixest's own
coeftable() (Estimate/Std. Error/t value/Pr(>|t|)), a diagnostic
snapshot only, never combined across implicates.
Source code in src/survey_kit/statistics/adapters.py
r_femlm ¶
r_femlm(
df,
formula: str,
family: str = "poisson",
vcov: str | None = None,
cluster=None,
panel_id=None,
ssc=None,
fixef=None,
lean: bool | None = None,
notes: bool | None = None,
verbose: int | None = None,
join_on_name: str = "Variable",
value_name: str = "estimate",
**r_kwargs,
) -> AdapterStats
fixest::femlm() (max-likelihood: Poisson/negative binomial/logit/
Gaussian, with fixed effects) with arguments mirroring fixest's own.
See `r_fixest_adapter` for the fully generic `func=` version and the
general conversion rules. Note: femlm has no `weights=` argument
(unlike feols/feglm/fepois).
Parameters
Parameters
df : the merged implicate data (supplied by mi_ses_from_function).
formula : fixest formula string, e.g. "y ~ x1 + x2 | firm".
family : one of "poisson" (default), "negbin", "logit", "gaussian" -
a plain string (femlm, unlike feglm, only accepts one of these four
exact names - there's no link-function customization here).
vcov : "hetero" (robust, the default), "iid" (classical), or a one-sided
formula string like "~firm" for cluster-robust SEs.
{params} join_on_name : name of the term-identifier column in the output. Default is "Variable". value_name : name of the coefficient/SE/covariance value column in the output. Default is "estimate".
Returns
Returns
AdapterStats
(df_estimates, df_ses, df_vcov, df_tidy) - df_tidy is fixest's own
coeftable() (Estimate/Std. Error/t value/Pr(>|t|)), a diagnostic
snapshot only, never combined across implicates.
Source code in src/survey_kit/statistics/adapters.py
mi_ses_from_r_fixest ¶
Namespace for per-estimator mi_ses_from_function(delegate=r_feols/
r_feglm/r_fepois/r_femlm, ...) wrappers - mi_ses_from_r_fixest.feols(...),
.feglm(...), .fepois(...), .femlm(...) - each naming that
estimator's own arguments (formula, weight, vcov, cluster,
panel_id, ...) directly instead of packing them into an
arguments={} dict, so IDEs show the right parameters for the one
you're actually calling. Everything else the R side of fixest accepts
still flows through **r_kwargs exactly as in r_feols/r_feglm/
r_fepois/r_femlm. See r_fixest_adapter for the fully generic
func= escape hatch (feNmlm, feglm.fit, ...) this doesn't cover.
feglm
staticmethod
¶
feglm(
df_implicates,
formula: str,
family: str = "gaussian",
weight: str | None = None,
vcov: str | None = None,
cluster=None,
panel_id=None,
ssc=None,
fixef=None,
lean: bool | None = None,
notes: bool | None = None,
verbose: int | None = None,
join_on_name: str = "Variable",
value_name: str = "estimate",
replicates=None,
path_srmi: str = "",
index: list | None = None,
df_noimputes=None,
parallel: bool = False,
parallel_inputs=None,
rounding=None,
round_output: bool = True,
**r_kwargs,
)
mi_ses_from_function(delegate=r_feglm, ...) - fixest::feglm()
(GLM, with fixed effects) across implicates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_implicates
|
parallel_inputs, rounding, round_output : see
|
required | |
path_srmi
|
parallel_inputs, rounding, round_output : see
|
required | |
index
|
parallel_inputs, rounding, round_output : see
|
required | |
df_noimputes
|
parallel_inputs, rounding, round_output : see
|
required | |
parallel
|
parallel_inputs, rounding, round_output : see
|
required | |
formula
|
str
|
lean, notes, verbose, join_on_name, value_name, **r_kwargs :
see |
required |
family
|
str
|
lean, notes, verbose, join_on_name, value_name, **r_kwargs :
see |
required |
weight
|
str
|
lean, notes, verbose, join_on_name, value_name, **r_kwargs :
see |
required |
vcov
|
str
|
lean, notes, verbose, join_on_name, value_name, **r_kwargs :
see |
required |
cluster
|
str
|
lean, notes, verbose, join_on_name, value_name, **r_kwargs :
see |
required |
panel_id
|
str
|
lean, notes, verbose, join_on_name, value_name, **r_kwargs :
see |
required |
ssc
|
str
|
lean, notes, verbose, join_on_name, value_name, **r_kwargs :
see |
required |
fixef
|
str
|
lean, notes, verbose, join_on_name, value_name, **r_kwargs :
see |
required |
replicates
|
see `mi_ses_from_r_fixest.feols` - same
|
replicate-weight-bootstrap option, |
None
|
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
See Also
r_feglm : the delegate this wraps.
femlm
staticmethod
¶
femlm(
df_implicates,
formula: str,
family: str = "poisson",
vcov: str | None = None,
cluster=None,
panel_id=None,
ssc=None,
fixef=None,
lean: bool | None = None,
notes: bool | None = None,
verbose: int | None = None,
join_on_name: str = "Variable",
value_name: str = "estimate",
path_srmi: str = "",
index: list | None = None,
df_noimputes=None,
parallel: bool = False,
parallel_inputs=None,
rounding=None,
round_output: bool = True,
**r_kwargs,
)
mi_ses_from_function(delegate=r_femlm, ...) - fixest::femlm()
(max-likelihood: Poisson/negative binomial/logit/Gaussian, with
fixed effects) across implicates. Note: femlm has no weight=
argument (unlike feols/feglm/fepois), so - unlike those three -
there's no replicates= option here either: nothing to substitute
a replicate weight column into.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_implicates
|
parallel_inputs, rounding, round_output : see
|
required | |
path_srmi
|
parallel_inputs, rounding, round_output : see
|
required | |
index
|
parallel_inputs, rounding, round_output : see
|
required | |
df_noimputes
|
parallel_inputs, rounding, round_output : see
|
required | |
parallel
|
parallel_inputs, rounding, round_output : see
|
required | |
formula
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
family
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
vcov
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
cluster
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
panel_id
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
ssc
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
fixef
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
lean
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
notes
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
See Also
r_femlm : the delegate this wraps.
feols
staticmethod
¶
feols(
df_implicates,
formula: str,
weight: str | None = None,
vcov: str | None = None,
cluster=None,
panel_id=None,
ssc=None,
fixef=None,
lean: bool | None = None,
notes: bool | None = None,
verbose: int | None = None,
join_on_name: str = "Variable",
value_name: str = "estimate",
replicates=None,
path_srmi: str = "",
index: list | None = None,
df_noimputes=None,
parallel: bool = False,
parallel_inputs=None,
rounding=None,
round_output: bool = True,
**r_kwargs,
)
mi_ses_from_function(delegate=r_feols, ...) - fixest::feols()
(linear regression, with fixed effects) across implicates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_implicates
|
parallel_inputs, rounding, round_output : see
|
required | |
path_srmi
|
parallel_inputs, rounding, round_output : see
|
required | |
index
|
parallel_inputs, rounding, round_output : see
|
required | |
df_noimputes
|
parallel_inputs, rounding, round_output : see
|
required | |
parallel
|
parallel_inputs, rounding, round_output : see
|
required | |
formula
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
weight
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
vcov
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
cluster
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
panel_id
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
ssc
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
fixef
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
lean
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
notes
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
replicates
|
`survey_kit.statistics.replicates.Replicates`,
|
optional. When given, per-implicate SEs come from resampling
across replicate weights instead of |
None
|
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
See Also
r_feols : the delegate this wraps.
fepois
staticmethod
¶
fepois(
df_implicates,
formula: str,
weight: str | None = None,
vcov: str | None = None,
cluster=None,
panel_id=None,
ssc=None,
fixef=None,
lean: bool | None = None,
notes: bool | None = None,
verbose: int | None = None,
join_on_name: str = "Variable",
value_name: str = "estimate",
replicates=None,
path_srmi: str = "",
index: list | None = None,
df_noimputes=None,
parallel: bool = False,
parallel_inputs=None,
rounding=None,
round_output: bool = True,
**r_kwargs,
)
mi_ses_from_function(delegate=r_fepois, ...) - fixest::fepois()
(Poisson regression, with fixed effects) across implicates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_implicates
|
parallel_inputs, rounding, round_output : see
|
required | |
path_srmi
|
parallel_inputs, rounding, round_output : see
|
required | |
index
|
parallel_inputs, rounding, round_output : see
|
required | |
df_noimputes
|
parallel_inputs, rounding, round_output : see
|
required | |
parallel
|
parallel_inputs, rounding, round_output : see
|
required | |
formula
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
weight
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
vcov
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
cluster
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
panel_id
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
ssc
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
fixef
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
lean
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
notes
|
str
|
verbose, join_on_name, value_name, **r_kwargs : see |
required |
replicates
|
see `mi_ses_from_r_fixest.feols` - same
|
replicate-weight-bootstrap option, |
None
|
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
See Also
r_fepois : the delegate this wraps.
Stata (pystata)¶
Requires Stata 17+ plus pip install survey-kit[stata]. stata_adapter (and its mi_ses_from_stata shortcut) runs any e-class command as a plain string - there's no separate named-wrapper-per-estimator layer to route around the way fixest has, since any Stata command already works by just changing the command string. stata_results_adapter reaches any r()/e() result rather than the fixed e(b)/e(V)/r(table) triplet, and is what mi_ses_from_stata's replicates= option uses under the hood for replicate-weight bootstrapping.
stata_adapter ¶
stata_adapter(
df,
command: str | list[str],
join_on_name: str = "Variable",
value_name: str = "estimate",
edition: str | None = None,
stata_path: str | None = None,
reuse_data: bool = False,
quietly: bool = True,
) -> AdapterStats
Run an arbitrary Stata e-class estimation command (regress, logit, xtreg, areg, svy: ..., or anything from an installed community package) and return its coefficient table in survey_kit's normalized (df_estimates, df_ses, df_vcov, df_tidy) shape.
See survey_kit.statistics._stata_interop's module docstring for
details, and check_stata_setup() there for a setup diagnostic.
Data moves into Stata via a .dta file written by polars_readstat
(write_readstat) rather than pystata's own DataFrame transfer - .dta
is Stata's own native, most battle-tested ingestion path, so this
doesn't depend on however pystata's transfer mechanism behaves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
the merged implicate data (supplied by mi_ses_from_function).
|
|
required |
command
|
the Stata command to run, e.g. "regress y x1 x2", or
|
"regress y x1 x2 [pw=w]", or "xtreg y x1 x2, fe". Must leave
e(b)/e(V) populated - true of most estimation commands. Pass a
list of commands run in order, instead of a single string, when
you need setup ( |
required |
join_on_name
|
name of the term-identifier column in the output.
|
Default is "Variable". |
'Variable'
|
value_name
|
name of the coefficient/SE/covariance value column in the
|
output. Default is "estimate". |
'estimate'
|
edition
|
forwarded to
|
|
None
|
stata_path
|
forwarded to
|
|
None
|
reuse_data
|
if True, skip re-exporting/re-`use`-ing df when it's the
|
same object (by identity) as a previous reuse_data=True call -
useful when calling this repeatedly for the same underlying data
(e.g. once per replicate weight, if |
False
|
quietly
|
pass False to let `command` stream Stata's own console
|
output on success too (failures always surface the real error
text regardless - see |
True
|
Returns:
| Type | Description |
|---|---|
AdapterStats
|
(df_estimates, df_ses, df_vcov, df_tidy) - df_vcov from e(V).
df_tidy is Stata's own r(table) (the matrix |
Source code in src/survey_kit/statistics/adapters.py
2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 | |
mi_ses_from_stata ¶
mi_ses_from_stata(
df_implicates,
command: str | list[str],
path_srmi: str = "",
index: list | None = None,
df_noimputes=None,
join_on_name: str = "Variable",
value_name: str = "estimate",
edition: str | None = None,
stata_path: str | None = None,
reuse_data: bool = False,
quietly: bool = True,
replicates=None,
parallel: bool = False,
parallel_inputs=None,
rounding=None,
round_output: bool = True,
)
mi_ses_from_function(delegate=stata_adapter, ...), with
stata_adapter's own arguments (command, edition, stata_path,
...) taken directly as keyword arguments instead of packed into an
arguments={} dict - the common case of running one Stata command
across implicates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_implicates
|
parallel_inputs, rounding, round_output : see
|
required | |
path_srmi
|
parallel_inputs, rounding, round_output : see
|
required | |
index
|
parallel_inputs, rounding, round_output : see
|
required | |
df_noimputes
|
parallel_inputs, rounding, round_output : see
|
required | |
parallel
|
parallel_inputs, rounding, round_output : see
|
required | |
command
|
str | list[str]
|
quietly : see |
required |
join_on_name
|
str | list[str]
|
quietly : see |
required |
value_name
|
str | list[str]
|
quietly : see |
required |
edition
|
str | list[str]
|
quietly : see |
required |
stata_path
|
str | list[str]
|
quietly : see |
required |
reuse_data
|
str | list[str]
|
quietly : see |
required |
replicates
|
`survey_kit.statistics.replicates.Replicates`, optional.
|
When given, per-implicate SEs come from resampling across
replicate weights instead of |
None
|
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
Examples:
>>> mi_reg = mi_ses_from_stata(
... df_implicates=df_implicates,
... command="regress y x1 x2",
... )
Replicate-weight SEs instead of Stata's own e(V):
>>> from survey_kit.statistics.replicates import Replicates
>>> mi_reg = mi_ses_from_stata(
... df_implicates=df_implicates,
... command="regress y x1 x2 [pw={weight}]",
... replicates=Replicates(weight_stub="replicate_", n_replicates=80),
... )
See Also
stata_adapter, stata_results_adapter : the delegates this wraps.
mi_ses_from_function :
the general-purpose function this specializes.
Source code in src/survey_kit/statistics/adapters.py
2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 | |
stata_results_adapter ¶
stata_results_adapter(
df,
command: str | list[str],
results: list[str],
weight: str = "",
join_on_name: str = "Variable",
value_name: str = "estimate",
edition: str | None = None,
stata_path: str | None = None,
reuse_data: bool = False,
quietly: bool = True,
) -> pl.DataFrame
Run an arbitrary Stata command (r-class or e-class) and return a flat
table of exactly the r()/e() results you name - the Stata counterpart
to survey_kit's generic R/rpy2 escape hatch (get_library/
extract_fit in _r_interop.py), but shaped as a
StatCalculator.from_function
delegate (df, weight -> one row per estimate) rather than an
mi_ses_from_function delegate: point estimates only, no vcov. Use
this for bootstrap/replicate-weight variance - the spread of estimates
across replicate weights IS the SE (computed by
Replicates/StatCalculator), not Stata's own e(V) - the same reason
the R tutorial's ad-hoc run_regression delegate returns just a plain
coefficient table with no SE of its own.
Unlike stata_adapter (which assumes an e-class fit and always reads
the fixed e(b)/e(V)/r(table) triplet), this works for ANY command that
populates r()/e() results - summarize, tabstat, ci, svy: mean,
or a full e-class regression - you just name what you want back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
one replicate/bootstrap draw's data (supplied by
|
StatCalculator.from_function per replicate weight). |
required |
command
|
the Stata command to run, with "{weight}" as a placeholder
|
for the weight column name if |
required |
results
|
names to pull back, e.g. ["r(mean)", "r(Var)"] or ["e(b)"].
|
A scalar becomes one row ( |
required |
weight
|
column name to substitute into "{weight}" in `command`, or ""
|
(the StatCalculator.from_function convention - see its
|
''
|
join_on_name
|
name of the term-identifier column in the output.
|
Default is "Variable". |
'Variable'
|
value_name
|
name of the estimate column in the output. Default is
|
"estimate". |
'estimate'
|
edition
|
forwarded to
|
|
None
|
stata_path
|
forwarded to
|
|
None
|
reuse_data
|
if True, skip re-exporting/re-`use`-ing df when it's the
|
same object (by identity) as the previous call - this is exactly
the common case here: StatCalculator.from_function calls this
delegate once per replicate weight with the same df object every
time (only |
False
|
quietly
|
pass False to let `command` stream Stata's own console
|
output on success too (failures always surface the real error
text regardless - see |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per named scalar, or per column of a named matrix - exactly the shape a StatCalculator.from_function delegate needs (no vcov/tidy - see the note above on where the variance actually comes from). |
Source code in src/survey_kit/statistics/adapters.py
2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 | |