Last active
March 17, 2020 01:40
-
-
Save psolymos/6b8f062e2e1d3d418048d82c8a62fe5c to your computer and use it in GitHub Desktop.
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
# COVID-19 cases in Alberta, Canada | |
# cases over time and some analyses | |
library(PVAClone) | |
dat <- data.frame( | |
date=c("2020-03-05", "2020-03-06", "2020-03-07", "2020-03-08", "2020-03-09", "2020-03-10", "2020-03-11", | |
"2020-03-12", "2020-03-13", "2020-03-14", "2020-03-15", "2020-03-16"), | |
cases=c(1, 2, 2, 4, 7, 14, 19, | |
23, 29, 39, 56, 74)) | |
m <- pva(dat$cases, ricker("none"), 10) | |
K <- -coef(m)["a"]/coef(m)["b"] | |
prx <- 0:(nrow(dat)*3) | |
pr <- numeric(length(prx)) | |
pr[1] <- log(dat$cases[1]) | |
for (i in 2:length(pr)) | |
pr[i] <- pr[i-1] + coef(m)["a"] + coef(m)["b"]*exp(pr[i-1]) | |
pr <- exp(pr) | |
plot(prx, pr, type="l", ylab="# of cases", xlab=paste("Days since", dat$date[1])) | |
lines(seq_len(nrow(dat))-1, dat$cases, col=2, type="b", lwd=2, pch=19) | |
abline(h=K, col=4, lty=3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment