Last updated: 2020-01-23

Checks: 7 0

Knit directory: HHVtransmission/

This reproducible R Markdown analysis was created with workflowr (version 1.4.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(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 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 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
    Ignored:    output/.DS_Store
    Ignored:    output/preprocess-model-data/.DS_Store

Untracked files:
    Untracked:  data/tmp/

Unstaged changes:
    Modified:   analysis/setup-exposure-data.Rmd
    Modified:   analysis/transmission-risk-sensitivity.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
Rmd af2a4c1 Bryan 2019-12-30 all updates after co-author review; edits to tables/figs; ID75
html af2a4c1 Bryan 2019-12-30 all updates after co-author review; edits to tables/figs; ID75
Rmd 54f6c39 Bryan 2019-11-10 separate pre-process model data and update index
html 54f6c39 Bryan 2019-11-10 separate pre-process model data and update index

Model data processing

Set up model data. Only pre-processing is removing left censored family starting at week 8.

library(tidyverse)
── Attaching packages ─────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
✔ ggplot2 3.2.1     ✔ purrr   0.3.3
✔ tibble  2.1.3     ✔ dplyr   0.8.3
✔ tidyr   1.0.0     ✔ stringr 1.4.0
✔ readr   1.3.1     ✔ forcats 0.4.0
── Conflicts ────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(conflicted)
exposure_data = read_csv("data/exposure_data.csv") 
Parsed with column specification:
cols(
  FamilyID = col_character(),
  virus = col_character(),
  infant_wks = col_double(),
  infectious_1wk = col_double(),
  final_infant_wk = col_double(),
  infected = col_double(),
  momhiv = col_character(),
  final_exposure = col_double(),
  interpolate_idpar = col_character(),
  M = col_double(),
  S = col_double(),
  HH = col_double(),
  obs_infected = col_double(),
  final_wk = col_double(),
  outcome_time = col_double(),
  enrollment_age = col_double()
)
exposure_data_long = read_csv("data/exposure_data_long.csv") %>%
  mutate(exposure = if_else(count == 1, 0, 10^(count)))
Parsed with column specification:
cols(
  FamilyID = col_character(),
  virus = col_character(),
  infant_wks = col_double(),
  infectious_1wk = col_double(),
  final_infant_wk = col_double(),
  infected = col_double(),
  momhiv = col_character(),
  final_exposure = col_double(),
  interpolate_idpar = col_character(),
  obs_infected = col_double(),
  final_wk = col_double(),
  outcome_time = col_double(),
  enrollment_age = col_double(),
  idpar = col_character(),
  count = col_double(),
  interpolated = col_logical()
)
exposure_data_long %>%
  subset(idpar != "HH") %>%
  group_by(virus, FamilyID, idpar) %>%
  mutate(any_interp = any(interpolated)) %>%
  subset(any_interp) %>%
  summarize(
    first_obs = min(which(is.na(interpolate_idpar)))
  ) %>%
  subset(first_obs > 2)
# A tibble: 2 x 4
# Groups:   virus, FamilyID [2]
  virus FamilyID idpar first_obs
  <chr> <chr>    <chr>     <int>
1 CMV   AD       S             8
2 HHV-6 AD       S             8
model_data = exposure_data %>% mutate(cohort = "All") %>% subset(FamilyID != "AD")
model_data_long = exposure_data_long %>% mutate(cohort = "All")  %>% subset(FamilyID != "AD")

save(model_data, model_data_long, file = "output/preprocess-model-data/model_data.RData")

Model background

The probability of being uninfected after a single, weekly exposure can written as following:

\[ s(i) = exp(-\beta_0 - \beta_{E}E_i) \] or \[ s(i) = exp(-\lambda(i)) \]

Instead of continuous time, we consider discretized time denoted by \(i \in \{1, ..., n+1\}\) for n+1 weeks of exposures (with n survived exposures). The likelihood follows for a single, infected participant (note that in discrete time we don’t apply an instantaneous hazard but use 1 - S(n) for the infectious week):

\[ L_j(n_j+1) = \prod_{i = 1}^{n_j} s_j(i) * (1-s_j(n_j+1))\]

for the j\(^{th}\) participant with a unique set of total exposures. We next setup the log-likelihood for the population (m participants) and use \(\Delta\) to denote an observed infection.

\[ \sum_{j = 1}^{m} log L_j(n_j) = \sum_{j = 1}^{m}\sum_{i = 1}^{n_j} log(s_j(i)) + \sum_{j = 1}^{m} \Delta_j * log(1-s_j(n_j+1))\]

The following assumptions are used: at-risk individuals are independent and the risk associated with a weekly exposures is unique from other exposures (i.e., non-infectious exposure weeks are exchangeable). From this formulation, we can find the maximum likelihood estimators for the parameters by minimizing the negative log likelihood. Both parameters are solved numerically.

The null model has the following form for weekly risk:

\[ s_0(i) = exp(-\beta_0) \]

I.e., risk is constant and not affected by household exposure. The null model has a simplified log-likelihood

\[ \sum_{j = 1}^{m} log L_j(n_j) = -\beta_0 \sum_{j = 1}^{m}n_j + log(1-exp(-\beta_0)) \sum_{j = 1}^{m} \Delta_j \]

with closed-form solution for the null risk

\[\hat{\beta_0} = -log(1 - \frac{\sum_{j = 1}^{m} \Delta_j}{\sum_{j = 1}^{m}n_j})\]


sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.2

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/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] conflicted_1.0.4 forcats_0.4.0    stringr_1.4.0    dplyr_0.8.3     
 [5] purrr_0.3.3      readr_1.3.1      tidyr_1.0.0      tibble_2.1.3    
 [9] ggplot2_3.2.1    tidyverse_1.2.1 

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.5 xfun_0.10        haven_2.1.1      lattice_0.20-38 
 [5] colorspace_1.4-1 vctrs_0.2.0      generics_0.0.2   htmltools_0.4.0 
 [9] yaml_2.2.0       utf8_1.1.4       rlang_0.4.2      pillar_1.4.2    
[13] glue_1.3.1       withr_2.1.2      modelr_0.1.5     readxl_1.3.1    
[17] lifecycle_0.1.0  munsell_0.5.0    gtable_0.3.0     workflowr_1.4.0 
[21] cellranger_1.1.0 rvest_0.3.5      evaluate_0.14    memoise_1.1.0   
[25] knitr_1.25       fansi_0.4.0      broom_0.5.2      Rcpp_1.0.3      
[29] scales_1.1.0     backports_1.1.5  jsonlite_1.6     fs_1.3.1        
[33] hms_0.5.1        digest_0.6.23    stringi_1.4.3    grid_3.6.1      
[37] rprojroot_1.3-2  cli_1.1.0        tools_3.6.1      magrittr_1.5    
[41] lazyeval_0.2.2   crayon_1.3.4     whisker_0.4      pkgconfig_2.0.3 
[45] zeallot_0.1.0    xml2_1.2.2       lubridate_1.7.4  assertthat_0.2.1
[49] rmarkdown_1.17   httr_1.4.1       rstudioapi_0.10  R6_2.4.1        
[53] nlme_3.1-142     git2r_0.26.1     compiler_3.6.1