# Load the PharmaDatasets package
using PharmaDatasets
Module 2: Data Wrangling and Visualization in Julia (Exercises)
1 Module Introduction and Objectives
The target audience are pharmacometricians with experience in the R programming and statistical language and familiar with dataset preparation and exploratory data analysis in pharmacometrics. The Module makes reference to similarities and differences to R and builds on the concepts described in Module 1: Introduction to Julia.
The concepts and Julia packages showcased in this Module are:
- Reading and writing data: CSV.jl and ReadStatTables.jl
- Piping practices: Chain.jl
- Manipulating data frames: DataFrames.jl and DataFramesMeta.jl
- Handling categorical variables: Categorical Arrays.jl
- Handling date/time variables: Dates.jl
- Plotting and visualization: CairoMakie.jl and AlgebraOfGraphics.jl
All output DataFrames have been converted for presentation purposes using SummaryTables.jl.
1.1 Objectives
The objectives of the Module 2 exercises are to:
- Perform an exploratory data analysis on an example dataset and re-create the figures and tables presented using Julia
- Bonus Challenge: translate your existing analysis code for exploratory data analysis and data summaries from R (or current programming language) to Julia
The exercises are designed to be challenging and require reference to the Module materials and package documentation.
2 Exercise Setup
To obtain the example analysis dataset for all exercises, the PharmaDatasets
package needs to be loaded. This is not the only package required to complete the exercises and you will need to load any additional packages.
The example analysis dataset can be obtained by:
# Load the warfarin dataset
= dataset("paganz2024/warfarin_long") warfarin_df
3 Summary Table of Demographics
Generate a summary table of the analysis population that appears as below:
Characteristic | Total (n = 31) |
Age (years) | |
Mean (SD) | 30.4 (10.1) |
Median (Min, Max) | 27.0 (21.0, 63.0) |
Missing (%) | 0 (0.00) |
Body Weight (kg) | |
Mean (SD) | 70.1 (12.9) |
Median (Min, Max) | 73.3 (40.0, 102.) |
Missing (%) | 0 (0.00) |
Sex; n (%) | |
Female | 5 (16.1) |
Male | 26 (83.9) |
Missing | 0 (0.00) |
The aesthetics of the example table is only for presentation purposes only.
4 Summary of Observations Over Time
Create a numerical summary (mean and 90% confidence interval) of pharmacokinetic [PK] (DVID = 1) and pharmacodynamic [PD] (DVID = 2) observations over time, stratified by sex:
Row | SEX | DVID | TIME | nid | mean_val | sd_val | lo90_val | hi90_val |
---|---|---|---|---|---|---|---|---|
Cat… | String | Float64 | Int64 | Float64 | Float64 | Float64 | Float64 | |
1 | Female | Warfarin Concentration (mg/L) | 0.5 | 2 | 0.0 | 0.0 | 0.0 | 0.0 |
2 | Female | Warfarin Concentration (mg/L) | 1.0 | 3 | 3.43333 | 2.87112 | -0.467701 | 7.33437 |
3 | Female | Warfarin Concentration (mg/L) | 2.0 | 2 | 8.1 | 4.94975 | -2.11995 | 18.3199 |
4 | Female | Warfarin Concentration (mg/L) | 3.0 | 5 | 11.45 | 1.87697 | 9.75856 | 13.1414 |
5 | Female | Warfarin Concentration (mg/L) | 6.0 | 5 | 11.9167 | 0.538207 | 11.4317 | 12.4017 |
6 | Female | Warfarin Concentration (mg/L) | 9.0 | 5 | 11.45 | 1.41527 | 10.1746 | 12.7254 |
7 | Female | Warfarin Concentration (mg/L) | 12.0 | 3 | 10.55 | 1.18181 | 8.94426 | 12.1557 |
8 | Female | Warfarin Concentration (mg/L) | 24.0 | 5 | 7.66 | 1.29923 | 6.48919 | 8.83081 |
9 | Female | Warfarin Concentration (mg/L) | 36.0 | 5 | 6.38 | 1.97028 | 4.60447 | 8.15553 |
10 | Female | Warfarin Concentration (mg/L) | 48.0 | 5 | 4.7 | 1.9975 | 2.89994 | 6.50006 |
11 | Female | Warfarin Concentration (mg/L) | 72.0 | 5 | 3.46 | 1.53721 | 2.07474 | 4.84526 |
12 | Female | Warfarin Concentration (mg/L) | 96.0 | 5 | 1.98 | 1.11669 | 0.973686 | 2.98631 |
13 | Female | Warfarin Concentration (mg/L) | 120.0 | 5 | 1.8 | 0.6245 | 1.23723 | 2.36277 |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
31 | Male | Warfarin Concentration (mg/L) | 48.0 | 26 | 6.26538 | 1.1541 | 5.87934 | 6.65143 |
32 | Male | Warfarin Concentration (mg/L) | 72.0 | 26 | 4.4 | 0.848057 | 4.11633 | 4.68367 |
33 | Male | Warfarin Concentration (mg/L) | 96.0 | 26 | 3.06923 | 0.761981 | 2.81435 | 3.32411 |
34 | Male | Warfarin Concentration (mg/L) | 120.0 | 26 | 2.19615 | 0.619342 | 1.98898 | 2.40332 |
35 | Male | Prothrombin Complex Activity | 0.0 | 26 | 97.1154 | 5.42827 | 95.2996 | 98.9311 |
36 | Male | Prothrombin Complex Activity | 24.0 | 26 | 37.5385 | 5.74965 | 35.6152 | 39.4617 |
37 | Male | Prothrombin Complex Activity | 36.0 | 26 | 24.3077 | 4.1547 | 22.9179 | 25.6974 |
38 | Male | Prothrombin Complex Activity | 48.0 | 26 | 18.8077 | 4.10871 | 17.4333 | 20.1821 |
39 | Male | Prothrombin Complex Activity | 72.0 | 26 | 20.0 | 6.08961 | 17.963 | 22.037 |
40 | Male | Prothrombin Complex Activity | 96.0 | 26 | 24.16 | 8.89138 | 21.1858 | 27.1342 |
41 | Male | Prothrombin Complex Activity | 120.0 | 26 | 32.08 | 11.7754 | 28.1411 | 36.0189 |
42 | Male | Prothrombin Complex Activity | 144.0 | 8 | 34.2857 | 13.925 | 25.1308 | 43.4407 |
5 Plot of Summarized Observations Over Time
Re-create the following plot of the summarized PK and PD observations over time: