Implement yli.logrank
This commit is contained in:
parent
e83aa88b19
commit
88509c71a3
@ -22,7 +22,7 @@ from .graphs import init_fonts
|
|||||||
from .io import pickle_read_compressed, pickle_read_encrypted, pickle_write_compressed, pickle_write_encrypted
|
from .io import pickle_read_compressed, pickle_read_encrypted, pickle_write_compressed, pickle_write_encrypted
|
||||||
from .regress import OrdinalLogit, PenalisedLogit, logit_then_regress, regress, vif
|
from .regress import OrdinalLogit, PenalisedLogit, logit_then_regress, regress, vif
|
||||||
from .sig_tests import anova_oneway, auto_univariable, chi2, mannwhitney, pearsonr, spearman, ttest_ind
|
from .sig_tests import anova_oneway, auto_univariable, chi2, mannwhitney, pearsonr, spearman, ttest_ind
|
||||||
from .survival import kaplanmeier
|
from .survival import kaplanmeier, logrank
|
||||||
from .utils import as_ordinal
|
from .utils import as_ordinal
|
||||||
|
|
||||||
def reload_me():
|
def reload_me():
|
||||||
|
@ -513,7 +513,7 @@ class ChiSquaredResult:
|
|||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return 'χ²({}) = {:.2f}; p {}'.format(self.ct, self.dof, self.statistic, fmt_p(self.pvalue, PValueStyle.RELATION))
|
return 'χ²({}) = {:.2f}; p {}'.format(self.dof, self.statistic, fmt_p(self.pvalue, PValueStyle.RELATION))
|
||||||
|
|
||||||
class PearsonChiSquaredResult(ChiSquaredResult):
|
class PearsonChiSquaredResult(ChiSquaredResult):
|
||||||
"""
|
"""
|
||||||
|
@ -18,6 +18,7 @@ from scipy import stats
|
|||||||
import statsmodels.api as sm
|
import statsmodels.api as sm
|
||||||
|
|
||||||
from .config import config
|
from .config import config
|
||||||
|
from .sig_tests import ChiSquaredResult
|
||||||
from .utils import check_nan
|
from .utils import check_nan
|
||||||
|
|
||||||
def kaplanmeier(df, time, status, by=None, ci=True, nan_policy='warn'):
|
def kaplanmeier(df, time, status, by=None, ci=True, nan_policy='warn'):
|
||||||
@ -102,3 +103,16 @@ def plot_survfunc(ax, time, status, ci):
|
|||||||
ax.fill_between(xpoints, ypoints0, ypoints1, alpha=0.3, label='_')
|
ax.fill_between(xpoints, ypoints0, ypoints1, alpha=0.3, label='_')
|
||||||
|
|
||||||
return handle
|
return handle
|
||||||
|
|
||||||
|
def logrank(df, time, status, by, nan_policy='warn'):
|
||||||
|
# TODO: Documentation
|
||||||
|
|
||||||
|
# Check for/clean NaNs
|
||||||
|
df = check_nan(df[[time, status, by]], nan_policy)
|
||||||
|
|
||||||
|
if df[time].dtype == '<m8[ns]':
|
||||||
|
df[time] = df[time].dt.total_seconds()
|
||||||
|
|
||||||
|
statistic, pvalue = sm.duration.survdiff(df[time], df[status], df[by])
|
||||||
|
|
||||||
|
return ChiSquaredResult(statistic=statistic, dof=1, pvalue=pvalue)
|
||||||
|
Loading…
Reference in New Issue
Block a user