Created
May 13, 2020 21:27
-
-
Save medewitt/d236c6a31d5e045550595f84c896d372 to your computer and use it in GitHub Desktop.
modelling-outbreak-risk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
n.sim <- 1000 | |
lambda <- 8/45 # 8 nursing homes in 45 days | |
set.seed(336) | |
n.sim <- 1000 | |
mu <- 20 # 20 hospitalizations mean | |
sigma <- 5 ## =/- 10 patients | |
sigma.sq <- sigma^2 | |
beta <- mu/sigma.sq | |
alpha <- beta * mu | |
severity <- rgamma(n.sim, alpha, beta) | |
severity <- rmutil::rpareto(n = n.sim,m = mu, s = 100000) | |
severity[severity>100] <- 100 | |
summary(severity) | |
(VaR.sev <- quantile(severity, alpha_tol)) | |
frequency <- rpois(n.sim, lambda) | |
summary(frequency) | |
poisson.freq <- data.frame(Frequency = frequency, | |
Distribution = rep("Poisson", each = n.sim)) | |
ggplot(poisson.freq, aes(x = frequency, | |
fill = Distribution)) + geom_density(alpha = 0.3) | |
loss <- rpois(n.sim, severity * lambda) | |
summary(loss) | |
hist(loss, breaks = 30, col = "lightgray") | |
loss | |
loss.rf <- data.frame(Loss = loss, Distribution = rep("Potential Loss", | |
each = n.sim)) | |
alpha_tol <- 0.05 | |
(VaR.loss.rf <- quantile(loss.rf$Loss, | |
1 - alpha_tol)) | |
(ES.loss.rf <- mean(loss.rf$Loss[loss.rf$Loss > | |
VaR.loss.rf])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment