Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created May 24, 2026 13:44
Show Gist options
  • Select an option

  • Save abikoushi/bbea122dee25e2b7a0e15b7ab51888b7 to your computer and use it in GitHub Desktop.

Select an option

Save abikoushi/bbea122dee25e2b7a0e15b7ab51888b7 to your computer and use it in GitHub Desktop.
基本再生産数と世代時間の関係
#西浦博 他『感染症流行を読み解く数理』(日本評論社)図3.3
library(dplyr)
library(ggplot2)
R0hat_gamma <- function(m,CV){
r <- 0.135
ab2 <- (m*CV)^2
b <- ab2/m
a <- m/b
int <- integrate(function(x){exp(-r*x)*dgamma(x,shape = a,scale = b)},0,Inf)
return(1/int$value)
}
resdf <- expand.grid(mean=seq(1,6,by=0.1),
CV=seq(0.1,1,by=0.1)) %>%
rowwise() %>%
mutate(R0=R0hat_gamma(mean, CV))
ggplot(resdf, aes(x=mean, y=CV, fill=R0))+
geom_tile(width = 0.1, height = 0.1)+
scale_fill_viridis_c()
ggsave("fig3_3.png", width = 7, height = 7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment