Add unit test for RegressionResult.brant
This commit is contained in:
parent
ea2d04ada1
commit
b2a72a8ef8
@ -62,3 +62,38 @@ somewhat likely/very likely 4.30 (2.72 - 5.88) <0.001*
|
|||||||
------------------------------------------------------------'''.format(result.fitted_dt)
|
------------------------------------------------------------'''.format(result.fitted_dt)
|
||||||
|
|
||||||
assert result.summary() == expected_summary
|
assert result.summary() == expected_summary
|
||||||
|
|
||||||
|
def test_brant_ucla():
|
||||||
|
"""Compare RegressionResult.brant with R brant library for UCLA example at https://stats.oarc.ucla.edu/r/dae/ordinal-logistic-regression/"""
|
||||||
|
|
||||||
|
df = pd.read_stata('tests/data/ucla_ologit.dta')
|
||||||
|
result = yli.regress(yli.OrdinalLogit, df, 'apply', 'pared + public + gpa', exp=False)
|
||||||
|
brant_result = result.brant()
|
||||||
|
|
||||||
|
# df <- read.dta("https://stats.idre.ucla.edu/stat/data/ologit.dta")
|
||||||
|
# m <- polr(apply ~ pared + public + gpa, data=df, Hess=TRUE)
|
||||||
|
# brant(m)
|
||||||
|
|
||||||
|
assert brant_result.tests['Omnibus'].statistic == approx(4.34, abs=0.01)
|
||||||
|
assert brant_result.tests['Omnibus'].dof == 3
|
||||||
|
assert brant_result.tests['Omnibus'].pvalue == approx(0.23, abs=0.01)
|
||||||
|
|
||||||
|
assert brant_result.tests['pared'].statistic == approx(0.13, abs=0.01)
|
||||||
|
assert brant_result.tests['pared'].dof == 1
|
||||||
|
assert brant_result.tests['pared'].pvalue == approx(0.72, abs=0.01)
|
||||||
|
|
||||||
|
assert brant_result.tests['public'].statistic == approx(3.44, abs=0.01)
|
||||||
|
assert brant_result.tests['public'].dof == 1
|
||||||
|
assert brant_result.tests['public'].pvalue == approx(0.06, abs=0.01)
|
||||||
|
|
||||||
|
assert brant_result.tests['gpa'].statistic == approx(0.18, abs=0.01)
|
||||||
|
assert brant_result.tests['gpa'].dof == 1
|
||||||
|
assert brant_result.tests['gpa'].pvalue == approx(0.67, abs=0.01)
|
||||||
|
|
||||||
|
expected_summary = ''' χ² df p
|
||||||
|
Omnibus 4.34 3 0.23
|
||||||
|
pared 0.13 1 0.72
|
||||||
|
public 3.44 1 0.06
|
||||||
|
gpa 0.18 1 0.67 '''
|
||||||
|
|
||||||
|
assert brant_result.summary() == expected_summary
|
||||||
|
@ -1097,5 +1097,9 @@ class BrantResult:
|
|||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# FIXME
|
table = pd.DataFrame([
|
||||||
return 'FIXME'
|
['{:.2f}'.format(test.statistic), '{:.0f}'.format(test.dof), fmt_p(test.pvalue, PValueStyle.TABULAR)]
|
||||||
|
for test in self.tests.values()
|
||||||
|
], index=self.tests.keys(), columns=['χ² ', 'df', 'p '])
|
||||||
|
|
||||||
|
return str(table)
|
||||||
|
Loading…
Reference in New Issue
Block a user