Advertisement
Spartrap

Eysuvis/Inveltys scripts

Mar 25th, 2022
1,476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.12 KB | None | 0 0
  1. #
  2. # An R script to visualize the sales trajectory of Kala Pharmaceuticals' Eysuvis/Inveltys
  3. #
  4. # (c) 2022 Germain Garand <germain.garand@laposte.net>
  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. #  v0.1 - 2022/03/25
  12. #
  13.  
  14. library(ggplot2)
  15. library(scales)
  16.  
  17. Sys.setlocale("LC_TIME", "C")
  18.  
  19. # current week
  20. cw <- as.Date("2022/03/18")
  21.  
  22. nw <- cw + 7
  23. a <- seq(as.Date("2021/10/01"), cw, "week")
  24. aa <- seq(nw, as.Date("2022/12/30"), "week")
  25. cur <- a
  26. a <- c(a, aa)
  27.  
  28. b <- seq(as.Date("2021/10/01"), a[length(a)], "months")
  29.  
  30. eys <- c(
  31.   1664, 1655, 1502, 1669, 1669,
  32.   1599, 1983, 1824, 1305,
  33.   1784, 1938, 1826, 1600, 1460,
  34.   1417, 1761, 1789, 1998,
  35.   1935, 2236, 2313, 1944,
  36.   2314, 2166, 2195,
  37.   rep(0, 2),
  38.   rep(0, 9),
  39.   rep(0, 9),
  40.   rep(0, 9),
  41.   rep(0, 9),
  42.   rep(0, 3)
  43. )
  44. inv <- c(
  45.   2922, 3067, 2876, 2885, 3136,
  46.   3004, 2990, 2938, 2248,
  47.   3006, 2851, 2660, 2107, 2071,
  48.   2348, 2634, 2494, 2764,
  49.   2511, 2816, 2907, 2562,
  50.   2790, 2809, 2598,
  51.   rep(2800, 2),
  52.   rep(2900, 9),
  53.   rep(2900, 9),
  54.   rep(3000, 9),
  55.   rep(3000, 9),
  56.   rep(3000, 3)
  57. )
  58.  
  59. e <- data.frame(a, eys, inv)
  60. names(e) <- c("Week", "Eysuvis", "Inveltys")
  61.  
  62. e$Month <- as.Date(cut(e$Week, breaks = "month"))
  63.  
  64. t = length(cur)-1
  65. cwgr = ( ((eys[t]+eys[t+1])/2) / ((eys[1]+eys[2])/2) )^(1/t)-1
  66. fw = length(a)-length(cur)
  67. for (i in 1:fw)
  68. {
  69.   e$Eysuvis[t+1+i] = e$Eysuvis[t+i] + (e$Eysuvis[t+i]*cwgr)
  70. }
  71.  
  72. options(scipen=10000)
  73.  
  74. png("eysuvis_inveltys_projected.png", width=960)
  75. plot(Eysuvis ~ Week, e, type = 'l', col='blue', main="Eysuvis/Inveltys", ylab="Scripts", sub=paste("Eysuvis CWGR: ", format(round(cwgr*100, 2), nsmall=2),"%"), col.sub="blue")
  76. par(new=TRUE)
  77. plot(Inveltys ~ Week, e, type='s', axes=FALSE, ann=FALSE,col='red')
  78. axis(4, e$Inveltys, col='red', col.axis='red')
  79. legend("topleft", inset=.05, c("Eysuvis","Inveltys"), fill=c("blue","red"))
  80. abline(v=c(nw), col="green", lty="dotted")
  81. text(x=nw,y=2600, labels="Data after this line is projected", cex=1, srt=90, col="black")
  82.  
  83. dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement