Last updated: 2019-04-08

Checks: 6 0

Knit directory: HHVtransmission/

This reproducible R Markdown analysis was created with workflowr (version 1.2.0). The Report 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(20190318) 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! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

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:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/.Rhistory
    Ignored:    data/.DS_Store
    Ignored:    docs/.DS_Store
    Ignored:    docs/figure/.DS_Store

Untracked files:
    Untracked:  analysis/chunks.R
    Untracked:  data/PHICS_transmission_data.RData
    Untracked:  data/exposure_data.RData

Unstaged changes:
    Modified:   analysis/setup-exposure-data.Rmd

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 R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view them.

File Version Author Date Message
html 2f57367 Bryan Mayer 2019-04-07 Build site.
html 5af6494 Bryan Mayer 2019-03-20 Build site.
Rmd 05626ad Bryan Mayer 2019-03-20 wflow_publish(c(“analysis/about.Rmd”, “analysis/index.Rmd”,

Here, we calculate some of the initial (pre-model) results from the infant cohort and exposure characteristcs. - Demographics - Initial survial curves - Exposure assessment

Demographics

Infant ages

exposure_data %>%
  select(FamilyID, enrollment_age) %>%
  distinct() %>%
  summarize(
        N = n(),
        enroll_median_age_days = median(enrollment_age),
        IQR = paste(quantile(enrollment_age, c(0.25, 0.75)), collapse = ", "),
        range_days = paste(range(enrollment_age), collapse = ", ")
        ) %>%
  kable() %>% kable_styling(full_width = F)
N enroll_median_age_days IQR range_days
32 2 1, 3 0, 9

Mom HIV

exposure_data %>% select(FamilyID, momhiv) %>% 
  distinct() %>%
  group_by(momhiv) %>%
  summarize(N = n()) %>% 
  kable() %>% kable_styling(full_width = F)
momhiv N
neg 15
pos 17

Survival analysis

exposure_data %>% 
  group_by(virus, FamilyID) %>% 
  summarize(obs_infected = max(infectious_1wk),
            is_infected = max(infected)) %>% group_by(virus) %>%
  summarize(
    total_infants = n_distinct(FamilyID),
    total_infected = sum(is_infected),
    total_outcome = sum(obs_infected)
    ) %>%
  kable() %>%
  kable_styling(full_width = F)
virus total_infants total_infected total_outcome
CMV 30 20 16
HHV-6 31 24 23
surv_data = exposure_data %>% 
  group_by(FamilyID, virus, momhiv, final_infant_wk) %>%
  summarize(
    infected = max(infected)
  )

surv_fit = surv_data %>%
  group_by(virus) %>%
  nest() %>%
  mutate(
    surv_mod = map(data, ~survfit(Surv(final_infant_wk, infected) ~ 1, data = .)),
    surv_mod_hiv = map(data, ~survfit(Surv(final_infant_wk, infected) ~ momhiv, data = .)),
    logrank = map_dbl(data, ~coin::pvalue(coin::logrank_test(Surv(final_infant_wk, infected) ~ factor(momhiv),
                                                             data = ., distribution = "exact")))
    ) %>%
  select(-data)

surv_fit %>%
  select(virus, logrank) %>%
  rename(`Mother HIV Log-rank` = logrank) %>%
  kable() %>% kable_styling(full_width = F)
virus Mother HIV Log-rank
CMV 0.9708864
HHV-6 0.3649318
surv_res = pmap_df(surv_fit, function(virus, surv_mod, surv_mod_hiv, logrank){
   broom::tidy(surv_mod) %>%
    mutate(strata = "Pooled") %>%
    bind_rows(broom::tidy(surv_mod_hiv)) %>%
    mutate(
      virus = virus,
      momhiv = str_remove_all(strata, "momhiv=")
      ) %>%
    bind_rows(crossing(virus = virus, time = -1e-12, estimate = 1, momhiv = c("Pooled", "neg", "pos")))
})
surv_res %>%
  arrange(virus, momhiv, time) %>%
  ggplot(aes(time, estimate, colour = momhiv)) + 
  geom_step() +
  geom_point(aes(shape = n.censor > 0)) +
  scale_shape_manual(guide = F, values = c(-1, 3)) +
  scale_x_continuous("Weeks after infant birth", breaks = 0:10 * 10) +
  scale_y_continuous("Proportion uninfected", expand = c(0.01, 0)) +
  geom_vline(xintercept = 52, colour = "black", linetype = "dashed") +
  scale_color_discrete("", breaks = c("neg", "pos", "Pooled"), 
                     labels = c("Mother HIV-", "Mother HIV+", "Pooled")) +
  geom_text(data= surv_fit, aes(label = str_c("p = ", round(logrank, 2))), 
            x = Inf, y = Inf, colour = "black", vjust = 1.2, hjust = 1.2) +
  facet_wrap(~virus) +
  theme_bw() +
  theme(legend.position = "top")

Version Author Date
5af6494 Bryan Mayer 2019-03-20

Exposure Analysis

exposure_data_long %>% 
  group_by(virus, idpar) %>% 
  summarize(total = n()) 
# A tibble: 6 x 3
# Groups:   virus [?]
  virus idpar total
  <chr> <chr> <int>
1 CMV   HH      807
2 CMV   M       807
3 CMV   S       807
4 HHV-6 HH      673
5 HHV-6 M       673
6 HHV-6 S       673
exposure_plots = map(c("CMV", "HHV-6"), function(v){
  surv_cens = exposure_data %>% 
    subset(virus == v) %>%
    group_by(FamilyID, virus, final_infant_wk) %>%
  summarize(
    cens = all(obs_infected == 0),
    final_time = if(!all(cens)) unique(final_infant_wk) else max(infant_wks)
  )
  
  exposure_data_long %>%
    subset(virus == v) %>%
    group_by(FamilyID) %>%
    ggplot(aes(x = infant_wks, y = count, colour = idpar)) + 
    geom_point() + 
    facet_wrap(~FamilyID) + 
    geom_vline(data = surv_cens, aes(xintercept = final_time, linetype = factor(cens))) +
    scale_linetype_discrete(guide = F) +
    ggtitle(v)
  
})


sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.14.4

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

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

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

other attached packages:
 [1] bindrcpp_0.2.2   survminer_0.4.3  ggpubr_0.2       magrittr_1.5    
 [5] survival_2.43-3  kableExtra_1.1.0 forcats_0.3.0    stringr_1.4.0   
 [9] dplyr_0.7.8      purrr_0.3.0      readr_1.3.1      tidyr_0.8.2     
[13] tibble_2.0.1     ggplot2_3.1.0    tidyverse_1.2.1 

loaded via a namespace (and not attached):
 [1] httr_1.4.0        jsonlite_1.6      viridisLite_0.3.0
 [4] splines_3.5.1     modelr_0.1.2      assertthat_0.2.0 
 [7] highr_0.7         stats4_3.5.1      coin_1.2-2       
[10] cellranger_1.1.0  yaml_2.2.0        pillar_1.3.1     
[13] backports_1.1.3   lattice_0.20-38   glue_1.3.0       
[16] digest_0.6.18     rvest_0.3.2       colorspace_1.4-0 
[19] sandwich_2.5-0    cmprsk_2.2-7      htmltools_0.3.6  
[22] Matrix_1.2-15     plyr_1.8.4        pkgconfig_2.0.2  
[25] broom_0.5.1       haven_2.0.0       xtable_1.8-3     
[28] mvtnorm_1.0-8     scales_1.0.0      webshot_0.5.1    
[31] km.ci_0.5-2       whisker_0.3-2     KMsurv_0.1-5     
[34] git2r_0.24.0      generics_0.0.2    TH.data_1.0-10   
[37] withr_2.1.2       lazyeval_0.2.1    cli_1.0.1        
[40] crayon_1.3.4      readxl_1.2.0      evaluate_0.12    
[43] fansi_0.4.0       fs_1.2.6          nlme_3.1-137     
[46] MASS_7.3-51.1     xml2_1.2.0        tools_3.5.1      
[49] data.table_1.12.0 hms_0.4.2         multcomp_1.4-8   
[52] munsell_0.5.0     compiler_3.5.1    rlang_0.3.1      
[55] grid_3.5.1        rstudioapi_0.9.0  labeling_0.3     
[58] rmarkdown_1.8     codetools_0.2-16  gtable_0.2.0     
[61] R6_2.3.0          gridExtra_2.3     zoo_1.8-4        
[64] lubridate_1.7.4   knitr_1.21        utf8_1.1.4       
[67] survMisc_0.5.5    bindr_0.1.1       workflowr_1.2.0  
[70] rprojroot_1.3-2   modeltools_0.2-22 stringi_1.2.4    
[73] Rcpp_1.0.0        tidyselect_0.2.5  xfun_0.4