File talk:Ferguson influenza generation time distribution.png

出自Wikimedia Commons
跳至導覽 跳至搜尋

R script

[編輯]

This image was created using the following R script:

###Calculating R_0 from the Ferguson function for g(t) in influenza
#The unit of time here is days
#Parameters are taken from Ferguson 2005


############################################################
# Latency period                                           # 
############################################################
# page 10 in Ferguson's supplementary material             #
#                                                          #
# "right-shifted Weibull distribution with a               #
# fixed offset of 0.5 days, power parameter 2.21           # 
# (95% CI: 1.36-3.37) and scale parameter 1.10             #
# (95% CI: 0.83-1.42) ñ giving a mean incubation           #
# period of 1.48 days and standard deviation of            #
# 0.47 days"                                               #
############################################################

###Weibull distribution for the latency.
shape=2.21
scale=1.10
latency.Ferguson <- function(t) dweibull(t, shape=shape, scale=scale)
curve(latency.Ferguson,main="Latency (Weibull)") #Is it pretty?

############################################################
# distribution of infectiousness after latency             # 
############################################################
# page 10 in Ferguson's supplementary material             #
#                                                          #
# "We assumed ? (T ) had a lognormal form ? (T;d;?)"       #
#                                                          #
# Table SI1 page 12 in Ferguson's supplementary material   #
#                                                          #
# d(log(day)) = -0.72                                      #
# ? (log(day)) = 1.8                                       # 
############################################################

###Log-normal distribution for period of infectiousness
meanlog=-0.72
sdlog=1.8
infectiousness.Ferguson <- function(t) dlnorm(t, meanlog=meanlog, sdlog=sdlog)
curve(infectiousness.Ferguson,main="Infectiousness (log-normal)") #Is it pretty?
#g(t) is the convolution of the two functions
time.step = 0.001
latency.Ferguson.numerical <- latency.Ferguson(seq(0,10,time.step))
infectiousness.Ferguson.numerical <- infectiousness.Ferguson(seq(0,10,time.step))
g.Ferguson.numerical <- convolve(latency.Ferguson.numerical,rev(infectiousness.Ferguson.numerical),type="open")
g.Ferguson.numerical.scaled <- g.Ferguson.numerical/(time.step*sum(g.Ferguson.numerical))
g.Ferguson <- approxfun(c(0,seq(0.5,10.5,time.step)),c(0,g.Ferguson.numerical.scaled[1:length(seq(0.5,10.5,time.step))]))
curve(g.Ferguson,main="Ferguson g(t)",xlab="Time (days)",ylab="Generation time probability density",xlim=c(0,10),ylim=c(0,0.5))