| Title: | Estimate Transmission Assortativity Coefficients |
| Version: | 0.1.0 |
| Description: | Estimates group transmission assortativity coefficients from transmission trees. Group transmission assortativity coefficients measure the tendency for individuals to transmit within their own group (e.g. age group, vaccination status, or location) compared to other groups. The package requires information on who infected whom, group membership for all individuals, and the relative sizes of each group in the population. For more details see Geismar et al. (2024) <doi:10.1371/journal.pone.0313037>. |
| License: | CC BY 4.0 |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0), pak, epicontacts, visNetwork |
| Config/testthat/edition: | 3 |
| Depends: | R (≥ 3.5) |
| LazyData: | true |
| VignetteBuilder: | knitr |
| URL: | https://github.com/CyGei/linktree, https://cygei.github.io/linktree/ |
| BugReports: | https://github.com/CyGei/linktree/issues |
| NeedsCompilation: | no |
| Packaged: | 2025-12-09 19:18:40 UTC; cy |
| Author: | Cyril Geismar |
| Maintainer: | Cyril Geismar <c.geismar21@imperial.ac.uk> |
| Repository: | CRAN |
| Date/Publication: | 2025-12-15 18:30:02 UTC |
Check 'alpha' value
Description
Check 'alpha' value
Usage
check_alpha(alpha)
Arguments
alpha |
A numeric value between 0 and 1. |
Check 'delta' value
Description
Check 'delta' value
Usage
check_delta(delta)
Arguments
delta |
A numeric vector between -1 and 1. |
Check 'f' levels
Description
Check 'f' levels
Usage
check_flevels(f, levels)
Arguments
f |
A named numeric vector with non-negative values. |
levels |
The groups in the data. |
Check 'from' and 'to' vectors
Description
Check 'from' and 'to' vectors
Usage
check_fromto(from, to)
Arguments
from |
A vector of infectors. |
to |
A vector of infectees |
Check 'gamma' value
Description
Check 'gamma' value
Usage
check_gamma(gamma)
Arguments
gamma |
A numeric vector with non-negative values. |
Check 'x' and 'n' values
Description
Check 'x' and 'n' values
Usage
check_xn(x, n)
Arguments
x |
Number of successes. |
n |
Number of trials. |
Convert delta to gamma
Description
Convert delta to gamma
Usage
delta2gamma(delta)
Arguments
delta |
A numeric vector of delta coefficients. |
Value
A numeric vector of the corresponding gamma coefficients.
Examples
delta2gamma(delta = c(-1,0,1))
Convert gamma to delta
Description
Convert gamma to delta
Usage
gamma2delta(gamma)
Arguments
gamma |
A numeric vector of gamma coefficients. |
Value
A numeric vector delta coefficients.
Examples
gamma2delta(gamma = c(0,1,10, Inf))
Calculate delta
Description
Computes the scaled tansmission assortativity coefficient, see function gamma2delta.
Usage
get_delta(from, to, f, alpha = 0.05)
Arguments
from |
A vector of infectors. |
to |
A vector of infectees. |
f |
A named numeric value representing the prevalence of each group in the population or directly the group sizes. |
alpha |
The significance level for the confidence interval. |
Value
A data frame with the estimated delta, lower and upper confidence limits for each group.
Examples
from <- c("A", "A", NA, "C", "C", "C")
to <- c("A", "B", "B", "C", "C", "C")
f <- c(A = 0.3, B = 0.2, C = 0.5)
get_delta(from, to, f, alpha = 0.05)
Calculate gamma
Description
Computes the tansmission assortativity coefficient defined as the excess probability of a secondary infection taking place within-group compared to random expectations.
Usage
get_gamma(from, to, f, alpha = 0.05)
Arguments
from |
A vector of infectors. |
to |
A vector of infectees. |
f |
A named numeric value representing the prevalence of each group in the population or directly the group sizes. |
alpha |
The significance level for the confidence interval. |
Value
A data frame with the estimated gamma, lower and upper confidence limits for each group.
Examples
from <- c("A", "A", NA, "C", "C", "C")
to <- c("A", "B", "B", "C", "C", "C")
f <- c(A = 0.3, B = 0.2, C = 0.5)
get_gamma(from, to, f, alpha = 0.05)
Calculate Pi Values
Description
Calculates the within-group transmission proportion 'pi' for each group in the data.
Usage
get_pi(from, to, alpha = 0.05)
Arguments
from |
A vector of infectors. |
to |
A vector of infectees. |
alpha |
The significance level for the confidence intervals. |
Value
A data frame with the group names and the corresponding 'pi' values and confidence intervals.
Examples
from <- c("A", "A", "NA", "C", "C", "C")
to <- c("A", "B", "B", "C", "C", "C")
get_pi(from, to, alpha = 0.05)
Plot linktree objects
Description
Plots error bars for objects of class linktree (with subclasses gamma, delta, or pi).
The method displays point estimates with confidence intervals for each group.
A horizontal dotted line is added at the neutral value: y = 1 for subclass gamma and y = 0 for subclass delta.
Usage
## S3 method for class 'linktree'
plot(x, ...)
Arguments
x |
An object of class |
... |
Additional arguments passed to the base |
Value
No return value, called for side effects (produces a plot).
Examples
from <- c("A", "A", NA, "C", "C", "C")
to <- c("A", "B", "B", "C", "C", "C")
f <- c(A = 0.3, B = 0.2, C = 0.5)
plot(get_delta(from, to, f))
plot(get_gamma(from, to, f))
Simulated transmission tree
Description
This dataset represents a simulated transmission tree.
This simulation was generated using the R package o2groups (see https://github.com/CyGei/o2groups for more information).
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:
pak::pak("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)
)
Usage
sim_tree
Format
A data frame with 373 rows and 6 columns:
- group
Character. The group to which the individual belongs.
- id
Character. Unique identifier for each individual in the study.
- source
Character. The ID of the individual who was the source of infection, if known.
NAindicates an unknown source.- source_group
Character. The group of the source individual.
NAfor unknown sources.- date_infection
Numeric. The date of infection. Represented as the number of days since the start of the study.
- 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.