Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. library(ggplot2)
  2.  
  3. t = seq(1,40)
  4. realcases = 100*exp(t/4)
  5. realincrement = diff(c(0, realcases))
  6.  
  7.  
  8. testseekers = 10e3 + realincrement*4
  9. maxtests = 20000
  10.  
  11. ## now assume that you test *up to* 20k people. if more people are
  12. ## seeking tests, you test a random subset of the seekers
  13. ## getting a binomial count of positives for the given frequency
  14.  
  15. ntests = rep(0,NROW(t));
  16. ntests[1] = 10e3;
  17. confinc = rep(0,NROW(t));
  18. confinc[1] = 100;
  19. for(i in 2:(NROW(t)-1)){
  20. if(testseekers[i] < maxtests){
  21. confinc[i] = realincrement[i]
  22. ntests[i] = testseekers[i]
  23. }
  24. else if(testseekers[i] > maxtests){
  25. confinc[i] = min(realincrement[i],rbinom(1, maxtests, realincrement[i]/testseekers[i]))
  26. ntests[i] = maxtests
  27. }
  28. }
  29.  
  30. confinc = head(confinc, - 1)/1000
  31. ntests = head(ntests, -1)/1000
  32.  
  33. # cumconf = cumsum(confinc)
  34. # cumtests = cumsum(ntests)
  35.  
  36. # ggplot(data.frame(t=t,conf=cumconf,nt=cumtests,real=realcases))+geom_line(aes(t,cumconf),color="blue") + geom_line(aes(t,nt),color="green")+ geom_line(aes(t,real),color="red") +coord_cartesian(xlim=c(0,35),ylim=c(0,400000));
  37. # ggplot(data.frame(t=t,conf=cumconf,nt=cumtests,real=realcases))+geom_line(aes(t,log(cumconf)),color="blue") + geom_line(aes(t,log(nt)),color="green")+ geom_line(aes(t,log(real)),color="red") +coord_cartesian(xlim=c(0,30),ylim=c(0,log(400000)));
  38.  
  39.  
  40. par(mfrow = c(2, 2))
  41. plot(ntests,
  42. ylim = c(0, max(ntests)),
  43. type = "b",
  44. col = "Blue",
  45. ylab = "# per day (Thousands)",
  46. panel.first = grid())
  47. lines(confinc, type = "b", col = "Red")
  48. legend("topleft",
  49. legend = c("Tests", "Cases"),
  50. col = c("Blue", "Red"),
  51. lwd = 2)
  52.  
  53. plot(confinc/ntests,
  54. type = "b",
  55. col = "Blue",
  56. ylab = "% Positive",
  57. panel.first = grid())
  58.  
  59. plot(ntests, confinc,
  60. type = "p",
  61. col = "Blue",
  62. xlab = "# Tests (Thousands)",
  63. ylab = "# Cases (Thousands)",
  64. panel.first = grid())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement