#### main analysis #### rm(list=ls()) library(BB) library(Bhat) library(MASS) serial_data <- read.csv("kyoto_serial_interval_1.csv", header=T) offspring_data <- read.csv("kyoto_offspring_1.csv", header=T) ## setting ## serial_data <- na.omit(serial_data) t <- serial_data[,1] # serial interval r <- offspring_data[,1] # offspring sym <- offspring_data[,2] # symptomatic status(0:asymptomatic, 1:symptomatic) ## discretization ## dlnormd <- function(x,alpha,beta){ y=(plnorm(x+1,alpha,beta)-plnorm(x,alpha,beta)) return(y) } dexpd <- function(x,alpha){ y=(pexp(x+1,alpha)-pexp(x,alpha)) return(y) } dgammad <- function(x,alpha,beta){ y=(pgamma(x+1,alpha,beta)-pgamma(x,alpha,beta)) return(y) } dweibulld <- function(x,alpha,beta){ y=(pweibull(x+1,alpha,beta)-pweibull(x,alpha,beta)) return(y) } f <- dlnormd(1:200,1.43,0.66) # incubation period m <- 6 ## estimation of parameters of pdf of infectiousness ## nlogl <-function(x){ z=0 ## parameters for estimation alpha1=x[1] # parameters for h (h is the distribution of infectiousness relative to disease-age) alpha2=x[2] # parameters for h h <- dgammad(1:200,alpha1,alpha2) #the distribution of infectiousness relative to disease-age #h <- dweibulld(1:200,alpha1,alpha2) ## serial interval ## for(i in 1:nrow(serial_data)){ s <- numeric(100) for(j in 1:100){ tau=1 while(tau