H/Clinical/Grouped Summary
The module clinical
include basic functions for processing data generated from clinical trails.
Clinical data include data collected at planning, executing, monitoring and post-study reporting.
Note that although examples are take from clinical data, the same function may be applicable to nonclinical or other types of data.
Example 1
To use an example dataset:
from mtbp3.health.clinical import summary_by_group
summary = summary_by_group(df=None)
print(summary.df.head(2))
study treatment subject visit meal calorie
0 STD1 TRT1 SUBJ01 VISIT1 1 743
1 STD1 TRT1 SUBJ01 VISIT1 2 1195
If df=None
, an example dataset is generated representing a parallel, multi-visit clinical trial that records number of meals taken and calories per meal at each visit. Subject may dropout.
To count number of meals taken at each visits by each subjects grouped by low, median and high calories:
result = summary.count_to_cate(['study', 'treatment', 'subject', 'visit'], 'calorie', [0,500,1000,2000], stats=['count','total_count'])
print(result.head(2))
study treatment subject visit N(0<=X<500) N(500<=X<1000) \
0 STD1 TRT1 SUBJ01 VISIT1 0 1
1 STD1 TRT1 SUBJ01 VISIT2 0 2
N(1000<=V<=2000) N(all)
0 2 3
1 1 3
To count number subjects with low, median, or high number of meals at each visits:
summary1 = summary_by_group(df=result)
print( summary1.count_to_cate(['study', 'treatment', 'visit'], 'N(all)', [0,3,5,7], stats=['count','total_count']) )
study treatment visit N(0<=X<3) N(3<=X<5) N(5<=V<=7) N(all)
0 STD1 TRT1 VISIT1 3 13 4 20
1 STD1 TRT1 VISIT2 1 8 5 14
2 STD1 TRT1 VISIT3 2 5 2 9
3 STD1 TRT1 VISIT4 0 2 2 4
4 STD1 TRT2 VISIT1 5 12 3 20
5 STD1 TRT2 VISIT2 1 7 7 15
6 STD1 TRT2 VISIT3 4 5 2 11
7 STD1 TRT2 VISIT4 3 3 1 7
8 STD2 TRT1 VISIT1 5 10 5 20
9 STD2 TRT1 VISIT2 7 7 3 17
10 STD2 TRT1 VISIT3 6 4 1 11
11 STD2 TRT1 VISIT4 2 1 2 5
12 STD2 TRT2 VISIT1 3 11 6 20
13 STD2 TRT2 VISIT2 2 9 4 15
14 STD2 TRT2 VISIT3 1 4 4 9
15 STD2 TRT2 VISIT4 1 1 2 4
To sum the total number of meals within subjects with low, median, or high numbers of meals:
print( summary1.count_to_cate(['study', 'treatment', 'visit'], 'N(all)', [0,3,5,7], stats=['sum','total_sum']) )
study treatment visit Sum(0<=X<3) Sum(3<=X<5) Sum(5<=V<=7) Sum(all)
0 STD1 TRT1 VISIT1 6 45 20 71
1 STD1 TRT1 VISIT2 2 29 25 56
2 STD1 TRT1 VISIT3 4 18 10 32
3 STD1 TRT1 VISIT4 0 6 10 16
4 STD1 TRT2 VISIT1 10 42 15 67
5 STD1 TRT2 VISIT2 2 25 35 62
6 STD1 TRT2 VISIT3 8 18 10 36
7 STD1 TRT2 VISIT4 6 12 5 23
8 STD2 TRT1 VISIT1 10 36 25 71
9 STD2 TRT1 VISIT2 14 24 15 53
10 STD2 TRT1 VISIT3 12 15 5 32
11 STD2 TRT1 VISIT4 4 3 10 17
12 STD2 TRT2 VISIT1 6 38 30 74
13 STD2 TRT2 VISIT2 4 32 20 56
14 STD2 TRT2 VISIT3 2 14 20 36
15 STD2 TRT2 VISIT4 2 3 10 15