Comments (5)
from covid19model.
from covid19model.
from covid19model.
Hi @flaxter ,
It's more likely I'm the buggy one:
Code
LogMean <- function(realMean, realSD){
## takes REAL mean and REAL standard deviation; returns LOG mean
realVar <- realSD^2
mu <- log(realMean/ sqrt(1 + (realVar/realMean^2)))
return(mu)
}
LogVar <- function(realMean, realSD){
## takes REAL mean and REAL standard deviation; returns LOG variance
realVar <- realSD^2
sigmasq <- log(1 + (realVar/realMean^2))
return(sigmasq)
}
###################
M <- 1e6
kappa_ic <- abs(rnorm(n = M, mean = 0, sd = 1/2))
R0_ic <- abs(rnorm(n = M, mean = 3.28, sd = kappa_ic))
kappa_bram <- abs(rnorm(n = M, mean = 0, sd = 1))
R0_bram <- abs(rnorm(n = M, mean = 2.4, sd = kappa_bram))
m <- 3 # E[R0]
v <- .9^2 # Var(R0)
# Gamma
alpha <- m^2/v
beta <- m/v
#Log-normal
mu <- LogMean(realMean = m, realSD = sqrt(v) )
sigma <- sqrt( LogVar(realMean = m, realSD = sqrt(v) ) )
R0_gamma <- rgamma(n = M, shape = alpha, rate = beta)
R0_ln <- rlnorm(n = M, meanlog = mu, sdlog = sigma)
forplot <- data.frame(R_0 = c(R0_ic,
R0_bram,
R0_gamma,
R0_ln),
study = rep(c("Imperial",
"BRAM-COD",
"Gamma",
"Log-normal"), each = M))
library(ggplot2)
ggplot(forplot, aes(x = R_0, colour = study, fill = study)) +
geom_density(alpha = .4) +
scale_x_continuous(expression(R_0), expand = c(0, 0)) +
scale_y_continuous("Density", expand = c(0, 0)) +
geom_vline(xintercept = 1, linetype = "longdash") +
theme_bw(base_size = 16)
summy <- function(x, na.rm = TRUE){
ans <- data.frame(mean = mean(x, na.rm = na.rm),
sd = sd(x, na.rm = na.rm),
lwr = quantile(x, probs = .025, na.rm = na.rm),
uprr = quantile(x, probs = .975, na.rm = na.rm))
return(ans)
}
lapply(list(bramcod = R0_bram, imperial = R0_ic, Gamma = R0_gamma, LN = R0_ln), summy)
Last line gives
$bramcod
mean sd lwr upr
2.5% 2.435088 0.911255 0.5271803 4.580456
$imperial
mean sd lwr upr
2.5% 3.280113 0.4989465 2.190974 4.374173
$Gamma
mean sd lwr upr
2.5% 2.999272 0.8991958 1.503212 4.995466
$LN
mean sd lwr upr
2.5% 3.00032 0.8997761 1.617084 5.106452
BRAM-COD is a recent Brazilian study with a model based on your model from report 13.
from covid19model.
I realised the script above has a (as of yet inconsequential) bug in the generation of the random samples. Technically, the model specified in Stan is a truncated normal, not a folded normal, so the correct generation of the samples would be something like
M <- 1e6
library(truncnorm)
kappa_ic <- rtruncnorm(n = M, mean = 0, sd = 1/2, a = 0, b = Inf)
R0_ic <- rtruncnorm(n = M, mean = 3.28, sd = kappa_ic, a = 0, b = Inf)
kappa_bram <- rtruncnorm(n = M, mean = 0, sd = 1, a = 0, b = Inf)
R0_bram <- rtruncnorm(n = M, mean = 2.4, sd = kappa_bram, a = 0, b = Inf)
Giving
> lapply(list(bramcod = R0_bram, imperial = R0_ic, Gamma = R0_gamma, LN = R0_ln), summy)
$bramcod
mean sd lwr uprr
2.5% 2.471883 0.9082468 0.6756234 4.67399
$imperial
mean sd lwr uprr
2.5% 3.280978 0.497174 2.192721 4.371233
$Gamma
mean sd lwr uprr
2.5% 2.999731 0.9005028 1.502073 5.006691
$LN
mean sd lwr uprr
2.5% 3.00048 0.9005886 1.616915 5.110658
from covid19model.
Related Issues (20)
- R value in base.stan HOT 2
- Full run: execution halted after 8 hours - no figures HOT 3
- Sweden exception to general intervention effects
- Error "Rejecting initial value" HOT 2
- Updated data HOT 2
- Smoothing reported death data HOT 1
- new release for US report? HOT 3
- Data analysis for subdivision per country HOT 1
- Possible incorrect mixing of percentage and unit ratios in mobility forecast
- Divergent transitions in stan fits HOT 1
- Parametrization on population compliance to hygien and security rules
- conda env geofacet HOT 1
- posterior parameter values for alpha, alpha_region, and alpha_state HOT 1
- alpha_region HOT 3
- Typo in mean time from onset-to-death HOT 1
- Running Errors in windows10 HOT 1
- Incorrect Model Output
- Data for UK incorrect? HOT 2
- Access and Discussion of Google mobility data feature HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from covid19model.