rpstats 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rpstats-1.0.0/LICENSE +21 -0
- rpstats-1.0.0/PKG-INFO +224 -0
- rpstats-1.0.0/README.md +193 -0
- rpstats-1.0.0/pyproject.toml +53 -0
- rpstats-1.0.0/rpstats/__init__.py +62 -0
- rpstats-1.0.0/rpstats/_display.py +14 -0
- rpstats-1.0.0/rpstats/exp1.py +86 -0
- rpstats-1.0.0/rpstats/exp2.py +118 -0
- rpstats-1.0.0/rpstats/exp3.py +168 -0
- rpstats-1.0.0/rpstats/exp4.py +134 -0
- rpstats-1.0.0/rpstats/exp5.py +306 -0
- rpstats-1.0.0/rpstats/exp6.py +255 -0
- rpstats-1.0.0/rpstats/exp7.py +244 -0
- rpstats-1.0.0/rpstats/exp8.py +355 -0
- rpstats-1.0.0/rpstats.egg-info/PKG-INFO +224 -0
- rpstats-1.0.0/rpstats.egg-info/SOURCES.txt +19 -0
- rpstats-1.0.0/rpstats.egg-info/dependency_links.txt +1 -0
- rpstats-1.0.0/rpstats.egg-info/requires.txt +5 -0
- rpstats-1.0.0/rpstats.egg-info/top_level.txt +1 -0
- rpstats-1.0.0/setup.cfg +4 -0
- rpstats-1.0.0/tests/test_experiments.py +97 -0
rpstats-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
rpstats-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rpstats
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Clinical Data Programming and Statistical Analysis Practical Code Library.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Keywords: clinical-trials,biostatistics,clinical-data-programming,cdisc,sdtm,adam,pharmaceutical,r-programming,data-science,statistics
|
|
7
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
8
|
+
Classifier: Intended Audience :: Education
|
|
9
|
+
Classifier: Intended Audience :: Healthcare Industry
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: R
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
28
|
+
Requires-Dist: build; extra == "dev"
|
|
29
|
+
Requires-Dist: twine; extra == "dev"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# rpstats
|
|
33
|
+
|
|
34
|
+
[](https://pypi.org/project/rpstats/)
|
|
35
|
+
[](https://pypi.org/project/rpstats/)
|
|
36
|
+
[](https://opensource.org/licenses/MIT)
|
|
37
|
+
|
|
38
|
+
**rpstats** (*Reproducible Practical Statistics*) is a lightweight, professional Python package designed for biostatistics students, clinical data programmers, and researchers preparing for practical examinations and laboratory coursework.
|
|
39
|
+
|
|
40
|
+
It contains **8 complete clinical data programming and statistical analysis practical experiments**, providing complete, clean, practical-ready code in **both Python and R**.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Key Features
|
|
45
|
+
|
|
46
|
+
- **Dual-Language Practical Code**: Instant access to complete, tested implementations in Python and R for every experiment.
|
|
47
|
+
- **Zero Heavy Dependencies**: Installs instantly without requiring pandas, NumPy, SciPy, or R. Runs on any computer, standard college laboratory workstation, or laptop.
|
|
48
|
+
- **Exam & Laboratory Ready**: Formatted for quick copy-pasting directly into Jupyter Notebook, Google Colab, or RStudio.
|
|
49
|
+
- **Statistically & Clinically Sound**: Follows industry standards including CDISC SDTM / ADaM dataset architecture, standard clinical blood pressure guidelines, and statistical testing methodologies.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
### Standard Installation (via PyPI)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install rpstats
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Local Development Installation
|
|
62
|
+
|
|
63
|
+
Install in editable mode from the project directory:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install -e .
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Quick Start & Usage
|
|
72
|
+
|
|
73
|
+
Import the package in Python or inside a Jupyter Notebook:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import rpstats
|
|
77
|
+
|
|
78
|
+
# 1. Display package version
|
|
79
|
+
rpstats.version()
|
|
80
|
+
|
|
81
|
+
# 2. View the catalog of all 8 experiments
|
|
82
|
+
rpstats.help()
|
|
83
|
+
|
|
84
|
+
# 3. Print complete Python & R programs for any experiment
|
|
85
|
+
rpstats.exp1() # Data Import and Exploration
|
|
86
|
+
rpstats.exp2() # Data Cleaning
|
|
87
|
+
rpstats.exp3() # Data Transformation
|
|
88
|
+
rpstats.exp4() # Data Visualization
|
|
89
|
+
rpstats.exp5() # SDTM Dataset Creation
|
|
90
|
+
rpstats.exp6() # ADaM Dataset Creation
|
|
91
|
+
rpstats.exp7() # Statistical Analysis
|
|
92
|
+
rpstats.exp8() # Clinical Tables and Figures
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Experiments Catalog
|
|
98
|
+
|
|
99
|
+
| Function | Experiment Title | Input Files | Primary Output Files |
|
|
100
|
+
| :--- | :--- | :--- | :--- |
|
|
101
|
+
| `rpstats.exp1()` | **Data Import and Exploration** | `clinical_data.csv` | Terminal inspection output |
|
|
102
|
+
| `rpstats.exp2()` | **Data Cleaning** | `clinical_trial_data_raw.csv` | `clinical_trial_data_cleaned.csv` |
|
|
103
|
+
| `rpstats.exp3()` | **Data Transformation** | `clinical_demographics.csv`, `clinical_vitals_labs.csv` | `clinical_trial_data_analysis.csv` |
|
|
104
|
+
| `rpstats.exp4()` | **Data Visualization** | `clinical_visualization_data.csv` | 5 High-res PNG plots (`dpi=300`) |
|
|
105
|
+
| `rpstats.exp5()` | **SDTM Dataset Creation** | 5 Raw clinical domains | `dm_sdtm.csv`, `vs_sdtm.csv`, `lb_sdtm.csv`, `ae_sdtm.csv`, `ex_sdtm.csv` |
|
|
106
|
+
| `rpstats.exp6()` | **ADaM Dataset Creation** | 5 SDTM domains | `adsl.csv`, `advs.csv`, `adlb.csv`, `adae.csv` |
|
|
107
|
+
| `rpstats.exp7()` | **Statistical Analysis** | `adam_exp7_analysis.csv` | `placebo_sbp_qqplot.png`, `statistical_analysis_results.csv` |
|
|
108
|
+
| `rpstats.exp8()` | **Clinical Tables and Figures** | `adsl_exp8.csv`, `advs_exp8.csv`, `adae_exp8.csv` | Tables 14.1.1, 14.2.1, 14.3.1 (CSV), Figures 14.2.1, 14.2.2 (PNG) |
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Experiment Details
|
|
113
|
+
|
|
114
|
+
### Experiment 1: Data Import and Exploration
|
|
115
|
+
- **Objective**: Import and inspect clinical trial datasets.
|
|
116
|
+
- **Python**: Uses `pandas` and `numpy` to display the first and last records, shape, column names, data types, summary statistics, and missing value counts.
|
|
117
|
+
- **R**: Uses base R to inspect dimensions, structure (`str()`), column names, summary statistics, missing values per column, and complete case counts.
|
|
118
|
+
|
|
119
|
+
### Experiment 2: Data Cleaning
|
|
120
|
+
- **Objective**: Perform essential clinical data cleaning tasks.
|
|
121
|
+
- **Key Operations**:
|
|
122
|
+
- Impute numeric missing values using column medians.
|
|
123
|
+
- Impute missing site identifiers (`SITEID`) with `"Unknown"`.
|
|
124
|
+
- Identify and remove exact duplicate rows.
|
|
125
|
+
- Deduplicate patient records (`USUBJID`), retaining the first record.
|
|
126
|
+
- Standardize patient sex into `'M'` and `'F'`.
|
|
127
|
+
- Save cleaned data to `clinical_trial_data_cleaned.csv`.
|
|
128
|
+
|
|
129
|
+
### Experiment 3: Data Transformation
|
|
130
|
+
- **Objective**: Merge demographics with clinical vitals/labs and derive key study indicators.
|
|
131
|
+
- **Key Operations**:
|
|
132
|
+
- Verify subject identifier (`USUBJID`) uniqueness and merge datasets using an inner join.
|
|
133
|
+
- Derive age groups (`<65`, `>=65`).
|
|
134
|
+
- Derive clinical blood pressure categories (`Normal`, `Elevated`, `Stage 1 Hypertension`, `Stage 2 Hypertension`).
|
|
135
|
+
- Calculate days on study (`DAYS_ON_STUDY`) against a configurable cutoff date.
|
|
136
|
+
- Derive clinical high-risk flag (`HIGH_RISK_FLAG`).
|
|
137
|
+
- Save merged dataset as `clinical_trial_data_analysis.csv`.
|
|
138
|
+
|
|
139
|
+
### Experiment 4: Clinical Data Visualization
|
|
140
|
+
- **Objective**: Generate publication-grade, high-resolution figures.
|
|
141
|
+
- **Figures Generated**:
|
|
142
|
+
1. `age_histogram.png`: Age distribution with kernel density curve.
|
|
143
|
+
2. `sex_barchart.png`: Subject count by sex.
|
|
144
|
+
3. `bmi_by_agegroup_boxplot.png`: BMI distribution grouped by age category.
|
|
145
|
+
4. `glucose_by_arm_histogram.png`: Fasting glucose distribution across treatment arms.
|
|
146
|
+
5. `height_weight_scatterplot.png`: Height vs. weight scatter plot categorized by sex.
|
|
147
|
+
|
|
148
|
+
### Experiment 5: SDTM Dataset Creation
|
|
149
|
+
- **Objective**: Transform raw source data into standardized CDISC SDTM domain structures.
|
|
150
|
+
- **Domains Produced**:
|
|
151
|
+
- `DM` (Demographics): Subject identifiers, age, sex, race, treatment arm, date ISO standardizations.
|
|
152
|
+
- `VS` (Vital Signs): Wide-to-long transformation of SYSBP, DIABP, PULSE, and TEMP with sequence numbering (`VSSEQ`).
|
|
153
|
+
- `LB` (Laboratory): Wide-to-long transformation of GLUC, ALT, AST, and BILI with sequence numbering (`LBSEQ`).
|
|
154
|
+
- `AE` (Adverse Events): Standardized severity (`MILD`, `MODERATE`, `SEVERE`), start/end dates, sequence numbering (`AESEQ`).
|
|
155
|
+
- `EX` (Exposure): Standardized treatment dosing records and sequence numbering (`EXSEQ`).
|
|
156
|
+
|
|
157
|
+
### Experiment 6: ADaM Dataset Creation
|
|
158
|
+
- **Objective**: Build CDISC ADaM datasets for statistical analysis.
|
|
159
|
+
- **Datasets Produced**:
|
|
160
|
+
- `ADSL` (Subject-Level Analysis Dataset): Incorporates exposure metrics, treatment start/end dates, safety population flag (`SAFFL`), and risk categorizations.
|
|
161
|
+
- `ADVS` (Vital Signs Analysis Dataset): Identifies baseline assessment (`BASE`), calculates post-baseline change (`CHG`), and percentage change (`PCHG`).
|
|
162
|
+
- `ADLB` (Laboratory Analysis Dataset): Baseline identification, change (`CHG`), and percentage change (`PCHG`).
|
|
163
|
+
- `ADAE` (Adverse Events Analysis Dataset): Numeric severity (`AESEVN`) and numerical causality mappings, treatment-emergent event flags (`TRTEMFL`).
|
|
164
|
+
|
|
165
|
+
### Experiment 7: Statistical Analysis
|
|
166
|
+
- **Objective**: Perform formal statistical hypothesis testing and inference.
|
|
167
|
+
- **Tests Implemented**:
|
|
168
|
+
- Descriptive summary: N, Mean, SD, Median, IQR, Min, Max by treatment arm.
|
|
169
|
+
- Normality evaluation: Histograms, Q-Q plots, and Shapiro-Wilk tests.
|
|
170
|
+
- Variance homogeneity: Levene's test for equality of variances.
|
|
171
|
+
- Two-sample comparison: Independent t-test, mean differences, 95% confidence intervals, and Cohen's d effect size.
|
|
172
|
+
- Multi-group comparison: One-way ANOVA for SBP, DBP, and Glucose across all treatment arms.
|
|
173
|
+
- Post-hoc testing: Tukey's Honestly Significant Difference (HSD) test.
|
|
174
|
+
- Categorical association: Chi-square test and Fisher's exact test for adverse event incidence.
|
|
175
|
+
|
|
176
|
+
### Experiment 8: Clinical Tables and Figures
|
|
177
|
+
- **Objective**: Generate standard regulatory-style clinical trial tables and figures.
|
|
178
|
+
- **Deliverables**:
|
|
179
|
+
- `table_14_1_1_demographics.csv`: Table 14.1.1 Summary of Demographics and Baseline Characteristics.
|
|
180
|
+
- `table_14_2_1_efficacy.csv`: Table 14.2.1 Summary of Change in Systolic Blood Pressure and Treatment Comparisons vs. Placebo.
|
|
181
|
+
- `table_14_3_1_adverse_events.csv`: Table 14.3.1 Overall Summary of Adverse Events by Severity and Preferred Term.
|
|
182
|
+
- `figure_14_2_1_sbp_boxplot.png`: Box plot of SBP change by treatment arm.
|
|
183
|
+
- `figure_14_2_2_forest_plot.png`: Forest plot illustrating treatment differences versus Placebo with 95% confidence intervals.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Workflow Guide: Copying Code
|
|
188
|
+
|
|
189
|
+
### Jupyter Notebook / Google Colab (Python)
|
|
190
|
+
1. Run `rpstats.expX()` in a Python console or notebook cell (where `X` is 1 to 8).
|
|
191
|
+
2. Copy the text printed under `---------------- PYTHON CODE ----------------`.
|
|
192
|
+
3. Paste into a new Jupyter code cell and run.
|
|
193
|
+
4. Ensure the required input CSV file is placed in your working directory.
|
|
194
|
+
|
|
195
|
+
### RStudio / R Script (R Language)
|
|
196
|
+
1. Run `rpstats.expX()` in Python to display the code.
|
|
197
|
+
2. Copy the text printed under `---------------- R LANGUAGE CODE ----------------`.
|
|
198
|
+
3. Open RStudio, create a new R Script (`File -> New File -> R Script`), and paste.
|
|
199
|
+
4. Set your working directory using `setwd()` or place the input CSV in the R working directory, then execute the script.
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Requirements & Compatibility
|
|
204
|
+
|
|
205
|
+
- **rpstats Package Runtime**:
|
|
206
|
+
- Python: `>= 3.8` (tested on 3.8, 3.9, 3.10, 3.11, 3.12, 3.13)
|
|
207
|
+
- Operating Systems: Windows, macOS, Linux
|
|
208
|
+
- No external runtime dependencies required to install or display code.
|
|
209
|
+
|
|
210
|
+
- **To Execute Printed Python Scripts**:
|
|
211
|
+
- `pandas`, `numpy`, `matplotlib`, `seaborn`, `scipy`, `statsmodels`
|
|
212
|
+
- Install via: `pip install pandas numpy matplotlib seaborn scipy statsmodels`
|
|
213
|
+
|
|
214
|
+
- **To Execute Printed R Scripts**:
|
|
215
|
+
- R `>= 4.0`
|
|
216
|
+
- Packages: `tidyverse`, `ggplot2`
|
|
217
|
+
- Install in R via: `install.packages(c("tidyverse", "ggplot2"))`
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## License
|
|
222
|
+
|
|
223
|
+
Distributed under the [MIT License](LICENSE).
|
|
224
|
+
|
rpstats-1.0.0/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# rpstats
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/rpstats/)
|
|
4
|
+
[](https://pypi.org/project/rpstats/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
**rpstats** (*Reproducible Practical Statistics*) is a lightweight, professional Python package designed for biostatistics students, clinical data programmers, and researchers preparing for practical examinations and laboratory coursework.
|
|
8
|
+
|
|
9
|
+
It contains **8 complete clinical data programming and statistical analysis practical experiments**, providing complete, clean, practical-ready code in **both Python and R**.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Key Features
|
|
14
|
+
|
|
15
|
+
- **Dual-Language Practical Code**: Instant access to complete, tested implementations in Python and R for every experiment.
|
|
16
|
+
- **Zero Heavy Dependencies**: Installs instantly without requiring pandas, NumPy, SciPy, or R. Runs on any computer, standard college laboratory workstation, or laptop.
|
|
17
|
+
- **Exam & Laboratory Ready**: Formatted for quick copy-pasting directly into Jupyter Notebook, Google Colab, or RStudio.
|
|
18
|
+
- **Statistically & Clinically Sound**: Follows industry standards including CDISC SDTM / ADaM dataset architecture, standard clinical blood pressure guidelines, and statistical testing methodologies.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
### Standard Installation (via PyPI)
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install rpstats
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Local Development Installation
|
|
31
|
+
|
|
32
|
+
Install in editable mode from the project directory:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install -e .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Quick Start & Usage
|
|
41
|
+
|
|
42
|
+
Import the package in Python or inside a Jupyter Notebook:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import rpstats
|
|
46
|
+
|
|
47
|
+
# 1. Display package version
|
|
48
|
+
rpstats.version()
|
|
49
|
+
|
|
50
|
+
# 2. View the catalog of all 8 experiments
|
|
51
|
+
rpstats.help()
|
|
52
|
+
|
|
53
|
+
# 3. Print complete Python & R programs for any experiment
|
|
54
|
+
rpstats.exp1() # Data Import and Exploration
|
|
55
|
+
rpstats.exp2() # Data Cleaning
|
|
56
|
+
rpstats.exp3() # Data Transformation
|
|
57
|
+
rpstats.exp4() # Data Visualization
|
|
58
|
+
rpstats.exp5() # SDTM Dataset Creation
|
|
59
|
+
rpstats.exp6() # ADaM Dataset Creation
|
|
60
|
+
rpstats.exp7() # Statistical Analysis
|
|
61
|
+
rpstats.exp8() # Clinical Tables and Figures
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Experiments Catalog
|
|
67
|
+
|
|
68
|
+
| Function | Experiment Title | Input Files | Primary Output Files |
|
|
69
|
+
| :--- | :--- | :--- | :--- |
|
|
70
|
+
| `rpstats.exp1()` | **Data Import and Exploration** | `clinical_data.csv` | Terminal inspection output |
|
|
71
|
+
| `rpstats.exp2()` | **Data Cleaning** | `clinical_trial_data_raw.csv` | `clinical_trial_data_cleaned.csv` |
|
|
72
|
+
| `rpstats.exp3()` | **Data Transformation** | `clinical_demographics.csv`, `clinical_vitals_labs.csv` | `clinical_trial_data_analysis.csv` |
|
|
73
|
+
| `rpstats.exp4()` | **Data Visualization** | `clinical_visualization_data.csv` | 5 High-res PNG plots (`dpi=300`) |
|
|
74
|
+
| `rpstats.exp5()` | **SDTM Dataset Creation** | 5 Raw clinical domains | `dm_sdtm.csv`, `vs_sdtm.csv`, `lb_sdtm.csv`, `ae_sdtm.csv`, `ex_sdtm.csv` |
|
|
75
|
+
| `rpstats.exp6()` | **ADaM Dataset Creation** | 5 SDTM domains | `adsl.csv`, `advs.csv`, `adlb.csv`, `adae.csv` |
|
|
76
|
+
| `rpstats.exp7()` | **Statistical Analysis** | `adam_exp7_analysis.csv` | `placebo_sbp_qqplot.png`, `statistical_analysis_results.csv` |
|
|
77
|
+
| `rpstats.exp8()` | **Clinical Tables and Figures** | `adsl_exp8.csv`, `advs_exp8.csv`, `adae_exp8.csv` | Tables 14.1.1, 14.2.1, 14.3.1 (CSV), Figures 14.2.1, 14.2.2 (PNG) |
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Experiment Details
|
|
82
|
+
|
|
83
|
+
### Experiment 1: Data Import and Exploration
|
|
84
|
+
- **Objective**: Import and inspect clinical trial datasets.
|
|
85
|
+
- **Python**: Uses `pandas` and `numpy` to display the first and last records, shape, column names, data types, summary statistics, and missing value counts.
|
|
86
|
+
- **R**: Uses base R to inspect dimensions, structure (`str()`), column names, summary statistics, missing values per column, and complete case counts.
|
|
87
|
+
|
|
88
|
+
### Experiment 2: Data Cleaning
|
|
89
|
+
- **Objective**: Perform essential clinical data cleaning tasks.
|
|
90
|
+
- **Key Operations**:
|
|
91
|
+
- Impute numeric missing values using column medians.
|
|
92
|
+
- Impute missing site identifiers (`SITEID`) with `"Unknown"`.
|
|
93
|
+
- Identify and remove exact duplicate rows.
|
|
94
|
+
- Deduplicate patient records (`USUBJID`), retaining the first record.
|
|
95
|
+
- Standardize patient sex into `'M'` and `'F'`.
|
|
96
|
+
- Save cleaned data to `clinical_trial_data_cleaned.csv`.
|
|
97
|
+
|
|
98
|
+
### Experiment 3: Data Transformation
|
|
99
|
+
- **Objective**: Merge demographics with clinical vitals/labs and derive key study indicators.
|
|
100
|
+
- **Key Operations**:
|
|
101
|
+
- Verify subject identifier (`USUBJID`) uniqueness and merge datasets using an inner join.
|
|
102
|
+
- Derive age groups (`<65`, `>=65`).
|
|
103
|
+
- Derive clinical blood pressure categories (`Normal`, `Elevated`, `Stage 1 Hypertension`, `Stage 2 Hypertension`).
|
|
104
|
+
- Calculate days on study (`DAYS_ON_STUDY`) against a configurable cutoff date.
|
|
105
|
+
- Derive clinical high-risk flag (`HIGH_RISK_FLAG`).
|
|
106
|
+
- Save merged dataset as `clinical_trial_data_analysis.csv`.
|
|
107
|
+
|
|
108
|
+
### Experiment 4: Clinical Data Visualization
|
|
109
|
+
- **Objective**: Generate publication-grade, high-resolution figures.
|
|
110
|
+
- **Figures Generated**:
|
|
111
|
+
1. `age_histogram.png`: Age distribution with kernel density curve.
|
|
112
|
+
2. `sex_barchart.png`: Subject count by sex.
|
|
113
|
+
3. `bmi_by_agegroup_boxplot.png`: BMI distribution grouped by age category.
|
|
114
|
+
4. `glucose_by_arm_histogram.png`: Fasting glucose distribution across treatment arms.
|
|
115
|
+
5. `height_weight_scatterplot.png`: Height vs. weight scatter plot categorized by sex.
|
|
116
|
+
|
|
117
|
+
### Experiment 5: SDTM Dataset Creation
|
|
118
|
+
- **Objective**: Transform raw source data into standardized CDISC SDTM domain structures.
|
|
119
|
+
- **Domains Produced**:
|
|
120
|
+
- `DM` (Demographics): Subject identifiers, age, sex, race, treatment arm, date ISO standardizations.
|
|
121
|
+
- `VS` (Vital Signs): Wide-to-long transformation of SYSBP, DIABP, PULSE, and TEMP with sequence numbering (`VSSEQ`).
|
|
122
|
+
- `LB` (Laboratory): Wide-to-long transformation of GLUC, ALT, AST, and BILI with sequence numbering (`LBSEQ`).
|
|
123
|
+
- `AE` (Adverse Events): Standardized severity (`MILD`, `MODERATE`, `SEVERE`), start/end dates, sequence numbering (`AESEQ`).
|
|
124
|
+
- `EX` (Exposure): Standardized treatment dosing records and sequence numbering (`EXSEQ`).
|
|
125
|
+
|
|
126
|
+
### Experiment 6: ADaM Dataset Creation
|
|
127
|
+
- **Objective**: Build CDISC ADaM datasets for statistical analysis.
|
|
128
|
+
- **Datasets Produced**:
|
|
129
|
+
- `ADSL` (Subject-Level Analysis Dataset): Incorporates exposure metrics, treatment start/end dates, safety population flag (`SAFFL`), and risk categorizations.
|
|
130
|
+
- `ADVS` (Vital Signs Analysis Dataset): Identifies baseline assessment (`BASE`), calculates post-baseline change (`CHG`), and percentage change (`PCHG`).
|
|
131
|
+
- `ADLB` (Laboratory Analysis Dataset): Baseline identification, change (`CHG`), and percentage change (`PCHG`).
|
|
132
|
+
- `ADAE` (Adverse Events Analysis Dataset): Numeric severity (`AESEVN`) and numerical causality mappings, treatment-emergent event flags (`TRTEMFL`).
|
|
133
|
+
|
|
134
|
+
### Experiment 7: Statistical Analysis
|
|
135
|
+
- **Objective**: Perform formal statistical hypothesis testing and inference.
|
|
136
|
+
- **Tests Implemented**:
|
|
137
|
+
- Descriptive summary: N, Mean, SD, Median, IQR, Min, Max by treatment arm.
|
|
138
|
+
- Normality evaluation: Histograms, Q-Q plots, and Shapiro-Wilk tests.
|
|
139
|
+
- Variance homogeneity: Levene's test for equality of variances.
|
|
140
|
+
- Two-sample comparison: Independent t-test, mean differences, 95% confidence intervals, and Cohen's d effect size.
|
|
141
|
+
- Multi-group comparison: One-way ANOVA for SBP, DBP, and Glucose across all treatment arms.
|
|
142
|
+
- Post-hoc testing: Tukey's Honestly Significant Difference (HSD) test.
|
|
143
|
+
- Categorical association: Chi-square test and Fisher's exact test for adverse event incidence.
|
|
144
|
+
|
|
145
|
+
### Experiment 8: Clinical Tables and Figures
|
|
146
|
+
- **Objective**: Generate standard regulatory-style clinical trial tables and figures.
|
|
147
|
+
- **Deliverables**:
|
|
148
|
+
- `table_14_1_1_demographics.csv`: Table 14.1.1 Summary of Demographics and Baseline Characteristics.
|
|
149
|
+
- `table_14_2_1_efficacy.csv`: Table 14.2.1 Summary of Change in Systolic Blood Pressure and Treatment Comparisons vs. Placebo.
|
|
150
|
+
- `table_14_3_1_adverse_events.csv`: Table 14.3.1 Overall Summary of Adverse Events by Severity and Preferred Term.
|
|
151
|
+
- `figure_14_2_1_sbp_boxplot.png`: Box plot of SBP change by treatment arm.
|
|
152
|
+
- `figure_14_2_2_forest_plot.png`: Forest plot illustrating treatment differences versus Placebo with 95% confidence intervals.
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Workflow Guide: Copying Code
|
|
157
|
+
|
|
158
|
+
### Jupyter Notebook / Google Colab (Python)
|
|
159
|
+
1. Run `rpstats.expX()` in a Python console or notebook cell (where `X` is 1 to 8).
|
|
160
|
+
2. Copy the text printed under `---------------- PYTHON CODE ----------------`.
|
|
161
|
+
3. Paste into a new Jupyter code cell and run.
|
|
162
|
+
4. Ensure the required input CSV file is placed in your working directory.
|
|
163
|
+
|
|
164
|
+
### RStudio / R Script (R Language)
|
|
165
|
+
1. Run `rpstats.expX()` in Python to display the code.
|
|
166
|
+
2. Copy the text printed under `---------------- R LANGUAGE CODE ----------------`.
|
|
167
|
+
3. Open RStudio, create a new R Script (`File -> New File -> R Script`), and paste.
|
|
168
|
+
4. Set your working directory using `setwd()` or place the input CSV in the R working directory, then execute the script.
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Requirements & Compatibility
|
|
173
|
+
|
|
174
|
+
- **rpstats Package Runtime**:
|
|
175
|
+
- Python: `>= 3.8` (tested on 3.8, 3.9, 3.10, 3.11, 3.12, 3.13)
|
|
176
|
+
- Operating Systems: Windows, macOS, Linux
|
|
177
|
+
- No external runtime dependencies required to install or display code.
|
|
178
|
+
|
|
179
|
+
- **To Execute Printed Python Scripts**:
|
|
180
|
+
- `pandas`, `numpy`, `matplotlib`, `seaborn`, `scipy`, `statsmodels`
|
|
181
|
+
- Install via: `pip install pandas numpy matplotlib seaborn scipy statsmodels`
|
|
182
|
+
|
|
183
|
+
- **To Execute Printed R Scripts**:
|
|
184
|
+
- R `>= 4.0`
|
|
185
|
+
- Packages: `tidyverse`, `ggplot2`
|
|
186
|
+
- Install in R via: `install.packages(c("tidyverse", "ggplot2"))`
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
Distributed under the [MIT License](LICENSE).
|
|
193
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rpstats"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Clinical Data Programming and Statistical Analysis Practical Code Library."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
keywords = [
|
|
13
|
+
"clinical-trials",
|
|
14
|
+
"biostatistics",
|
|
15
|
+
"clinical-data-programming",
|
|
16
|
+
"cdisc",
|
|
17
|
+
"sdtm",
|
|
18
|
+
"adam",
|
|
19
|
+
"pharmaceutical",
|
|
20
|
+
"r-programming",
|
|
21
|
+
"data-science",
|
|
22
|
+
"statistics"
|
|
23
|
+
]
|
|
24
|
+
classifiers = [
|
|
25
|
+
"Development Status :: 5 - Production/Stable",
|
|
26
|
+
"Intended Audience :: Education",
|
|
27
|
+
"Intended Audience :: Healthcare Industry",
|
|
28
|
+
"Intended Audience :: Science/Research",
|
|
29
|
+
"Operating System :: OS Independent",
|
|
30
|
+
"Programming Language :: Python :: 3",
|
|
31
|
+
"Programming Language :: Python :: 3.8",
|
|
32
|
+
"Programming Language :: Python :: 3.9",
|
|
33
|
+
"Programming Language :: Python :: 3.10",
|
|
34
|
+
"Programming Language :: Python :: 3.11",
|
|
35
|
+
"Programming Language :: Python :: 3.12",
|
|
36
|
+
"Programming Language :: Python :: 3.13",
|
|
37
|
+
"Programming Language :: R",
|
|
38
|
+
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
39
|
+
"Topic :: Scientific/Engineering :: Medical Science Apps.",
|
|
40
|
+
"Topic :: Scientific/Engineering :: Mathematics"
|
|
41
|
+
]
|
|
42
|
+
dependencies = []
|
|
43
|
+
|
|
44
|
+
[project.optional-dependencies]
|
|
45
|
+
dev = [
|
|
46
|
+
"pytest>=7.0",
|
|
47
|
+
"build",
|
|
48
|
+
"twine"
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
[tool.setuptools.packages.find]
|
|
52
|
+
where = ["."]
|
|
53
|
+
include = ["rpstats*"]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""rpstats: Clinical Data Programming and Statistical Analysis Practical Code Library.
|
|
2
|
+
|
|
3
|
+
Provides complete, short, practical-ready code for 8 clinical data programming
|
|
4
|
+
and biostatistical analysis practical experiments in both Python and R.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .exp1 import exp1
|
|
8
|
+
from .exp2 import exp2
|
|
9
|
+
from .exp3 import exp3
|
|
10
|
+
from .exp4 import exp4
|
|
11
|
+
from .exp5 import exp5
|
|
12
|
+
from .exp6 import exp6
|
|
13
|
+
from .exp7 import exp7
|
|
14
|
+
from .exp8 import exp8
|
|
15
|
+
|
|
16
|
+
__version__ = "1.0.0"
|
|
17
|
+
|
|
18
|
+
_EXPERIMENTS = [
|
|
19
|
+
("exp1()", "Data Import and Exploration"),
|
|
20
|
+
("exp2()", "Data Cleaning"),
|
|
21
|
+
("exp3()", "Data Transformation"),
|
|
22
|
+
("exp4()", "Data Visualization"),
|
|
23
|
+
("exp5()", "SDTM Dataset Creation"),
|
|
24
|
+
("exp6()", "ADaM Dataset Creation"),
|
|
25
|
+
("exp7()", "Statistical Analysis"),
|
|
26
|
+
("exp8()", "Clinical Tables and Figures"),
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def help() -> None:
|
|
31
|
+
"""Display the list of all practical experiments available in rpstats."""
|
|
32
|
+
sep = "=" * 65
|
|
33
|
+
print(sep)
|
|
34
|
+
print("rpstats - Clinical Data Programming & Statistics Experiments")
|
|
35
|
+
print(sep)
|
|
36
|
+
print("Call any function below to print complete Python and R code:\n")
|
|
37
|
+
for func, title in _EXPERIMENTS:
|
|
38
|
+
print(f" rpstats.{func:<10} : {title}")
|
|
39
|
+
print(f"\nPackage version: {__version__}")
|
|
40
|
+
print("Use help(rpstats.<func>) for more details on each experiment.")
|
|
41
|
+
print(sep)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def version() -> None:
|
|
45
|
+
"""Display the installed rpstats package version."""
|
|
46
|
+
print(f"rpstats version {__version__}")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
"exp1",
|
|
51
|
+
"exp2",
|
|
52
|
+
"exp3",
|
|
53
|
+
"exp4",
|
|
54
|
+
"exp5",
|
|
55
|
+
"exp6",
|
|
56
|
+
"exp7",
|
|
57
|
+
"exp8",
|
|
58
|
+
"help",
|
|
59
|
+
"version",
|
|
60
|
+
"__version__",
|
|
61
|
+
]
|
|
62
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Display formatting utilities for rpstats practical experiments."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def display_experiment(exp_num: int, title: str, python_code: str, r_code: str) -> None:
|
|
5
|
+
"""Print standard formatted output for an experiment in both Python and R."""
|
|
6
|
+
sep = "=" * 55
|
|
7
|
+
print(sep)
|
|
8
|
+
print(f"EXPERIMENT {exp_num}: {title.upper()}")
|
|
9
|
+
print(sep)
|
|
10
|
+
print("\n---------------- PYTHON CODE ----------------\n")
|
|
11
|
+
print(python_code.strip())
|
|
12
|
+
print("\n---------------- R LANGUAGE CODE ----------------\n")
|
|
13
|
+
print(r_code.strip())
|
|
14
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Experiment 1: Data Import and Exploration."""
|
|
2
|
+
|
|
3
|
+
from ._display import display_experiment
|
|
4
|
+
|
|
5
|
+
PYTHON_CODE = r'''import pandas as pd
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
# 1. Read the CSV file
|
|
9
|
+
df = pd.read_csv("clinical_data.csv")
|
|
10
|
+
|
|
11
|
+
# 2. Display first 5 records
|
|
12
|
+
print("--- First 5 Records ---")
|
|
13
|
+
print(df.head())
|
|
14
|
+
|
|
15
|
+
# 3. Display last 5 records
|
|
16
|
+
print("\n--- Last 5 Records ---")
|
|
17
|
+
print(df.tail())
|
|
18
|
+
|
|
19
|
+
# 4. Display dataset shape
|
|
20
|
+
print(f"\nDataset Shape (Rows, Columns): {df.shape}")
|
|
21
|
+
|
|
22
|
+
# 5. Display column names
|
|
23
|
+
print("\n--- Column Names ---")
|
|
24
|
+
print(df.columns.tolist())
|
|
25
|
+
|
|
26
|
+
# 6. Display data types
|
|
27
|
+
print("\n--- Data Types ---")
|
|
28
|
+
print(df.dtypes)
|
|
29
|
+
|
|
30
|
+
# 7. Generate descriptive statistics
|
|
31
|
+
print("\n--- Descriptive Statistics ---")
|
|
32
|
+
print(df.describe(include="all"))
|
|
33
|
+
|
|
34
|
+
# 8. Check missing values per column
|
|
35
|
+
print("\n--- Missing Values Count ---")
|
|
36
|
+
print(df.isnull().sum())
|
|
37
|
+
|
|
38
|
+
# 9. Display dataset information
|
|
39
|
+
print("\n--- Dataset Info ---")
|
|
40
|
+
df.info()
|
|
41
|
+
'''
|
|
42
|
+
|
|
43
|
+
R_CODE = r'''# 1. Set working directory (adjust path as needed)
|
|
44
|
+
setwd(getwd())
|
|
45
|
+
|
|
46
|
+
# 2. Read the CSV file
|
|
47
|
+
df <- read.csv("clinical_data.csv", stringsAsFactors = FALSE)
|
|
48
|
+
|
|
49
|
+
# 3. Display first 6 records
|
|
50
|
+
cat("--- First 6 Records ---\n")
|
|
51
|
+
print(head(df))
|
|
52
|
+
|
|
53
|
+
# 4. Display last 6 records
|
|
54
|
+
cat("\n--- Last 6 Records ---\n")
|
|
55
|
+
print(tail(df))
|
|
56
|
+
|
|
57
|
+
# 5. Display dimensions (Rows, Columns)
|
|
58
|
+
cat("\n--- Dataset Dimensions ---\n")
|
|
59
|
+
print(dim(df))
|
|
60
|
+
|
|
61
|
+
# 6. Display column names
|
|
62
|
+
cat("\n--- Column Names ---\n")
|
|
63
|
+
print(colnames(df))
|
|
64
|
+
|
|
65
|
+
# 7. Display structure
|
|
66
|
+
cat("\n--- Dataset Structure ---\n")
|
|
67
|
+
str(df)
|
|
68
|
+
|
|
69
|
+
# 8. Generate summary statistics
|
|
70
|
+
cat("\n--- Summary Statistics ---\n")
|
|
71
|
+
print(summary(df))
|
|
72
|
+
|
|
73
|
+
# 9. Check missing values per column
|
|
74
|
+
cat("\n--- Missing Values Count ---\n")
|
|
75
|
+
print(colSums(is.na(df)))
|
|
76
|
+
|
|
77
|
+
# 10. Count complete cases
|
|
78
|
+
complete_count <- sum(complete.cases(df))
|
|
79
|
+
cat(sprintf("\nComplete Cases: %d out of %d\n", complete_count, nrow(df)))
|
|
80
|
+
'''
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def exp1() -> None:
|
|
84
|
+
"""Print complete Python and R programs for Experiment 1."""
|
|
85
|
+
display_experiment(1, "Data Import and Exploration", PYTHON_CODE, R_CODE)
|
|
86
|
+
|