Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # An R script to visualize the sales trajectory of Kala Pharmaceuticals' Eysuvis/Inveltys
- #
- # (c) 2022 Germain Garand <germain.garand@laposte.net>
- #
- # This is for information purposes only. Any calculation performed herein could be
- # wrong and/or misrepresent reality. Use at your own risk.
- #
- # License: Creative Commons BY-NC 2.0
- #
- # v0.1 - 2022/03/25
- #
- library(ggplot2)
- library(scales)
- Sys.setlocale("LC_TIME", "C")
- # current week
- cw <- as.Date("2022/03/18")
- nw <- cw + 7
- a <- seq(as.Date("2021/10/01"), cw, "week")
- aa <- seq(nw, as.Date("2022/12/30"), "week")
- cur <- a
- a <- c(a, aa)
- b <- seq(as.Date("2021/10/01"), a[length(a)], "months")
- eys <- c(
- 1664, 1655, 1502, 1669, 1669,
- 1599, 1983, 1824, 1305,
- 1784, 1938, 1826, 1600, 1460,
- 1417, 1761, 1789, 1998,
- 1935, 2236, 2313, 1944,
- 2314, 2166, 2195,
- rep(0, 2),
- rep(0, 9),
- rep(0, 9),
- rep(0, 9),
- rep(0, 9),
- rep(0, 3)
- )
- inv <- c(
- 2922, 3067, 2876, 2885, 3136,
- 3004, 2990, 2938, 2248,
- 3006, 2851, 2660, 2107, 2071,
- 2348, 2634, 2494, 2764,
- 2511, 2816, 2907, 2562,
- 2790, 2809, 2598,
- rep(2800, 2),
- rep(2900, 9),
- rep(2900, 9),
- rep(3000, 9),
- rep(3000, 9),
- rep(3000, 3)
- )
- e <- data.frame(a, eys, inv)
- names(e) <- c("Week", "Eysuvis", "Inveltys")
- e$Month <- as.Date(cut(e$Week, breaks = "month"))
- t = length(cur)-1
- cwgr = ( ((eys[t]+eys[t+1])/2) / ((eys[1]+eys[2])/2) )^(1/t)-1
- fw = length(a)-length(cur)
- for (i in 1:fw)
- {
- e$Eysuvis[t+1+i] = e$Eysuvis[t+i] + (e$Eysuvis[t+i]*cwgr)
- }
- options(scipen=10000)
- png("eysuvis_inveltys_projected.png", width=960)
- 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")
- par(new=TRUE)
- plot(Inveltys ~ Week, e, type='s', axes=FALSE, ann=FALSE,col='red')
- axis(4, e$Inveltys, col='red', col.axis='red')
- legend("topleft", inset=.05, c("Eysuvis","Inveltys"), fill=c("blue","red"))
- abline(v=c(nw), col="green", lty="dotted")
- text(x=nw,y=2600, labels="Data after this line is projected", cex=1, srt=90, col="black")
- dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement