59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
|
# scipy-yli: Helpful SciPy utilities and recipes
|
||
|
# Copyright © 2022–2023 Lee Yingtong Li (RunasSudo)
|
||
|
#
|
||
|
# This program is free software: you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU Affero General Public License as published by
|
||
|
# the Free Software Foundation, either version 3 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU Affero General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU Affero General Public License
|
||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
|
||
|
from pytest import approx
|
||
|
|
||
|
import pandas as pd
|
||
|
|
||
|
import yli
|
||
|
|
||
|
def test_kaplanmeier_simple():
|
||
|
"""Compare yli.kaplanmeier for simple example"""
|
||
|
|
||
|
df = pd.DataFrame({
|
||
|
'SurvTime': [2, 4, 6, 8],
|
||
|
'Status': [True, True, True, True]
|
||
|
})
|
||
|
|
||
|
xpoints, ypoints, _, _ = yli.survival.calc_survfunc_kaplanmeier(df['SurvTime'], df['Status'], False)
|
||
|
|
||
|
assert xpoints[0] == 0
|
||
|
assert ypoints[0] == 1
|
||
|
|
||
|
assert xpoints[1] == 2
|
||
|
assert ypoints[1] == 1
|
||
|
|
||
|
assert xpoints[2] == 2
|
||
|
assert ypoints[2] == 0.75
|
||
|
|
||
|
assert xpoints[3] == 4
|
||
|
assert ypoints[3] == 0.75
|
||
|
|
||
|
assert xpoints[4] == 4
|
||
|
assert ypoints[4] == approx(0.5)
|
||
|
|
||
|
assert xpoints[5] == 6
|
||
|
assert ypoints[5] == approx(0.5)
|
||
|
|
||
|
assert xpoints[6] == 6
|
||
|
assert ypoints[6] == approx(0.25)
|
||
|
|
||
|
assert xpoints[7] == 8
|
||
|
assert ypoints[7] == approx(0.25)
|
||
|
|
||
|
assert xpoints[8] == 8
|
||
|
assert ypoints[8] == 0
|