Spartrap

Annovera

Feb 28th, 2020
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.86 KB | None | 0 0
  1. #
  2. # An R script to visualize the sales trajectory of TherapeuticsMD's Annovera
  3. #
  4. # (c) 2019 Germain Garand <[email protected]>
  5. #
  6. # This is for information purposes only. Any calculation performed herein could be
  7. # wrong and/or misrepresent reality. Use at your own risk.
  8. #
  9. # License: Creative Commons BY-NC 2.0
  10.  
  11. Sys.setlocale("LC_TIME", "C")
  12.  
  13. # common ratio of the geometric progression to use as comparator
  14. geom_ratio <- 1.15
  15.  
  16. # Optionally, assume the geometric progression will gradually slow down to a lower value
  17. geom_min_ratio <- 1.13
  18. start_decay_after_n_week <- 12
  19. decay_pace <- 0.01
  20.  
  21. a <- c(
  22.     "2019/10/18","2019/10/25",
  23.     "2019/11/1","2019/11/8","2019/11/15","2019/11/22","2019/11/29",
  24.     "2019/12/6", "2019/12/13", "2019/12/20", "2019/12/27",
  25.     "2020/01/03", "2020/01/10", "2020/01/17", "2020/01/24", "2020/01/31",
  26.     "2020/02/07", "2020/02/14", "2020/02/21", "2020/02/28"
  27. )
  28. a <- as.Date(a, "%Y/%m/%d")
  29. b <- c(
  30.      15,28,
  31.      87,71,135,112,109,
  32.      73, 109, 74, 145,
  33.      71, 81, 121, 133, 192,
  34.      183, 271, 225, 239
  35. )
  36. c <- c(1:length(b))
  37. d <- c(1:(length(b)+2))
  38. g <- c( rep(geom_ratio, start_decay_after_n_week), seq(from=geom_ratio, to=geom_min_ratio, by=-decay_pace ))
  39.  
  40. if (length(g) < length(a)+1) {
  41.   g <- c( g, rep(geom_min_ratio, (length(b)+1)-length(g)) )
  42. } else if (length(g) > length(b)+1) {
  43.   g <- head(g, length(b)+1)
  44. }
  45.  
  46. message("Geometric ratios: ", paste(g," "))
  47.  
  48. z=b[1]
  49. x=c(z)
  50. for( i in g) {
  51.   z=i*z
  52.   x=c(x, z)
  53. }
  54.  
  55. # the ordinary guess is that symphony only captures 1/3rd of Annovera scripts.
  56. #b <- b*3
  57. #x <- x*3
  58. e <- data.frame(a,b)
  59. names(e) <- c("Week", "Scripts")
  60.  
  61. f <- data.frame(d,x)
  62. names(f) <- c("Week", "Geometric")
  63.  
  64. p <- (geom_ratio-1)*100
  65. pm <- (geom_min_ratio-1)*100
  66. if (p == pm) {
  67.   main_legend <- paste("Annovera Weekly Scripts vs.", p , "% Compounded Growth Curve", sep='')
  68. } else {
  69.   main_legend <- paste("Annovera Weekly vs.", p ,"% -> ",pm ,"% Sliding Compounded Growth", sep='')
  70. }
  71. #main_legend <- paste( main_legend, "\nSH Data scaled 200% (current best guess)")
  72.  
  73. t = length(a)-1
  74. cwgr = ( ((b[t]+b[t+1])/2) / b[1] )^(1/t)-1
  75.  
  76. msg = paste("Total scripts: ", sum(e$Scripts),
  77.             " 4Q19: ", sum(head(e$Scripts,13)),
  78.             " 1Q20: ",sum(tail(e$Scripts,-13)),
  79.             " Mean: ", floor(mean(e$Scripts)),
  80.             " CWGR: ", round(cwgr*100), "%")
  81.  
  82. png("annovera.png",width=480,height=480)
  83. plot(Scripts ~ Week, e, type = 'l', col='blue', ylim=c(head(b,1),max(x,b)), main=main_legend, sub= msg,
  84. #paste("CWGR: ", round(cwgr*100), "%"),
  85.  col.sub='red')
  86. par(new=TRUE)
  87. plot(Geometric ~ Week, f, type='l', ylim=c(head(b,1),max(x,b)),axes=FALSE, ann=FALSE,col='violet')
  88. axis(4, round(f$Geometric), col='violet', col.axis='violet')
  89. legend("top", inset=.05, c("Annovera scripts","Geometric reference"), fill=c("blue","violet"), title="Symph. Health data")
  90. dev.off()
Advertisement
Add Comment
Please, Sign In to add comment