Description Usage Arguments Details Value Examples
View source: R/simulate_general_outbreaks.R
Simulate the branching process of flipping until failure for K clusters
1 2 3 4 5 6 7 8 | simulate_bp(
K,
inf_params,
sample_covariates_df,
covariate_names,
covariate_weights = NULL,
max_size = 50
)
|
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 |
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)})
data frame with the following columns
unique cluster ID
order of infection in the cluster
generation number (>=0)
ID of the infector
number of people infected by person
whether the cluster end was censored or not
size of the cluster
covariates of the individuals
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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.