Skip to content

Commit

Permalink
Merge pull request #150 from tompollard/tp/pval_threshold
Browse files Browse the repository at this point in the history
WIP: Display asterisk next to P-Value when it is below a defined threshold
  • Loading branch information
tompollard committed May 10, 2023
2 parents 3efbfea + 34c4f47 commit 0b46fa1
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tableone/tableone.py
Expand Up @@ -217,7 +217,8 @@ def __init__(self, data: pd.DataFrame,
smd: bool = False, overall: bool = True,
row_percent: bool = False, display_all: bool = False,
dip_test: bool = False, normal_test: bool = False,
tukey_test: bool = False) -> None:
tukey_test: bool = False,
pval_threshold: float = None) -> None:

# labels is now rename
if labels is not None and rename is not None:
Expand Down Expand Up @@ -356,6 +357,7 @@ def __init__(self, data: pd.DataFrame,
self._label_suffix = label_suffix
self._decimals = decimals
self._smd = smd
self._pval_threshold = pval_threshold
self._overall = overall
self._row_percent = row_percent

Expand Down Expand Up @@ -1422,15 +1424,28 @@ def _create_tableone(self, data):

# round pval column and convert to string
if self._pval and self._pval_adjust:
if self._pval_threshold:
asterisk_mask = table['P-Value (adjusted)'] < self._pval_threshold

table['P-Value (adjusted)'] = table['P-Value (adjusted)'].apply(
'{:.3f}'.format).astype(str)
table.loc[table['P-Value (adjusted)'] == '0.000',
'P-Value (adjusted)'] = '<0.001'
'P-Value (adjusted)'] = '<0.001'

if self._pval_threshold:
table.loc[asterisk_mask, 'P-Value (adjusted)'] = table['P-Value (adjusted)'][asterisk_mask].astype(str)+"*"

elif self._pval:
if self._pval_threshold:
asterisk_mask = table['P-Value'] < self._pval_threshold

table['P-Value'] = table['P-Value'].apply(
'{:.3f}'.format).astype(str)
table.loc[table['P-Value'] == '0.000', 'P-Value'] = '<0.001'

if self._pval_threshold:
table.loc[asterisk_mask, 'P-Value'] = table['P-Value'][asterisk_mask].astype(str)+"*"

# round smd columns and convert to string
if self._smd:
for c in list(self.smd_table.columns):
Expand Down

0 comments on commit 0b46fa1

Please sign in to comment.