-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_statsmodels_poisson.py
37 lines (27 loc) · 1.32 KB
/
test_statsmodels_poisson.py
1
2
3
4
5
6
7
8
9
10
11
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
import polars as pl
import statsmodels.formula.api as smf
from polars.testing import assert_series_equal
from marginaleffects import comparisons, predictions
from tests.conftest import mtcars_df
dat = mtcars_df.with_columns(pl.col("cyl").cast(pl.Utf8))
mod = smf.poisson("carb ~ mpg * qsec + cyl", data=dat.to_pandas()).fit()
def test_predictions_01():
unknown = predictions(mod)
known = pl.read_csv("tests/r/test_statsmodels_poisson_predictions_01.csv")
assert_series_equal(known["estimate"], unknown["estimate"], rtol=1e-4)
def test_predictions_02():
unknown = predictions(mod, by="cyl")
known = pl.read_csv("tests/r/test_statsmodels_poisson_predictions_02.csv")
assert_series_equal(known["estimate"], unknown["estimate"], rtol=1e-4)
def test_comparisons_01():
unknown = comparisons(mod).sort(["term", "contrast"])
known = pl.read_csv("tests/r/test_statsmodels_poisson_comparisons_01.csv").sort(
["term", "contrast"]
)
assert_series_equal(known["estimate"], unknown["estimate"], rtol=1e-4)
def test_comparisons_02():
unknown = comparisons(mod, by="cyl").sort(["term", "contrast", "cyl"])
known = pl.read_csv("tests/r/test_statsmodels_poisson_comparisons_02.csv").sort(
["term", "contrast", "cyl"]
)
assert_series_equal(known["estimate"], unknown["estimate"], rtol=1e-4)