simulate_bp: Simulate the branching process of flipping until failure for...

Description Usage Arguments Details Value Examples

View source: R/simulate_general_outbreaks.R

Description

Simulate the branching process of flipping until failure for K clusters

Usage

1
2
3
4
5
6
7
8
simulate_bp(
  K,
  inf_params,
  sample_covariates_df,
  covariate_names,
  covariate_weights = NULL,
  max_size = 50
)

Arguments

K

number of total clusters to simulate

inf_params

vector with beta coefficients to use in logistic function for probability of transmission

sample_covariates_df

Data frame of covariates to sample from

covariate_names

names of the covariates. Must match size of inf_params - 1.

covariate_weights

default is NULL which draws uniformly at random with replacement from the sample_covariates_df. Otherwise, the weights are used.

max_size

maximum size a cluster can be

Details

Generate a branching process according to the following process. First a root infector is drawn covariates X from some distribution $F$ (given by the set of covariates in sample_covariates_df) and has probability of transmission according to a logit function. The number of infections produced by the root node $N_(1,1) is a geometric random variable with probability $p_(1,1)$ where the indexing represents $(g=$, generation, $i=$ index). If $N_(1,1) > 0$, then the $N_(1,1)$ infections are added to the cluster and assigned to generation $g=2$ with indices $i=1, ..., N_(1,1)$ and covariats are drawn for these new infections. The infection process continues with individuals $(2, 1)$ through $(2, $N_(1,1))$ where new infections are added, in order to the subsequent generation. The process terminates when either there are no new infections or the maximum number of infections specified in max_size is reached.

X_{(g,i)} \sim F

p_{(g,i)} = logit^{-1}≤ft ( X_{(g,i)} β\right )

N_{(g,i)} \sim Geometric(p_{(g,i)})

Value

data frame with the following columns

cluster_id

unique cluster ID

person_id

order of infection in the cluster

gen

generation number (>=0)

inf_id

ID of the infector

n_inf

number of people infected by person

censored

whether the cluster end was censored or not

cluster_size

size of the cluster

covariates

covariates of the individuals

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
set.seed(2020)
inf_params <- c("beta_0" = -2, "beta_1" = 2)
df <- data.frame(x= c(0, 1))
branching_processes <- simulate_bp(K = 10,
inf_params = inf_params,
covariate_names = "x",
sample_covariates_df = df)
head(branching_processes)
table(branching_processes$cluster_size) /
sort(unique(branching_processes$cluster_size))

skgallagher/InfectionTrees documentation built on July 28, 2021, 2:14 p.m.