Converts a transmission matrix from the get_transmat
function into a phylo
class object.
Arguments
- x
An object of class
transmat
, the output fromget_transmat
.- vertex.exit.times
Optional numeric vector providing the time of departure of vertices, to be used to scale the lengths of branches reaching to the tips. Index position on vector corresponds to network id. NA indicates no departure, so branch will extend to the end of the tree.
- ...
Further arguments (unused).
Details
Converts a transmat
object containing information about the
history of a simulated infection into a phylo
object
representation suitable for plotting as a tree with
plot.phylo
. Each infection event becomes a 'node'
(horizontal branch) in the resulting phylo
tree, and each network
vertex becomes a 'tip' of the tree. The infection events are labeled with the
vertex ID of the infector to make it possible to trace the path of infection.
The infection timing information is included to position the phylo-nodes,
with the lines to the tips drawn to the max time value +1 (unless
vertex.exit.times
are passed in it effectively assumes all vertices
are active until the end of the simulation).
If the transmat
contains multiple infection seeds (there are multiple
trees with separate root nodes), this function will return a list of class
multiPhylo
, each element of which is a phylo
object. See
read.tree
.
Examples
set.seed(13)
# Fit a random mixing TERGM with mean degree of 1 and mean edge
# duration of 20 time steps
nw <- network_initialize(n = 100)
formation <- ~edges
target.stats <- 50
coef.diss <- dissolution_coefs(dissolution = ~offset(edges), duration = 20)
est <- netest(nw, formation, target.stats, coef.diss, verbose = FALSE)
#> Starting maximum pseudolikelihood estimation (MPLE):
#> Obtaining the responsible dyads.
#> Evaluating the predictor and response matrix.
#> Maximizing the pseudolikelihood.
#> Finished MPLE.
# Parameterize the epidemic model as SI with one infected seed
param <- param.net(inf.prob = 0.5)
init <- init.net(i.num = 1)
control <- control.net(type = "SI", nsteps = 40, nsims = 1, verbose = FALSE)
# Simulate the model
mod1 <- netsim(est, param, init, control)
# Extract the transmission matrix
tm <- get_transmat(mod1)
head(tm, 15)
#> # A tibble: 15 × 8
#> # Groups: at, sus [15]
#> at sus inf network infDur transProb actRate finalProb
#> <dbl> <int> <int> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 2 93 97 1 4 0.5 1 0.5
#> 2 11 34 97 1 13 0.5 1 0.5
#> 3 30 91 34 1 19 0.5 1 0.5
#> 4 31 12 91 1 1 0.5 1 0.5
#> 5 32 30 12 1 1 0.5 1 0.5
#> 6 34 64 30 1 2 0.5 1 0.5
#> 7 35 55 12 1 4 0.5 1 0.5
#> 8 36 61 30 1 4 0.5 1 0.5
#> 9 37 38 61 1 1 0.5 1 0.5
#> 10 37 58 55 1 2 0.5 1 0.5
#> 11 38 46 38 1 1 0.5 1 0.5
#> 12 38 63 97 1 40 0.5 1 0.5
#> 13 39 82 55 1 4 0.5 1 0.5
#> 14 40 51 46 1 2 0.5 1 0.5
#> 15 40 75 82 1 1 0.5 1 0.5
# Convert to phylo object and plot
tmPhylo <- as.phylo.transmat(tm)
par(mar = c(1,1,1,1))
plot(tmPhylo, show.node.label = TRUE,
root.edge = TRUE,
cex = 0.75)