tompollard / tableone

Create "Table 1" for research papers in Python
https://pypi.python.org/pypi/tableone/
MIT License
161 stars 38 forks source link

warns that no p-value is computed, but p-value is still computed #39

Closed alistairewj closed 4 years ago

alistairewj commented 6 years ago
url="https://raw.githubusercontent.com/tompollard/data/master/primary-biliary-cirrhosis/pbc.csv"
data_pbc=pd.read_csv(url)

# 6 categories of age based on decade
data_pbc['age_group'] = data_pbc['age'].map(lambda x: int(x/10))
columns = ['age_group', 'age', 'sex', 'albumin', 'ast']
categorical = ['age_group']
table = TableOne(data_pbc, columns=columns, categorical=categorical, groupby='sex', pval=True)
table

gives:

tableone.py:463: UserWarning: No p-value was computed for age_group due to the low number of observations.
  warnings.warn('No p-value was computed for {} due to the low number of observations.'.format(v))

but the p-value still appears in the output table

variable level isnull f m pval ptest
n 374 44
age_group 2 0.0 3 (0.8) 0.022 Chi-squared (warning: expected count < 5)
age_group 3 63 (16.84) 3 (6.82)
age_group 4 116 (31.02) 10 (22.73)
age_group 5 121 (32.35) 14 (31.82)
age_group 6 62 (16.58) 13 (29.55)
age_group 7 9 (2.41) 4 (9.09)
age 0.0 50.16 (10.24) 55.71 (10.98) 0.001 One-way ANOVA
albumin 0.0 3.49 (0.42) 3.53 (0.46) 0.536 One-way ANOVA
ast 106.0 122.63 (57.92) 121.99 (47.01) 0.949 One-way ANOVA
tompollard commented 6 years ago

well spotted. this warning s raised when the observed cell count <5, when it should be the expected cell count <5.