sim.TSIR: Simulate stochastic TSIR

Description Usage Arguments Value Author(s) See Also Examples

View source: R/hmob_funcs.R

Description

This function produces one stochastic realization of a spatial Time series Susceptible-Infected-Recovered model. The simulation expects estimates of the posterior distribution for trip duration decay rate (lambda), probability of movement (pi), and proportion of travellers remaining for a full epidemic generation (rho).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
sim.TSIR(
  districts,
  N,
  tau = NULL,
  lambda = NULL,
  pi,
  rho = NULL,
  beta,
  gamma,
  gen.t,
  I.0,
  max.t = 100,
  duration = TRUE,
  freq.dep = TRUE
)

Arguments

districts

Vector of district names

N

Vector giving the population size of each district

tau

Vector giving the proportion of individuals that travel in each district

lambda

Matrix of trip duration decay for route i to j

pi

Matrix of district connectivity for route i to j

rho

Matrix of proportion of travellers remaining for full generation for route i to j

beta

Transmission rate

gamma

Recovery rate

gen.t

Pathogen generation time (days)

I.0

Vector giving number of infected individuals in each district at time 0

max.t

Maximum number of epidemic generations

freq.dep

Logical indicating frequency (TRUE) or density dependent (FALSE) transmission

Value

a three-dimensional named array giving the numbers of Susceptible, Infected, and Recovered infividuals in each location and time step

Author(s)

John Giles

See Also

Other simulation: calc.hpd(), calc.prop.inf(), calc.prop.remain(), calc.timing.magnitude(), calc.wait.time(), decay.func(), get.age.beta(), get.beta.params(), sim.TSIR.full(), sim.combine.dual(), sim.combine(), sim.gravity.duration(), sim.gravity(), sim.lambda(), sim.pi(), sim.rho(), sim.tau()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
d <- read.csv("./data/trip_durations_longform_metadata_13_34_42_85_10_14_16_99_urban_rural.csv", stringsAsFactors=F)
load('./data/distance_matrix_named.rdata')                         # distance.matrix
load('./data/N_pop.rdata')                                         # N.pop
load('./output/decay_model_route_12dists.Rdata')                   # mod.decay # Decay model parameters (Lambda)
load('./output/gravity_model_route_12dists.Rdata')                 # mod.grav  # Gravity model with duration
load('./output/gravity_model_basic_route_12dists.Rdata')           # mod.grav.basic  # Basic gravity model
load('./data/prop_leave.Rdata')                                    # prop.leave # observed proportion individuals leaving origin at time t in trip duration data  
load('./output/prop_remaining.Rdata')                              # p # observed proportion of individuals remaining for full pathogen generation

districts <- dimnames(M)$origin
n.districts <- length(districts)
N <- round(N.pop$N[N.pop$ID %in% as.integer(districts)])
I.0 <- rep(0, length(districts))
I.0[2] <- 1

# lambda.hat
tmp <- get.param.vals(n.districts=n.districts, name='lambda', level='route', stats=mod.grav)
lambda.hat <- sim.lambda(mu=tmp$mean, sigma=tmp$sd, level='route')

# pi.hat
tmp <- get.param.vals(n.districts=n.districts, name='pi', level='route', stats=mod.grav)
pi.hat <- sim.pi(mu=tmp$mean, level='route')

# pi.hat.basic
tmp <- get.param.vals(n.districts=n.districts, name='pi', level='route', stats=mod.grav.basic)
pi.hat.basic <- sim.pi(mu=tmp$mean, level='route')

# rho.hat
d <- jags.data.array(d=d, time='month', variable='duration', agg.int=1)
p <- calc.p(d=d, gen.t=3)
rho.hat <- sim.rho(p=p, level='route')

# tau.hat
tau.hat <- sim.tau(prop.leave)
tau.hat <- tau.hat[names(tau.hat) %in% districts]

# Simulate measles epidemic using basic gravity model
grav <- sim.TSIR(districts=districts,                 
                 N=N,                                 
                 pi=pi.hat.basic,        # connectivity comes from basic gravity model formulation 
                 tau=tau.hat,            # Probability of leaving district i
                 beta=0.7125,            # Transmission rate
                 gamma=1/21,             # Recovery rate                         
                 gen.t=gen.t,                         
                 max.t=max.t,                         
                 I.0=I.0,                             
                 duration=F,             # do NOT use trip duration in force of infection                 
                 freq.dep=T                           
)

grav[,,1:5]

# Simulate influenza epidemic using gravity model with duration
grav.dur <- sim.TSIR(districts=districts,                 
                     N=N,                                 
                     tau=tau.hat,            # Probability of leaving district i
                     lambda=lambda.hat,      # Matrix of trip duration decay for route i to j 
                     pi=pi.hat,              # Matrix of district connectivity (estimated pi_ijt)
                     rho=rho.hat,            # Matrix of proportion of travellers remaining for full generation when moving from i to j
                     beta=0.5,               # Transmission rate
                     gamma=1/14,             # Recovery rate                          
                     gen.t=gen.t,                         
                     max.t=max.t,                
                     I.0=I.0,                             
                     duration=T,             # Use trip duration in force of infection
                     freq.dep=T                         
)

grav.dur[,,1:5]

gilesjohnr/hmob documentation built on Aug. 8, 2020, 1:26 a.m.