Last updated: 2023-06-16

Checks: 7 0

Knit directory: eGFRslopes/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20230613) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 7de25c8. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .RData
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  analysis/04longitudinal.Rmd
    Untracked:  analysis/05survival.Rmd
    Untracked:  analysis/07extractSlopes.Rmd
    Untracked:  analysis/misc_performanceChecks.Rmd
    Untracked:  code/calculateEGFR.R
    Untracked:  code/extractSlopes.R
    Untracked:  code/flagAKI.R
    Untracked:  code/syntheticData.R
    Untracked:  data/simulated_longitudinal_data.csv
    Untracked:  data/simulated_metadata.csv
    Untracked:  output/eGFR_meta.csv
    Untracked:  output/eGFR_minimal.csv
    Untracked:  output/eGFR_minimal_surv.csv
    Untracked:  output/fitJMbayes.RDS
    Untracked:  output/flagged_episodes.csv
    Untracked:  output/longitudinal_data.csv
    Untracked:  output/pred_long.csv

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/00syntheticData.Rmd) and HTML (docs/00syntheticData.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 7de25c8 Charlotte Boys 2023-06-16 Publish main parts of framework

Introduction

To demonstrate the inference of eGFR slopes with a joint modelling approach using open-source R packages, we first create a synthetic dataset. We simulate a patient cohort consisting of 100 patients sampled from two disease groups “Disease A” and “Disease B”.

The support functions which we use to simulate our data can be found in the script code/syntheticData.R.

Load necessary libraries:

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.2     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Load support functions:

source("code/syntheticData.R")

Simulate the dataset

Simulate patient metadata for our synthetic cohort:

patient_metadata <- sim_cohort_metadata(n_patients = 100)
knitr::kable(head(patient_metadata))
patient_id sex disease age_at_biopsy
1 M B 29
2 M A 79
3 M B 35
4 F B 60
5 M A 43
6 F B 80

Simulate longitudinal data:

longitudinal_data <- sim_cohort_longitudinal_data(n_patients = 100,
                                                  patient_metadata = patient_metadata)
knitr::kable(head(longitudinal_data))
patient_id years_from_biopsy measurement type units days_from_biopsy
1 0.0054757 107.02514 SCr umol/L 2
1 0.0191650 107.14072 SCr umol/L 7
1 0.0273785 101.41421 SCr umol/L 10
1 0.0301164 106.18664 SCr umol/L 11
1 0.7091034 95.95474 SCr umol/L 259
1 0.9637235 95.74575 SCr umol/L 352

The simulated longitudinal data currently contains two types of measurements:

unique(longitudinal_data$type)
[1] "SCr"      "Dialysis"

We have a range of follow-up times. Some dropout is random, due to time of biopsy relative to the end of follow-up, and we also have dropout not-at-random due to dialysis.

endpoint_date <- longitudinal_data %>%
  dplyr::filter(type == "Dialysis") %>%
  dplyr::transmute(patient_id = patient_id, endpoint_years = years_from_biopsy)

to_plot <- longitudinal_data %>%
  dplyr::full_join(endpoint_date, by = "patient_id") %>%
  dplyr::group_by(patient_id) %>%
  dplyr::summarise(start = 0,
                   end = max(years_from_biopsy),
                   endpoint = min(endpoint_years))

to_plot %>%
  dplyr::mutate(patient_id = forcats::fct_reorder(patient_id, end, .desc = T)) %>% 
  ggplot() +
  geom_segment(aes(x=start,
                     xend=end,
                     y=patient_id,
                     yend=patient_id),
               linewidth=1, lineend = "round") +
  geom_point(aes(x = endpoint, 
                 y = patient_id, color = "Dialysis" ),
             na.rm=TRUE) + 
  labs(x = "Follow-up time", y = "Patient", color = "Endpoint reached") +
  theme(axis.ticks.y = element_blank(),
        axis.text.y = element_blank(),
        legend.position = c(0.85, 0.93))

Plot longitudinal SCr measurements for the first eight patients:

longitudinal_data %>%
  dplyr::filter(patient_id %in% 1:8) %>%
  ggplot(aes(x = years_from_biopsy,
             y = measurement)) +
  geom_point(size = 1) +
  xlim(0, 20) +
  facet_wrap(vars(patient_id), nrow = 2)

Save patient metadata and longitudinal data:

write.csv(patient_metadata, "data/simulated_metadata.csv", row.names = FALSE)
write.csv(longitudinal_data, "data/simulated_longitudinal_data.csv", row.names = FALSE)

sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.4

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Rome
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] lubridate_1.9.2 forcats_1.0.0   stringr_1.5.0   dplyr_1.1.2    
 [5] purrr_1.0.1     readr_2.1.4     tidyr_1.3.0     tibble_3.2.1   
 [9] ggplot2_3.4.2   tidyverse_2.0.0 workflowr_1.7.0

loaded via a namespace (and not attached):
 [1] sass_0.4.6       utf8_1.2.3       generics_0.1.3   stringi_1.7.12  
 [5] hms_1.1.3        digest_0.6.31    magrittr_2.0.3   timechange_0.2.0
 [9] evaluate_0.21    grid_4.3.0       fastmap_1.1.1    rprojroot_2.0.3 
[13] jsonlite_1.8.5   processx_3.8.1   whisker_0.4.1    ps_1.7.5        
[17] promises_1.2.0.1 httr_1.4.6       fansi_1.0.4      scales_1.2.1    
[21] jquerylib_0.1.4  cli_3.6.1        rlang_1.1.1      munsell_0.5.0   
[25] withr_2.5.0      cachem_1.0.8     yaml_2.3.7       tools_4.3.0     
[29] tzdb_0.4.0       colorspace_2.1-0 httpuv_1.6.11    vctrs_0.6.2     
[33] R6_2.5.1         lifecycle_1.0.3  git2r_0.32.0     fs_1.6.2        
[37] pkgconfig_2.0.3  callr_3.7.3      pillar_1.9.0     bslib_0.4.2     
[41] later_1.3.1      gtable_0.3.3     glue_1.6.2       Rcpp_1.0.10     
[45] highr_0.10       xfun_0.39        tidyselect_1.2.0 rstudioapi_0.14 
[49] knitr_1.43       farver_2.1.1     htmltools_0.5.5  labeling_0.4.2  
[53] rmarkdown_2.22   compiler_4.3.0   getPass_0.2-2