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.
sort() evaluates the expression on df_estimates and reorders df_ses, df_tidy (if it has the id columns) and df_vcov's {id}_1/{id}_2 to follow it, so everything stays aligned even when sorting by a value column.
concat_with() raises for df_tidy and 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). df_tidy is stacked too (columns not shared are null). concat_with() returns a NEW object. Use rename_values() (inherited) to rename id values consistently across all tables.
.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 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 | |
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,
by: dict[str, list[str]] | list | str | 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
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) - same formats
as StatCalculator's own |
None
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) (see the
delegate adapter's |
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
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 414 415 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 | |
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,
by: dict[str, list[str]] | list | str | None = None,
)
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
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) (see the
delegate adapter's |
None
|
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
See Also
statsmodels_adapter : the delegate this wraps.
Source code in src\survey_kit\statistics\adapters.py
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 528 529 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 | |
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,
by: dict[str, list[str]] | list | str | 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
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) - same formats
as StatCalculator's own |
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
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 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 | |
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,
by: dict[str, list[str]] | list | str | None = None,
)
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
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) (see the
delegate adapter's |
None
|
Returns:
| Type | Description |
|---|---|
MultipleImputation
|
Same as |
See Also
linearmodels_adapter : the delegate this wraps.
Source code in src\survey_kit\statistics\adapters.py
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 | |
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",
by: dict[str, list[str]] | list | str | None = None,
**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`,
|
|
{}
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) - same formats
as StatCalculator's own |
None
|
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
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 | |
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,
by: dict[str, list[str]] | list | str | None = None,
**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`,
|
|
{}
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) (see the
delegate adapter's |
None
|
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,
by: dict[str, list[str]] | list | str | None = None,
**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`,
|
|
{}
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) (see the
delegate adapter's |
None
|
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,
by: dict[str, list[str]] | list | str | None = None,
**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`,
|
|
{}
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) (see the
delegate adapter's |
None
|
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",
by: dict[str, list[str]] | list | str | None = None,
) -> 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'
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) - same formats
as StatCalculator's own |
None
|
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
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 1305 1306 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 1374 1375 1376 1377 1378 | |
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,
by: dict[str, list[str]] | list | str | None = None,
)
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
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) (see the
delegate adapter's |
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
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 | |
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",
by: dict[str, list[str]] | list | str | None = None,
filter: str | None = None,
**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=`,
|
|
{}
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) - same formats
as StatCalculator's own |
None
|
filter
|
str | None
|
A R condition (e.g. "g == 1 & age > 18") restricting this run to the rows it
keeps. R subsets a copy inside R with |
None
|
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
1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 | |
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",
by: dict[str, list[str]] | list | str | None = None,
filter: str | None = None,
**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`,
|
|
{}
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) - same formats
as StatCalculator's own |
None
|
filter
|
str | None
|
A R condition (e.g. "g == 1 & age > 18") restricting this run to the rows it
keeps. R subsets a copy inside R with |
None
|
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
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 | |
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",
by: dict[str, list[str]] | list | str | None = None,
filter: str | None = None,
**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".
by : dict[str, list[str]] | list | str | None, optional
Fit separately within each group of these column(s) - same formats
as StatCalculator's own `by`. The group columns are added to every
returned table (df_estimates, df_ses, df_tidy and df_vcov) and set
as the result's `by`. Covariances *across* groups are not computed
(each group is its own fit). Default is None (one fit on all of df).
filter : str | None, optional
A R condition (e.g. "g == 1 & age > 18") restricting this run to the rows it
keeps. R subsets a copy inside R with `subset()` (rows where it is NA
are dropped), so the loaded data is never changed.
Combines (AND) with each group's own condition when `by` is used. Default is
None (all rows).
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
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 | |
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",
by: dict[str, list[str]] | list | str | None = None,
filter: str | None = None,
**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".
by : dict[str, list[str]] | list | str | None, optional
Fit separately within each group of these column(s) - same formats
as StatCalculator's own `by`. The group columns are added to every
returned table (df_estimates, df_ses, df_tidy and df_vcov) and set
as the result's `by`. Covariances *across* groups are not computed
(each group is its own fit). Default is None (one fit on all of df).
filter : str | None, optional
A R condition (e.g. "g == 1 & age > 18") restricting this run to the rows it
keeps. R subsets a copy inside R with `subset()` (rows where it is NA
are dropped), so the loaded data is never changed.
Combines (AND) with each group's own condition when `by` is used. Default is
None (all rows).
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
1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 | |
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",
by: dict[str, list[str]] | list | str | None = None,
filter: str | None = None,
**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".
by : dict[str, list[str]] | list | str | None, optional
Fit separately within each group of these column(s) - same formats
as StatCalculator's own `by`. The group columns are added to every
returned table (df_estimates, df_ses, df_tidy and df_vcov) and set
as the result's `by`. Covariances *across* groups are not computed
(each group is its own fit). Default is None (one fit on all of df).
filter : str | None, optional
A R condition (e.g. "g == 1 & age > 18") restricting this run to the rows it
keeps. R subsets a copy inside R with `subset()` (rows where it is NA
are dropped), so the loaded data is never changed.
Combines (AND) with each group's own condition when `by` is used. Default is
None (all rows).
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
1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 | |
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",
by: dict[str, list[str]] | list | str | None = None,
filter: str | None = None,
**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".
by : dict[str, list[str]] | list | str | None, optional
Fit separately within each group of these column(s) - same formats
as StatCalculator's own `by`. The group columns are added to every
returned table (df_estimates, df_ses, df_tidy and df_vcov) and set
as the result's `by`. Covariances *across* groups are not computed
(each group is its own fit). Default is None (one fit on all of df).
filter : str | None, optional
A R condition (e.g. "g == 1 & age > 18") restricting this run to the rows it
keeps. R subsets a copy inside R with `subset()` (rows where it is NA
are dropped), so the loaded data is never changed.
Combines (AND) with each group's own condition when `by` is used. Default is
None (all rows).
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
1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 | |
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,
by: dict[str, list[str]] | list | str | None = None,
**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
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) (see the
delegate adapter's |
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,
by: dict[str, list[str]] | list | str | None = None,
**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 |
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) (see the
delegate adapter's |
None
|
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,
by: dict[str, list[str]] | list | str | None = None,
**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
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) (see the
delegate adapter's |
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,
by: dict[str, list[str]] | list | str | None = None,
**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
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) (see the
delegate adapter's |
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,
by: dict[str, list[str]] | list | str | None = None,
filter: str | None = None,
) -> 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
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) - same formats
as StatCalculator's own |
None
|
filter
|
str | None
|
A Stata condition (e.g. "g == 1 & age > 18") restricting this run to the rows it
keeps. The run is wrapped in |
None
|
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
2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 | |
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,
by: dict[str, list[str]] | list | str | None = None,
)
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
|
by
|
dict[str, list[str]] | list | str | None
|
Fit separately within each group of these column(s) (see the
delegate adapter's |
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
2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 | |
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,
filter: str | None = None,
) -> 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
|
filter
|
str | None
|
A Stata condition (e.g. "g == 1 & age > 18") restricting this run to
the rows it keeps - the run is wrapped in |
None
|
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
2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 | |