Skip to content

Commit

Permalink
Removing o2groups dependency in the vignette (causing error) by addin…
Browse files Browse the repository at this point in the history
…g sim_tree.rda instead.
  • Loading branch information
CyGei committed Jan 25, 2025
1 parent 4f7b6c9 commit 9ae81ea
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 67 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ jobs:
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- name: Install o2groups from GitHub
run: |
R -e "remotes::install_github('CyGei/o2groups')"
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:

name: test-coverage.yaml

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
7 changes: 2 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0),
remotes,
dplyr,
pacman,
epicontacts,
visNetwork
Remotes:
CyGei/o2groups
Config/testthat/edition: 3
Depends:
R (>= 2.10)
R (>= 3.5)
LazyData: true
VignetteBuilder: knitr
30 changes: 22 additions & 8 deletions R/simulated_tree.R → R/sim_tree.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
#'Simulated transmission tree
#' A simulated transmission tree generated from the `o2groups` package.
#' Simulated transmission tree
#'
#' This dataset represents a simulated infection transmission tree, capturing the spread of an infectious disease within groups.
#' This dataset represents a simulated transmission tree.
#' This simulation was generated using the R package `o2groups` (see \url{https://github.com/CyGei/o2groups} for more information).
#' Group `A` is assortative with a delta coefficient of 0.75 and group `B` is neutral with a delta coefficient of 0.
#' Both group sizes were set at 100 individuals.
#'
#' @format A data frame with 151 rows and 6 columns:
#' Group `HCW` is assortative with a gamma coefficient of 2 and group `patient` is disassortative with a gamma coefficient of 1/1.25.
#' Suceptible group sizes were 100 and 350, respectively.
#' Code to reproduce the data below:
#' ```
#' pacman::p_load_gh("CyGei/o2groups")
#' set.seed(123)
#' sim_tree <- o2groups::simulate_groups(
#' duration = 100,
#' group_n = 2,
#' size = c(100, 350), # susceptible group sizes
#' name = c("HCW", "patient"),
#' gamma = c(2, 0.8), # assortativity coefficients
#' intro_n = c(1, 3),
#' r0 = c(2, 2),
#' generation_time = c(0, 0.1, 0.2, 0.4, 0.2, 0.1, 0),
#' incubation_period = sample(1:14, 1000, replace = TRUE)
#' )
#'```
#' @format A data frame with 373 rows and 6 columns:
#' \describe{
#' \item{group}{Character. The group to which the individual belongs.}
#' \item{id}{Character. Unique identifier for each individual in the study.}
Expand All @@ -16,4 +30,4 @@
#' \item{date_onset}{Numeric. The date of onset of symptoms. Represented as the number of days since the start of the study.}
#' }
#' @source This dataset is simulated (see R package `o2groups`) and does not correspond to real-world data.
"simulated_tree"
"sim_tree"
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ knitr::opts_chunk$set(
<!-- badges: start -->

[![R-CMD-check](https://github.com/CyGei/linktree/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/CyGei/linktree/actions/workflows/R-CMD-check.yaml)

[![Codecov test coverage](https://codecov.io/gh/CyGei/linktree/graph/badge.svg)](https://app.codecov.io/gh/CyGei/linktree)
<!-- badges: end -->

`linktree` is a novel framework that leverages transmission chain data to estimate ***group transmission assortativity***; this quantifies the extent to which individuals transmit within their own group compared to others. The methodology is described in our [paper](https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0313037).
Expand All @@ -36,7 +36,7 @@ knitr::opts_chunk$set(

```{r}
# install.packages("devtools")
devtools::install_github("CyGei/linktree")
# devtools::install_github("CyGei/linktree")
library(linktree)
```

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ linktree
<!-- badges: start -->

[![R-CMD-check](https://github.com/CyGei/linktree/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/CyGei/linktree/actions/workflows/R-CMD-check.yaml)

[![Codecov test
coverage](https://codecov.io/gh/CyGei/linktree/graph/badge.svg)](https://app.codecov.io/gh/CyGei/linktree)
<!-- badges: end -->

`linktree` is a novel framework that leverages transmission chain data
Expand All @@ -27,7 +28,7 @@ others. The methodology is described in our

``` r
# install.packages("devtools")
devtools::install_github("CyGei/linktree")
# devtools::install_github("CyGei/linktree")
library(linktree)
```

Expand Down
4 changes: 0 additions & 4 deletions _pkgdown.yml

This file was deleted.

Binary file added data/sim_tree.rda
Binary file not shown.
Binary file removed data/simulated_tree.rda
Binary file not shown.
35 changes: 25 additions & 10 deletions man/simulated_tree.Rd → man/sim_tree.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 15 additions & 32 deletions vignettes/linktree_vignette.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ The goal of `linktree` is to estimate the transmission assortativity coefficient
## Installation

```{r}
library(remotes)
remotes::install_github("CyGei/linktree")
library(linktree)
pacman::p_load_gh("CyGei/linktree")
```

## Understanding the transmission assortativity coefficient
Expand Down Expand Up @@ -83,39 +81,26 @@ points(1, 0, col = "red", pch = 16) # Homogeneous

### Data

We can simulate an outbreak with multiple groups using the [`o2groups`](https://github.com/CyGei/o2groups) package and then use `linktree` to estimate the assortativity coefficients from the transmission tree.
We can simulate an outbreak with multiple groups using the [`o2groups`](https://github.com/CyGei/o2groups) package and then use `linktree` to estimate the assortativity coefficients from the transmission tree. Below is a pre-loaded simulated transmission tree, see `?sim_tree` for more details.

```{r}
remotes::install_github("CyGei/o2groups")
library(o2groups)
true_gamma <- c(2, 0.8) # assortativity coefficients
set.seed(123)
sim <- simulate_groups(
duration = 100,
group_n = 2,
size = c(100, 400),
name = c("HCW", "patient"),
gamma = true_gamma,
intro_n = c(1, 3),
r0 = c(1.7, 2),
generation_time = c(0, 0.1, 0.2, 0.4, 0.2, 0.1, 0),
incubation_period = sample(1:14, 1000, replace = TRUE)
)
head(sim)
#?sim_tree
true_gammas <- c(HCW = 2, patient = 1/1.25)
sizes <- c(HCW = 100, patient = 350)
data(sim_tree)
head(sim_tree)
```

### Visualise the transmission tree

```{r, message=FALSE}
```{r, message=FALSE, warning=FALSE}
remotes::install_github('reconhub/epicontacts@timeline')
library(dplyr)
library(epicontacts)
library(visNetwork)
x <- epicontacts::make_epicontacts(
linelist = dplyr::select(sim, c(group, id, date_infection, date_onset)),
contacts = dplyr::select(sim, c(source, id, source_group, group)),
linelist = sim_tree[, c("group", "id", "date_infection", "date_onset")],
contacts = sim_tree[, c("source", "id", "source_group", "group")],
id = "id",
from = "source",
to = "id",
Expand All @@ -140,20 +125,18 @@ plot(x,
```

### Estimate the transmission assortativity coefficient


Our published [paper](https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0313037) provides guidelines as to when and under which circumstances we can reliably infer group transmission assortativity. Notably, we should analyse transmission chains up to the group's epidemic peak to avoid the saturation effect, and we should have at least ~30 cases in the group.

```{r, fig.width=8, fig.height=6, message=FALSE}
est_delta <- get_delta(
from = sim$source_group,
to = sim$group,
f = c("HCW" = 100, "patient" = 400),
from = sim_tree$source_group,
to = sim_tree$group,
f = sizes,
)
true_delta <- gamma2delta(true_gamma)
true_deltas <- gamma2delta(true_gammas)
plot(est_delta, main = "Estimated vs True assortativity coefficients")
abline(h = true_delta, col = c("#d53e4f", "#3288bd"), lty = 2)
abline(h = true_deltas, col = c("#d53e4f", "#3288bd"), lty = 2)
legend("topright", legend = c("HCW (truth)", "patient (truth)"), fill = c("#d53e4f", "#3288bd"), bty = "n")
```

Expand Down
Binary file modified vignettes/man/figures/README-unnamed-chunk-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9ae81ea

Please sign in to comment.