# TITLE: "Replication of the "Reference Model", described in the manuscript submitted to the European Journal of Health Economics in November 2014: # "Economic evaluation in chronic pain: A systematic review and de novo flexible economic model" # This code uses the package "ggplot2". To cite: H. Wickham. ggplot2: elegant graphics for data analysis. Springer New York, 2009. # WHEN VIEWED IN RStudio # TO VIEW THE CODE IN COLLAPSED SECTIONS: # Edit>Folding>Collapse All # Click on margin arrows to show section headings and contained code #Running order: #DESCRIPTION #CONTROLS #SOURCE DATA #MODEL PARAMETERS #PARAMETER MATRIX #MODEL AS A FUNCTION #DETERMINISTIC ANALYSIS #PROBABILISTIC ANALYSIS #OWSA ANALYSIS ############ #DESCRIPTION ############ #This model is the 'Reference Model' submitted as an appendix to the manuscript "Economic evaluation in chronic pain: A systematic review and de novo flexible economic model" #submitted to the European Journal of Health Economics in January 2015 #The model compares two treatments for chronic musculoskeletal pain: (i) oral morphine (though the model has the flexibility to select oxycodone data at #first-line instead) (Treatment 1 / Tx1) and (ii) a hypothetical novel formulation (Treatment 2 /Tx2). The model structure is identical across treatment arms. #The model has two absorbing states to capture outcomes for those who have discontinued treatment or moved on to subsequent treatment following two failed #attempts at therapy: 'treatment discontinuation' and 'subsequent treatment'. The other states in the model are states to capture outcomes while on treatment, #or transitory states to capture temporary outcomes following withdrawal from treatment. #Patients enter the model and begin treatment. While on treatment, patients may experience treatment-emergent tolerable adverse events (AEs) (constipation and #nausea/vomiting); the simulated cohort can therefore be separated into two AE-related Markov states within 1st-line treatment. HRQL consequences of differences #in analgesic effects across treatments are captured across treatment arms. #Patients may withdraw from 1st-line treatment and move to either 'withdrawal, AEs' or 'withdrawal, other (including pain)' for one model cycle to accrue the #temporary dip in HRQL and cost outcomes which patients experience immediately following treatment failure. These patients then either: # . forgo further therapy and move to the absorbing state 'treatment discontinuation, or # . attempt 2nd-line therapy. #The Markov states for 2nd-line therapy are identical to those for 1st-line therapy. Patients may withdraw from 2nd-line therapy for identical reasons as for #1st-line therapy. Outcomes following withdrawal from 2nd-line therapy are assumed to be captured by the two absorbing states in the model. #Different structural and data assumptions can be tested by adjusting settings in #CONTROLs #The scenarios tested in the manuscript are detailed within #CONTROLS #The type of analysis being run (deterministic, probabilistic or one-way sensitivity analysis) is set within #CONTROLS #Treatment 1 - Comparator #Treatment 2 - Novel therapy ######### #CONTROLS ######### #MODEL SETTINGS - the user can adjust these to explore different parameter and structural assumptions #Base case settings stored below cont.AnalysisType<-"Deterministic" cont.nruns<-1000 cont.standarderror<-0.1 cont.utilitypercimp_NovelTherap<-0 cont.costmultiplier_noveltherapy<-6 cont.prob.discont.after.failed.1L<-0.05 cont.prob.discont.after.failed.2L<-0.1 cont.PatPathway<-"Discontinuation" cont.titration<-"no adjustment for first 4 weeks" cont.Tx1Arm_1LTxoptions<-"Morphine" cont.Tx1Arm_2LTxoptions<-"Oxycodone" cont.Tx2Arm_2LTxoptions<-"Oxycodone" cont.withd_mult_init<-2 cont.doseadj_init<-0.65 cont.prop_improv_AE_noveltherapy<-0.3 cont.prop_disc_GP<-0.5 cont.prop_naus_GP<-0.2 cont.umult_failed1L<-0.9 cont.umult_failed2L<-0.8 #cycle length 1 week cont.CycleProp<-7/365.25 cont.TimeHorizon<-52 cont.WTPperQALY<-20000 # MODEL SETTINGS - BASE CASE and ##RESTRICTIONS # cont.AnalysisType<-cont.nruns ##cont.nruns,"Probabilistic" or "OWSA" # cont.nruns<-100 ##If "Probabilistic" analysis, input a positive integer to select number of PSA runs # cont.standarderror=0.1 ##input a value between 0 and 0.5, inclusive # cont.utilitypercimp_NovelTherap<-0 ##input a value between 0 and 0.2, inclusive - scenario 0.05 # cont.costmultiplier_noveltherapy<-4 ##input a positive number # cont.prob.discont.after.failed.1L<-0.05 ##input a value between 0 and 1, inclusive # cont.prob.discont.after.failed.2L<-0.1 ##input a value between 0 and 1, inclusive # cont.PatPathway<-"Discontinuation" ##"Discontinuation" or "Some enter subsequent treatment" # cont.titration<-"no adjustment for first 4 weeks" ##"no adjustment for first 4 weeks" or "User-defined dose and withdrawal rate adjustment for first 4 weeks" # cont.Tx1Arm_1LTxoptions<-"Morphine" ##"Morphine" or "Oxycodone" # cont.Tx1Arm_2LTxoptions<-"Oxycodone" ##"Oxycodone" or "Morphine" # cont.Tx2Arm_2LTxoptions<-"Oxycodone" ##"Oxycodone" or "Morphine" # cont.withd_mult_init<-2 ##input a positive value # cont.doseadj_init<-0.65 ##input a value between 0 and 1, inclusive # cont.prop_improv_AE_noveltherapy<-0.3 ##input a positive value # cont.prop_disc_GP<-0.5 ##input a value between 0 and 1, inclusive # cont.prop_naus_GP<-0.2 ##input a value between 0 and 1, inclusive # cont.umult_failed1L<-0.9 ##input a value between 0 and 1, inclusive # cont.umult_failed2L<-0.8 ##input a value between 0 and 1, inclusive # cont.TimeHorizon<-52 ##input a time horizon up to 104 (weeks) # SCENARIOS # Scenario 1 - Base case settings # Scenario 2 - Base case settings, but cont.PatPathway<-"Some enter subsequent treatment" # Scenario 3 - Base case settings, but cont.Tx2Arm_2LTxoptions<-"Morphine" # Scenario 4 - Base case settings, but cont.titration<-"User-defined dose and withdrawal rate adjustment for first 4 weeks" # Scenario 5 - Base case settings, but cont.utilitypercimp_NovelTherap<-0.05 # Scenario 6 - Base case settings, but cont.TimeHorizon<-104 # Scenario 7 - Base case settings, but cont.umult_failed1L<-1 and cont.umult_failed2L<-1 ############ #SOURCE DATA ############ #Cost source data #Much of source cost data are 2009/10 data - Curtis et al Inflation Factor update to 2012/2013 cost year PriceIndex0910<-268.6 PriceIndex1213<-289.1 InfFactor<-PriceIndex1213/PriceIndex0910 #Morphine cost from BNF 67, dose from NICE 2012 study c_cycle_Tx_morphine<-2.632729166666670000 #Morphine comed costs, withdrawal and constipation AE costs from NICE 2012 study c_cycle_comed_morphine<-2.1*InfFactor c_withdrawal<-99.33*InfFactor c_constipation<-4.68*InfFactor #Oxycodone cost from BNF 67, dose from Dunlop et al 2012 study c_cycle_Tx_oxycodone<-9.2011500000 #Oxycodone comed costs from Dunlop et al 2012 study c_cycle_comed_oxycodone<-0.04*InfFactor #GP visit cost from PSSRU 2013 (Applied to a proportion of nausea AE patients) c_GP<-37 #Utility source data #Utility data from Ikenberg et al 2012 u_OnTx<-0.695 u_disc_AE<-0.503 u_disc_efficacy<-0.405 u_OnTx_AE<-0.583 #Cycle (7 day) probability source data #Morphine data from Grenier et al 2006 28-day probability data - assume 7 day nausea/vomitting duration and continuous constipation duration #nausea/vomiting M28DNVprob<-0.387 McontinNVprob<-(-log(1-M28DNVprob))/28 Mcycle_prob_nausea<-1-exp(-McontinNVprob*7) #constipation Mcycle_prob_const<-0.321 #Tolerable AE cycle prob cycle_prob_morphine_tolerableAE<-Mcycle_prob_nausea+Mcycle_prob_const #withdrawal due to AEs M28DWITHDAEprob<-0.205 McontinWITHDAEprob<-(-log(1-M28DWITHDAEprob))/28 cycle_prob_morphine_withd_AEs<-1-exp(-McontinWITHDAEprob*7) #withdrawal due to other reason M28DWITHDOTHERprob<-0.050 McontinWITHDOTHERprob<-(-log(1-M28DWITHDOTHERprob))/28 cycle_prob_morphine_withd_other<-1-exp(-McontinWITHDOTHERprob*7) #Oxycodone data from Ikenberg et al 2012 105-day probability data - did not report tolerable AEs by each AE, assume continuous AE duration #tolerable AEs cycle_prob_oxy_tolerableAE<-0.4635 #withdrawal due to AEs O105DWITHDAEprob<-0.3936 OcontinWITHDAEprob<-(-log(1-O105DWITHDAEprob))/105 cycle_prob_oxy_withdrawAE<-1-exp(-OcontinWITHDAEprob*7) #withdrawal due to other reason O105DWITHDOTHERprob<-0.034 OcontinWITHDOTHERprob<-(-log(1-O105DWITHDOTHERprob))/105 cycle_prob_oxy_withdrawother<-1-exp(-OcontinWITHDOTHERprob*7) ################# #MODEL PARAMETERS ################# #costs c_cycle_tx_tx1<-ifelse(cont.Tx1Arm_1LTxoptions=="Morphine",c_cycle_Tx_morphine,c_cycle_Tx_oxycodone) c_cycle_tx_tx2<-c_cycle_Tx_oxycodone*cont.costmultiplier_noveltherapy c_cycle_comed_tx1<-ifelse(cont.Tx1Arm_1LTxoptions=="Morphine",c_cycle_comed_morphine,c_cycle_comed_oxycodone) c_cycle_comed_tx2<-c_cycle_comed_oxycodone*(1-cont.prop_improv_AE_noveltherapy) c_cycle_ae<-(Mcycle_prob_nausea/cycle_prob_morphine_tolerableAE)*cont.prop_naus_GP*c_GP+c_constipation c_cycle_withd_AE<-c_withdrawal c_cycle_withd_other<-c_withdrawal c_cycle_2Ltx_tx1arm<-ifelse(cont.Tx1Arm_2LTxoptions=="Morphine",c_cycle_Tx_morphine+c_cycle_comed_morphine,c_cycle_Tx_oxycodone+c_cycle_comed_oxycodone) c_cycle_2Ltx_tx2arm<-ifelse(cont.Tx2Arm_2LTxoptions=="Morphine",c_cycle_Tx_morphine+c_cycle_comed_morphine,c_cycle_Tx_oxycodone+c_cycle_comed_oxycodone) c_cycle_3Ltx_tx1modelarm<-c_cycle_Tx_morphine+c_cycle_comed_morphine c_cycle_3Ltx_tx2modelarm<-c_cycle_Tx_morphine+c_cycle_comed_morphine c_cycle_discontinued<-c_GP*cont.prop_disc_GP c_cycle_tx_tx1_init<-c_cycle_tx_tx1*cont.doseadj_init c_cycle_tx_tx2_init<-c_cycle_tx_tx1*cont.costmultiplier_noveltherapy*cont.doseadj_init #utilities u_on1LTx_Tx1_noAE<-u_OnTx u_on1LTx_Tx1_AE<-u_OnTx_AE u_on1LTx_Tx2_noAE<-u_OnTx*(1+cont.utilitypercimp_NovelTherap) u_on1LTx_Tx2_AE<-u_OnTx_AE*(1+cont.utilitypercimp_NovelTherap) u_withdrawn1L_AE<-u_disc_AE u_withdrawn1L_other<-u_disc_efficacy u_on2LTx_noAE<-u_OnTx*cont.umult_failed1L u_on2LTx_AE<-u_OnTx_AE*cont.umult_failed1L u_withdrawn2L_AE<-u_disc_AE*cont.umult_failed1L u_withdrawn2L_other<-u_disc_efficacy*cont.umult_failed1L u_3L<-((u_OnTx+u_OnTx_AE+u_disc_AE+u_disc_efficacy)/4)*cont.umult_failed2L u_discontinuation<-u_disc_efficacy*cont.umult_failed2L #cycle probabilities prob_AE_Tx1arm_1L<-ifelse(cont.Tx1Arm_1LTxoptions=="Morphine",cycle_prob_morphine_tolerableAE,cycle_prob_oxy_tolerableAE) prob_AE_Tx2arm_1L<-cycle_prob_oxy_tolerableAE*(1-cont.prop_improv_AE_noveltherapy) prob_withdAE_Tx1arm_1L<-ifelse(cont.Tx1Arm_1LTxoptions=="Morphine",cycle_prob_morphine_withd_AEs,cycle_prob_oxy_withdrawAE) prob_withdAE_Tx2arm_1L<-cycle_prob_oxy_withdrawAE*(1-cont.prop_improv_AE_noveltherapy) prob_withdother_Tx1arm_1L<-ifelse(cont.Tx1Arm_1LTxoptions=="Morphine",cycle_prob_morphine_withd_other,cycle_prob_oxy_withdrawother) prob_withdother_Tx2arm_1L<-cycle_prob_oxy_withdrawother*(1-cont.prop_improv_AE_noveltherapy) prob_AE_Tx1arm_2L<-ifelse(cont.Tx1Arm_2LTxoptions=="Morphine",cycle_prob_morphine_tolerableAE,cycle_prob_oxy_tolerableAE) prob_AE_Tx2arm_2L<-ifelse(cont.Tx2Arm_2LTxoptions=="Morphine",cycle_prob_morphine_tolerableAE,cycle_prob_oxy_tolerableAE) prob_withdAE_Tx1arm_2L<-ifelse(cont.Tx1Arm_2LTxoptions=="Morphine",cycle_prob_morphine_withd_AEs,cycle_prob_oxy_withdrawAE) prob_withdAE_Tx2arm_2L<-ifelse(cont.Tx2Arm_2LTxoptions=="Morphine",cycle_prob_morphine_withd_AEs,cycle_prob_oxy_withdrawAE) prob_withdother_Tx1arm_2L<-ifelse(cont.Tx1Arm_2LTxoptions=="Morphine",cycle_prob_morphine_withd_other,cycle_prob_oxy_withdrawother) prob_withdother_Tx2arm_2L<-ifelse(cont.Tx2Arm_2LTxoptions=="Morphine",cycle_prob_morphine_withd_other,cycle_prob_oxy_withdrawother) prob_discontafter1L<-cont.prob.discont.after.failed.1L prob_discontafter2L<-cont.prob.discont.after.failed.2L prob_withdAE_Tx1arm_1L_init<-prob_withdAE_Tx1arm_1L*cont.withd_mult_init prob_withdAE_Tx2arm_1L_init<-prob_withdAE_Tx2arm_1L*cont.withd_mult_init prob_withdother_Tx1arm_1L_init<-prob_withdother_Tx1arm_1L*cont.withd_mult_init prob_withdother_Tx2arm_1L_init<-prob_withdother_Tx2arm_1L*cont.withd_mult_init ################# #PARAMETER MATRIX ################# ParamMatrix<-matrix(nrow=44,ncol=5) rownames(ParamMatrix) <- c("p_c_cycle_tx_tx1","p_c_cycle_tx_tx2","p_c_cycle_comed_tx1","p_c_cycle_comed_tx2","p_c_cycle_ae","p_c_cycle_withd_AE", "p_c_cycle_withd_other","p_c_cycle_2Ltx_tx1arm","p_c_cycle_2Ltx_tx2arm","p_c_cycle_3Ltx_tx1modelarm","p_c_cycle_3Ltx_tx2modelarm","p_c_cycle_discontinued", "p_c_cycle_tx_tx1_init","p_c_cycle_tx_tx2_init","p_u_on1LTx_Tx1_noAE","p_u_on1LTx_Tx1_AE","p_u_on1LTx_Tx2_noAE","p_u_on1LTx_Tx2_AE", "p_u_withdrawn1L_AE","p_u_withdrawn1L_other","p_u_on2LTx_noAE","p_u_on2LTx_AE","p_u_withdrawn2L_AE","p_u_withdrawn2L_other", "p_u_3L","p_u_discontinuation","p_prob_AE_Tx1arm_1L","p_prob_AE_Tx2arm_1L","p_prob_withdAE_Tx1arm_1L","p_prob_withdAE_Tx2arm_1L", "p_prob_withdother_Tx1arm_1L","p_prob_withdother_Tx2arm_1L","p_prob_AE_Tx1arm_2L","p_prob_AE_Tx2arm_2L","p_prob_withdAE_Tx1arm_2L","p_prob_withdAE_Tx2arm_2L", "p_prob_withdother_Tx1arm_2L","p_prob_withdother_Tx2arm_2L","p_prob_discontafter1L","p_prob_discontafter2L","p_prob_withdAE_Tx1arm_1L_init","p_prob_withdAE_Tx2arm_1L_init", "p_prob_withdother_Tx1arm_1L_init","p_prob_withdother_Tx2arm_1L_init") colnames(ParamMatrix) <- c("Deterministic","Alpha","Beta","LCI","UCI") #Column "Deterministic" ParamMatrix["p_c_cycle_tx_tx1","Deterministic"]<- c_cycle_tx_tx1 ParamMatrix["p_c_cycle_tx_tx2","Deterministic"]<- c_cycle_tx_tx2 ParamMatrix["p_c_cycle_comed_tx1","Deterministic"]<- c_cycle_comed_tx1 ParamMatrix["p_c_cycle_comed_tx2","Deterministic"]<- c_cycle_comed_tx2 ParamMatrix["p_c_cycle_ae","Deterministic"]<- c_cycle_ae ParamMatrix["p_c_cycle_withd_AE","Deterministic"]<- c_cycle_withd_AE ParamMatrix["p_c_cycle_withd_other","Deterministic"]<- c_cycle_withd_other ParamMatrix["p_c_cycle_2Ltx_tx1arm","Deterministic"]<- c_cycle_2Ltx_tx1arm ParamMatrix["p_c_cycle_2Ltx_tx2arm","Deterministic"]<- c_cycle_2Ltx_tx2arm ParamMatrix["p_c_cycle_3Ltx_tx1modelarm","Deterministic"]<- c_cycle_3Ltx_tx1modelarm ParamMatrix["p_c_cycle_3Ltx_tx2modelarm","Deterministic"]<- c_cycle_3Ltx_tx2modelarm ParamMatrix["p_c_cycle_discontinued","Deterministic"]<- c_cycle_discontinued ParamMatrix["p_c_cycle_tx_tx1_init","Deterministic"]<- c_cycle_tx_tx1_init ParamMatrix["p_c_cycle_tx_tx2_init","Deterministic"]<- c_cycle_tx_tx2_init ParamMatrix["p_u_on1LTx_Tx1_noAE","Deterministic"]<- u_on1LTx_Tx1_noAE ParamMatrix["p_u_on1LTx_Tx1_AE","Deterministic"]<- u_on1LTx_Tx1_AE ParamMatrix["p_u_on1LTx_Tx2_noAE","Deterministic"]<- u_on1LTx_Tx2_noAE ParamMatrix["p_u_on1LTx_Tx2_AE","Deterministic"]<- u_on1LTx_Tx2_AE ParamMatrix["p_u_withdrawn1L_AE","Deterministic"]<- u_withdrawn1L_AE ParamMatrix["p_u_withdrawn1L_other","Deterministic"]<- u_withdrawn1L_other ParamMatrix["p_u_on2LTx_noAE","Deterministic"]<- u_on2LTx_noAE ParamMatrix["p_u_on2LTx_AE","Deterministic"]<- u_on2LTx_AE ParamMatrix["p_u_withdrawn2L_AE","Deterministic"]<- u_withdrawn2L_AE ParamMatrix["p_u_withdrawn2L_other","Deterministic"]<- u_withdrawn2L_other ParamMatrix["p_u_3L","Deterministic"]<- u_3L ParamMatrix["p_u_discontinuation","Deterministic"]<- u_discontinuation ParamMatrix["p_prob_AE_Tx1arm_1L","Deterministic"]<- prob_AE_Tx1arm_1L ParamMatrix["p_prob_AE_Tx2arm_1L","Deterministic"]<- prob_AE_Tx2arm_1L ParamMatrix["p_prob_withdAE_Tx1arm_1L","Deterministic"]<- prob_withdAE_Tx1arm_1L ParamMatrix["p_prob_withdAE_Tx2arm_1L","Deterministic"]<- prob_withdAE_Tx2arm_1L ParamMatrix["p_prob_withdother_Tx1arm_1L","Deterministic"]<- prob_withdother_Tx1arm_1L ParamMatrix["p_prob_withdother_Tx2arm_1L","Deterministic"]<- prob_withdother_Tx2arm_1L ParamMatrix["p_prob_AE_Tx1arm_2L","Deterministic"]<- prob_AE_Tx1arm_2L ParamMatrix["p_prob_AE_Tx2arm_2L","Deterministic"]<- prob_AE_Tx2arm_2L ParamMatrix["p_prob_withdAE_Tx1arm_2L","Deterministic"]<- prob_withdAE_Tx1arm_2L ParamMatrix["p_prob_withdAE_Tx2arm_2L","Deterministic"]<- prob_withdAE_Tx2arm_2L ParamMatrix["p_prob_withdother_Tx1arm_2L","Deterministic"]<- prob_withdother_Tx1arm_2L ParamMatrix["p_prob_withdother_Tx2arm_2L","Deterministic"]<- prob_withdother_Tx2arm_2L ParamMatrix["p_prob_discontafter1L","Deterministic"]<- prob_discontafter1L ParamMatrix["p_prob_discontafter2L","Deterministic"]<- prob_discontafter2L ParamMatrix["p_prob_withdAE_Tx1arm_1L_init","Deterministic"]<- prob_withdAE_Tx1arm_1L_init ParamMatrix["p_prob_withdAE_Tx2arm_1L_init","Deterministic"]<- prob_withdAE_Tx2arm_1L_init ParamMatrix["p_prob_withdother_Tx1arm_1L_init","Deterministic"]<- prob_withdother_Tx1arm_1L_init ParamMatrix["p_prob_withdother_Tx2arm_1L_init","Deterministic"]<- prob_withdother_Tx2arm_1L_init #Column "Alpha" #costs for (i in 3:7) { ParamMatrix[i,"Alpha"]<-((ParamMatrix[i,"Deterministic"])^2)/((ParamMatrix[i,"Deterministic"]*cont.standarderror)^2) } ParamMatrix[12,"Alpha"]<-((ParamMatrix[12,"Deterministic"])^2)/((ParamMatrix[12,"Deterministic"]*cont.standarderror)^2) #utilities ParamMatrix[15,"Alpha"]<-((ParamMatrix[15,"Deterministic"])^2)*(1-ParamMatrix[15,"Deterministic"])/((((ParamMatrix[15,"Deterministic"]*(1-(ParamMatrix[15,"Deterministic"])))/215)^0.5)^2) ParamMatrix[16,"Alpha"]<-((ParamMatrix[16,"Deterministic"])^2)*(1-ParamMatrix[16,"Deterministic"])/((((ParamMatrix[16,"Deterministic"]*(1-(ParamMatrix[16,"Deterministic"])))/1571)^0.5)^2) ParamMatrix[19,"Alpha"]<-((ParamMatrix[19,"Deterministic"])^2)*(1-ParamMatrix[19,"Deterministic"])/((((ParamMatrix[19,"Deterministic"]*(1-(ParamMatrix[19,"Deterministic"])))/569)^0.5)^2) ParamMatrix[20,"Alpha"]<-((ParamMatrix[20,"Deterministic"])^2)*(1-ParamMatrix[20,"Deterministic"])/((((ParamMatrix[20,"Deterministic"]*(1-(ParamMatrix[20,"Deterministic"])))/95)^0.5)^2) #probabilities for (i in 27:32) { SE2<-(ifelse(cont.Tx1Arm_1LTxoptions=="Morphine",(ParamMatrix[i,"Deterministic"]*cont.standarderror),((ParamMatrix[i,"Deterministic"]*(1-ParamMatrix[i,"Deterministic"]))/1001)^0.5)^2) ParamMatrix[i,"Alpha"]<-((ParamMatrix[i,"Deterministic"])^2)*(1-ParamMatrix[i,"Deterministic"])/SE2 } for (i in 1:3) { j<-31+i*2 SE2<-(ifelse(cont.Tx1Arm_2LTxoptions=="Morphine",(ParamMatrix[j,"Deterministic"]*cont.standarderror),((ParamMatrix[j,"Deterministic"]*(1-ParamMatrix[j,"Deterministic"]))/1001)^0.5)^2) ParamMatrix[j,"Alpha"]<-((ParamMatrix[j,"Deterministic"])^2)*(1-ParamMatrix[j,"Deterministic"])/SE2 } for (i in 1:3) { j<-32+i*2 SE2<-(ifelse(cont.Tx2Arm_2LTxoptions=="Morphine",(ParamMatrix[j,"Deterministic"]*cont.standarderror),((ParamMatrix[j,"Deterministic"]*(1-ParamMatrix[j,"Deterministic"]))/1001)^0.5)^2) ParamMatrix[j,"Alpha"]<-((ParamMatrix[j,"Deterministic"])^2)*(1-ParamMatrix[j,"Deterministic"])/SE2 } for (i in 39:40) { ParamMatrix[i,"Alpha"]<-((ParamMatrix[i,"Deterministic"])^2)*(1-ParamMatrix[i,"Deterministic"])/((ParamMatrix[i,"Deterministic"]*cont.standarderror)^2) } #Column "Beta" #costs for (i in 3:7) { ParamMatrix[i,"Beta"]<-((ParamMatrix[i,"Deterministic"]*cont.standarderror)^2)/ParamMatrix[i,"Deterministic"] } ParamMatrix[12,"Beta"]<-((ParamMatrix[12,"Deterministic"]*cont.standarderror)^2)/ParamMatrix[12,"Deterministic"] #utilities ParamMatrix[15,"Beta"]<-((ParamMatrix[15,"Deterministic"]))*(1-ParamMatrix[15,"Deterministic"])/((((ParamMatrix[15,"Deterministic"]*(1-(ParamMatrix[15,"Deterministic"])))/215)^0.5)^2)-((ParamMatrix[15,"Deterministic"]^2))*(1-ParamMatrix[15,"Deterministic"])/((((ParamMatrix[15,"Deterministic"]*(1-(ParamMatrix[15,"Deterministic"])))/215)^0.5)^2) ParamMatrix[16,"Beta"]<-((ParamMatrix[16,"Deterministic"]))*(1-ParamMatrix[16,"Deterministic"])/((((ParamMatrix[16,"Deterministic"]*(1-(ParamMatrix[16,"Deterministic"])))/1571)^0.5)^2)-((ParamMatrix[16,"Deterministic"]^2))*(1-ParamMatrix[16,"Deterministic"])/((((ParamMatrix[16,"Deterministic"]*(1-(ParamMatrix[16,"Deterministic"])))/1571)^0.5)^2) ParamMatrix[19,"Beta"]<-((ParamMatrix[19,"Deterministic"]))*(1-ParamMatrix[19,"Deterministic"])/((((ParamMatrix[19,"Deterministic"]*(1-(ParamMatrix[19,"Deterministic"])))/569)^0.5)^2)-((ParamMatrix[19,"Deterministic"]^2))*(1-ParamMatrix[19,"Deterministic"])/((((ParamMatrix[19,"Deterministic"]*(1-(ParamMatrix[19,"Deterministic"])))/569)^0.5)^2) ParamMatrix[20,"Beta"]<-((ParamMatrix[20,"Deterministic"]))*(1-ParamMatrix[20,"Deterministic"])/((((ParamMatrix[20,"Deterministic"]*(1-(ParamMatrix[20,"Deterministic"])))/95)^0.5)^2)-((ParamMatrix[20,"Deterministic"]^2))*(1-ParamMatrix[20,"Deterministic"])/((((ParamMatrix[20,"Deterministic"]*(1-(ParamMatrix[20,"Deterministic"])))/95)^0.5)^2) #probabilities for (i in 27:32) { SE2<-(ifelse(cont.Tx1Arm_1LTxoptions=="Morphine",((ParamMatrix[i,"Deterministic"]*cont.standarderror)^2),(((ParamMatrix[i,"Deterministic"]*(1-ParamMatrix[i,"Deterministic"]))/1001)^0.5)^2)) ParamMatrix[i,"Beta"]<-((ParamMatrix[i,"Deterministic"]))*(1-ParamMatrix[i,"Deterministic"])/SE2-((ParamMatrix[i,"Deterministic"]^2))*(1-ParamMatrix[i,"Deterministic"])/SE2 } for (i in 1:3) { j<-31+i*2 SE2<-(ifelse(cont.Tx1Arm_2LTxoptions=="Morphine",((ParamMatrix[j,"Deterministic"]*cont.standarderror)^2),(((ParamMatrix[j,"Deterministic"]*(1-ParamMatrix[j,"Deterministic"]))/1001)^0.5)^2)) ParamMatrix[j,"Beta"]<-((ParamMatrix[j,"Deterministic"]))*(1-ParamMatrix[j,"Deterministic"])/SE2-((ParamMatrix[j,"Deterministic"]^2))*(1-ParamMatrix[j,"Deterministic"])/SE2 } for (i in 1:3) { j<-32+i*2 SE2<-(ifelse(cont.Tx2Arm_2LTxoptions=="Morphine",((ParamMatrix[j,"Deterministic"]*cont.standarderror)^2),(((ParamMatrix[j,"Deterministic"]*(1-ParamMatrix[j,"Deterministic"]))/1001)^0.5)^2)) ParamMatrix[j,"Beta"]<-((ParamMatrix[j,"Deterministic"]))*(1-ParamMatrix[j,"Deterministic"])/SE2-((ParamMatrix[j,"Deterministic"]^2))*(1-ParamMatrix[j,"Deterministic"])/SE2 } for (i in 39:40) { SE2<-((ParamMatrix[i,"Deterministic"]*cont.standarderror)^2) ParamMatrix[i,"Beta"]<-((ParamMatrix[i,"Deterministic"]))*(1-ParamMatrix[i,"Deterministic"])/SE2-((ParamMatrix[i,"Deterministic"]^2))*(1-ParamMatrix[i,"Deterministic"])/SE2 } #Column "LCI" #costs for (i in 1:2) { ParamMatrix[i,"LCI"]<-ParamMatrix[i,"Deterministic"] } for (i in 3:7) { ParamMatrix[i,"LCI"]<-qgamma(0.025,shape=ParamMatrix[i,"Alpha"],scale=ParamMatrix[i,"Beta"]) } for (i in 8:11) { ParamMatrix[i,"LCI"]<-ParamMatrix[i,"Deterministic"] } ParamMatrix[12,"LCI"]<-qgamma(0.025,shape=ParamMatrix[12,"Alpha"],scale=ParamMatrix[12,"Beta"]) for (i in 13:14) { ParamMatrix[i,"LCI"]<-ParamMatrix[i,"Deterministic"] } #utilities for (i in 15:16) { ParamMatrix[i,"LCI"]<-qbeta(0.025,shape1=ParamMatrix[i,"Alpha"],shape2=ParamMatrix[i,"Beta"]) } for (i in 17:18) { ParamMatrix[i,"LCI"]<-min(ParamMatrix[i-2,"LCI"]*(1+cont.utilitypercimp_NovelTherap),1) } for (i in 19:20) { ParamMatrix[i,"LCI"]<-qbeta(0.025,shape1=ParamMatrix[i,"Alpha"],shape2=ParamMatrix[i,"Beta"]) } for (i in 21:22) { ParamMatrix[i,"LCI"]<-ParamMatrix[i-6,"LCI"]*cont.umult_failed1L } for (i in 23:24) { ParamMatrix[i,"LCI"]<-ParamMatrix[i-4,"LCI"]*cont.umult_failed1L } ParamMatrix[25,"LCI"]<-(0.25*(ParamMatrix[15,"LCI"]+ParamMatrix[16,"LCI"]+ParamMatrix[19,"LCI"]+ParamMatrix[20,"LCI"]))*cont.umult_failed2L ParamMatrix[26,"LCI"]<-ParamMatrix[20,"LCI"]*cont.umult_failed2L #probabilities for (i in 27:40) { ParamMatrix[i,"LCI"]<-qbeta(0.025,shape1=ParamMatrix[i,"Alpha"],shape2=ParamMatrix[i,"Beta"]) } for (i in 41:44) { ParamMatrix[i,"LCI"]<-ParamMatrix[i-12,"LCI"]*cont.withd_mult_init } #Column "UCI" #costs for (i in 1:2) { ParamMatrix[i,"UCI"]<-ParamMatrix[i,"Deterministic"] } for (i in 3:7) { ParamMatrix[i,"UCI"]<-qgamma(0.975,shape=ParamMatrix[i,"Alpha"],scale=ParamMatrix[i,"Beta"]) } for (i in 8:11) { ParamMatrix[i,"UCI"]<-ParamMatrix[i,"Deterministic"] } ParamMatrix[12,"UCI"]<-qgamma(0.975,shape=ParamMatrix[12,"Alpha"],scale=ParamMatrix[12,"Beta"]) for (i in 13:14) { ParamMatrix[i,"UCI"]<-ParamMatrix[i,"Deterministic"] } #utilities for (i in 15:16) { ParamMatrix[i,"UCI"]<-qbeta(0.975,shape1=ParamMatrix[i,"Alpha"],shape2=ParamMatrix[i,"Beta"]) } for (i in 17:18) { ParamMatrix[i,"UCI"]<-min(ParamMatrix[i-2,"UCI"]*(1+cont.utilitypercimp_NovelTherap),1) } for (i in 19:20) { ParamMatrix[i,"UCI"]<-qbeta(0.975,shape1=ParamMatrix[i,"Alpha"],shape2=ParamMatrix[i,"Beta"]) } for (i in 21:22) { ParamMatrix[i,"UCI"]<-ParamMatrix[i-6,"UCI"]*cont.umult_failed1L } for (i in 23:24) { ParamMatrix[i,"UCI"]<-ParamMatrix[i-4,"UCI"]*cont.umult_failed1L } ParamMatrix[25,"UCI"]<-(0.25*(ParamMatrix[15,"UCI"]+ParamMatrix[16,"UCI"]+ParamMatrix[19,"UCI"]+ParamMatrix[20,"UCI"]))*cont.umult_failed2L ParamMatrix[26,"UCI"]<-ParamMatrix[20,"UCI"]*cont.umult_failed2L #probabilities for (i in 27:40) { ParamMatrix[i,"UCI"]<-qbeta(0.975,shape1=ParamMatrix[i,"Alpha"],shape2=ParamMatrix[i,"Beta"]) } for (i in 41:44) { ParamMatrix[i,"UCI"]<-ParamMatrix[i-12,"UCI"]*cont.withd_mult_init } #################### #MODEL AS A FUNCTION #################### #MODEL AS A FUNCTION #set Cost Matrix and Trace/Trans Matrices length to 105 - maximum time horizon tested+1 costANDtracematrices_nrows<-105 Pain_Markov <- function(TransArray, stateCost, stateUtil){ trace_matrix <- matrix(NA, nrow=costANDtracematrices_nrows, ncol=ncol(TransArray)) trace_matrix[1,] <- InitVector trace_matrix[2,] <- InitVector %*% TransArray[,,1] for (i in 3:nrow(trace_matrix)){ trace_matrix[i,] <- trace_matrix[i-1,] %*% TransArray[,,i-1] } #hcc = half cycle corrected hcc_trace_matrix <- matrix(NA, nrow=costANDtracematrices_nrows, ncol=ncol(TransArray)) hcc_trace_matrix[1,] <- 0.5*InitVector + 0.5*trace_matrix[2,] for (i in 2:costANDtracematrices_nrows-1){ hcc_trace_matrix[i,] <- 0.5*trace_matrix[i,] + 0.5*trace_matrix[i+1,] } hcc_trace_matrix[costANDtracematrices_nrows,] <- trace_matrix[costANDtracematrices_nrows,] trace_costs1 <- trace_matrix*stateCost trace_qalys1 <- sweep(trace_matrix, MARGIN=2, stateUtil, "*") trace_costs <- hcc_trace_matrix*stateCost trace_qalys <- sweep(hcc_trace_matrix, MARGIN=2, stateUtil, "*") total_costs <- sum(trace_costs) total_qalys <- sum(trace_qalys) trace_costs <- hcc_trace_matrix*stateCost trace_qalys <- sweep(hcc_trace_matrix, MARGIN=2, stateUtil, "*") HealthStateCosts <- colSums(trace_costs[1:cont.TimeHorizon,]) HealthStateQALYs <- colSums(trace_qalys[1:cont.TimeHorizon,]) total_costs <- sum(colSums(trace_costs[1:cont.TimeHorizon,])) total_qalys <- sum(colSums(trace_qalys[1:cont.TimeHorizon,])) obj <- list(costs=total_costs, qalys=total_qalys) invisible(obj) } #### #INPUT VECTORS, PATIENT FLOW SHEETS AND RESULTS #IN ENTIRETY FOR DETERMINISTIC, PROBABILISTIC OR OWSA #### ####################### #DETERMINISTIC ANALYSIS ####################### if (cont.AnalysisType=="Deterministic"){ # Pain_Inputs(ParamMatrix,Deterministic) #INITIAL VECTOR InitVector<-c(1,0,0,0,0, 0,0,0,0,0) #UTILITY VECTORS UtilityVector_Comp<-c(ParamMatrix["p_u_on1LTx_Tx1_noAE","Deterministic"],ParamMatrix["p_u_on1LTx_Tx1_AE","Deterministic"], ParamMatrix["p_u_withdrawn1L_AE","Deterministic"],ParamMatrix["p_u_withdrawn1L_other","Deterministic"], ParamMatrix["p_u_on2LTx_noAE","Deterministic"],ParamMatrix["p_u_on2LTx_AE","Deterministic"], ParamMatrix["p_u_withdrawn2L_AE","Deterministic"],ParamMatrix["p_u_withdrawn2L_other","Deterministic"], ParamMatrix["p_u_3L","Deterministic"],ParamMatrix["p_u_discontinuation","Deterministic"] )*cont.CycleProp UtilityVector_Novel<-UtilityVector_Comp UtilityVector_Novel[1]<-ParamMatrix["p_u_on1LTx_Tx2_noAE","Deterministic"]*cont.CycleProp UtilityVector_Novel[2]<-ParamMatrix["p_u_on1LTx_Tx2_AE","Deterministic"]*cont.CycleProp #COST MATRICES CostMatrix_Comp<-matrix(nrow=costANDtracematrices_nrows,ncol=10) CostMatrix_Comp[,1]<-ParamMatrix["p_c_cycle_tx_tx1","Deterministic"]+ParamMatrix["p_c_cycle_comed_tx1","Deterministic"] CostMatrix_Comp[,2]<-ParamMatrix["p_c_cycle_tx_tx1","Deterministic"]+ParamMatrix["p_c_cycle_comed_tx1","Deterministic"]+ParamMatrix["p_c_cycle_ae","Deterministic"] CostMatrix_Comp[,3]<-ParamMatrix["p_c_cycle_withd_AE","Deterministic"] CostMatrix_Comp[,4]<-ParamMatrix["p_c_cycle_withd_other","Deterministic"] CostMatrix_Comp[,5]<-ParamMatrix["p_c_cycle_2Ltx_tx1arm","Deterministic"] CostMatrix_Comp[,6]<-ParamMatrix["p_c_cycle_2Ltx_tx1arm","Deterministic"]+ParamMatrix["p_c_cycle_ae","Deterministic"] CostMatrix_Comp[,7]<-ParamMatrix["p_c_cycle_withd_AE","Deterministic"] CostMatrix_Comp[,8]<-ParamMatrix["p_c_cycle_withd_other","Deterministic"] CostMatrix_Comp[,9]<-ParamMatrix["p_c_cycle_3Ltx_tx1modelarm","Deterministic"] CostMatrix_Comp[,10]<-ParamMatrix["p_c_cycle_discontinued","Deterministic"] if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { for (i in 2:5){ CostMatrix_Comp[i,1]<-ParamMatrix["p_c_cycle_tx_tx1_init","Deterministic"]+ParamMatrix["p_c_cycle_comed_tx1","Deterministic"] CostMatrix_Comp[i,2]<-ParamMatrix["p_c_cycle_tx_tx1_init","Deterministic"]+ParamMatrix["p_c_cycle_comed_tx1","Deterministic"]+ParamMatrix["p_c_cycle_ae","Deterministic"] }} #NovelTherapy arm CostMatrix_Novel<-CostMatrix_Comp CostMatrix_Novel[,1]<-ParamMatrix["p_c_cycle_tx_tx2","Deterministic"]+ParamMatrix["p_c_cycle_comed_tx2","Deterministic"] CostMatrix_Novel[,2]<-ParamMatrix["p_c_cycle_tx_tx2","Deterministic"]+ParamMatrix["p_c_cycle_comed_tx2","Deterministic"]+ParamMatrix["p_c_cycle_ae","Deterministic"] CostMatrix_Novel[,5]<-ParamMatrix["p_c_cycle_2Ltx_tx2arm","Deterministic"] CostMatrix_Novel[,6]<-ParamMatrix["p_c_cycle_2Ltx_tx2arm","Deterministic"]+ParamMatrix["p_c_cycle_ae","Deterministic"] if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { for (i in 2:5){ CostMatrix_Novel[i,1]<-ParamMatrix["p_c_cycle_tx_tx2_init","Deterministic"]+ParamMatrix["p_c_cycle_comed_tx2","Deterministic"] CostMatrix_Novel[i,2]<-ParamMatrix["p_c_cycle_tx_tx2_init","Deterministic"]+ParamMatrix["p_c_cycle_comed_tx2","Deterministic"]+ParamMatrix["p_c_cycle_ae","Deterministic"] }} #TRANSITION ARRAYS - 1= transitions from 1LTx NO AEs, etc #Note - 3D arrays are required rather than 2D matrices as different transition matrices are required for early cycles if titration is considered TransVec1_Comp<-c((1-ParamMatrix["p_prob_withdAE_Tx1arm_1L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx1arm_1L","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx1arm_1L","Deterministic"]), (1-ParamMatrix["p_prob_withdAE_Tx1arm_1L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx1arm_1L","Deterministic"])*(ParamMatrix["p_prob_AE_Tx1arm_1L","Deterministic"]), ParamMatrix["p_prob_withdAE_Tx1arm_1L","Deterministic"], ParamMatrix["p_prob_withdother_Tx1arm_1L","Deterministic"], 0, 0,0,0,0,0 ) TransVec2_Comp<-c((1-ParamMatrix["p_prob_withdAE_Tx1arm_1L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx1arm_1L","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx1arm_1L","Deterministic"]), (1-ParamMatrix["p_prob_withdAE_Tx1arm_1L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx1arm_1L","Deterministic"])*(ParamMatrix["p_prob_AE_Tx1arm_1L","Deterministic"]), ParamMatrix["p_prob_withdAE_Tx1arm_1L","Deterministic"], ParamMatrix["p_prob_withdother_Tx1arm_1L","Deterministic"], 0, 0,0,0,0,0 ) TransVec3_Comp<-c(0,0,0,0, (1-ParamMatrix["p_prob_discontafter1L","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx1arm_2L","Deterministic"]), (1-ParamMatrix["p_prob_discontafter1L","Deterministic"])*ParamMatrix["p_prob_AE_Tx1arm_2L","Deterministic"], 0,0,0, ParamMatrix["p_prob_discontafter1L","Deterministic"] ) TransVec4_Comp<-c(0,0,0,0, (1-ParamMatrix["p_prob_discontafter1L","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx1arm_2L","Deterministic"]), (1-ParamMatrix["p_prob_discontafter1L","Deterministic"])*ParamMatrix["p_prob_AE_Tx1arm_2L","Deterministic"], 0,0,0, ParamMatrix["p_prob_discontafter1L","Deterministic"] ) TransVec5_Comp<-c(0,0,0,0, (1-ParamMatrix["p_prob_withdAE_Tx1arm_2L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx1arm_2L","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx1arm_2L","Deterministic"]), (1-ParamMatrix["p_prob_withdAE_Tx1arm_2L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx1arm_2L","Deterministic"])*(ParamMatrix["p_prob_AE_Tx1arm_2L","Deterministic"]), ParamMatrix["p_prob_withdAE_Tx1arm_2L","Deterministic"], ParamMatrix["p_prob_withdother_Tx1arm_2L","Deterministic"], 0,0 ) TransVec6_Comp<-c(0,0,0,0, (1-ParamMatrix["p_prob_withdAE_Tx1arm_2L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx1arm_2L","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx1arm_2L","Deterministic"]), (1-ParamMatrix["p_prob_withdAE_Tx1arm_2L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx1arm_2L","Deterministic"])*(ParamMatrix["p_prob_AE_Tx1arm_2L","Deterministic"]), ParamMatrix["p_prob_withdAE_Tx1arm_2L","Deterministic"], ParamMatrix["p_prob_withdother_Tx1arm_2L","Deterministic"], 0,0 ) TransVec7_Comp<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-ParamMatrix["p_prob_discontafter2L","Deterministic"]), ifelse(cont.PatPathway=="Discontinuation",1,ParamMatrix["p_prob_discontafter2L","Deterministic"]) ) TransVec8_Comp<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-ParamMatrix["p_prob_discontafter2L","Deterministic"]), ifelse(cont.PatPathway=="Discontinuation",1,ParamMatrix["p_prob_discontafter2L","Deterministic"]) ) TransVec9_Comp<-c(0,0,0,0,0, 0,0,0,1,0) TransVec10_Comp<-c(0,0,0,0,0, 0,0,0,0,1) TransMat_Comp<-rbind(TransVec1_Comp,TransVec2_Comp,TransVec3_Comp,TransVec4_Comp,TransVec5_Comp, TransVec6_Comp,TransVec7_Comp,TransVec8_Comp,TransVec9_Comp,TransVec10_Comp) colnames(TransMat_Comp)<-c("NoAEs_1L","AEs_1L","WithdAEs_1L","WithdOther_1L","NoAEs_2L","AEs_2L","WithdAEs_2L","WithdOther_1L","3rdL","Discontinuation") rownames(TransMat_Comp)<-colnames(TransMat_Comp) rowSums(TransMat_Comp) #Novel Therapy arm TransVec1_Novel<-c((1-ParamMatrix["p_prob_withdAE_Tx2arm_1L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx2arm_1L","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx2arm_1L","Deterministic"]), (1-ParamMatrix["p_prob_withdAE_Tx2arm_1L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx2arm_1L","Deterministic"])*(ParamMatrix["p_prob_AE_Tx2arm_1L","Deterministic"]), ParamMatrix["p_prob_withdAE_Tx2arm_1L","Deterministic"], ParamMatrix["p_prob_withdother_Tx2arm_1L","Deterministic"], 0, 0,0,0,0,0 ) TransVec2_Novel<-c((1-ParamMatrix["p_prob_withdAE_Tx2arm_1L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx2arm_1L","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx2arm_1L","Deterministic"]), (1-ParamMatrix["p_prob_withdAE_Tx2arm_1L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx2arm_1L","Deterministic"])*(ParamMatrix["p_prob_AE_Tx2arm_1L","Deterministic"]), ParamMatrix["p_prob_withdAE_Tx2arm_1L","Deterministic"], ParamMatrix["p_prob_withdother_Tx2arm_1L","Deterministic"], 0, 0,0,0,0,0 ) TransVec3_Novel<-c(0,0,0,0, (1-ParamMatrix["p_prob_discontafter1L","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx2arm_2L","Deterministic"]), (1-ParamMatrix["p_prob_discontafter1L","Deterministic"])*ParamMatrix["p_prob_AE_Tx2arm_2L","Deterministic"], 0,0,0, ParamMatrix["p_prob_discontafter1L","Deterministic"] ) TransVec4_Novel<-c(0,0,0,0, (1-ParamMatrix["p_prob_discontafter1L","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx2arm_2L","Deterministic"]), (1-ParamMatrix["p_prob_discontafter1L","Deterministic"])*ParamMatrix["p_prob_AE_Tx2arm_2L","Deterministic"], 0,0,0, ParamMatrix["p_prob_discontafter1L","Deterministic"] ) TransVec5_Novel<-c(0,0,0,0, (1-ParamMatrix["p_prob_withdAE_Tx2arm_2L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx2arm_2L","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx2arm_2L","Deterministic"]), (1-ParamMatrix["p_prob_withdAE_Tx2arm_2L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx2arm_2L","Deterministic"])*(ParamMatrix["p_prob_AE_Tx2arm_2L","Deterministic"]), ParamMatrix["p_prob_withdAE_Tx2arm_2L","Deterministic"], ParamMatrix["p_prob_withdother_Tx2arm_2L","Deterministic"], 0,0 ) TransVec6_Novel<-c(0,0,0,0, (1-ParamMatrix["p_prob_withdAE_Tx2arm_2L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx2arm_2L","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx2arm_2L","Deterministic"]), (1-ParamMatrix["p_prob_withdAE_Tx2arm_2L","Deterministic"]-ParamMatrix["p_prob_withdother_Tx2arm_2L","Deterministic"])*(ParamMatrix["p_prob_AE_Tx2arm_2L","Deterministic"]), ParamMatrix["p_prob_withdAE_Tx2arm_2L","Deterministic"], ParamMatrix["p_prob_withdother_Tx2arm_2L","Deterministic"], 0,0 ) TransVec7_Novel<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-ParamMatrix["p_prob_discontafter2L","Deterministic"]), ifelse(cont.PatPathway=="Discontinuation",1,ParamMatrix["p_prob_discontafter2L","Deterministic"]) ) TransVec8_Novel<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-ParamMatrix["p_prob_discontafter2L","Deterministic"]), ifelse(cont.PatPathway=="Discontinuation",1,ParamMatrix["p_prob_discontafter2L","Deterministic"]) ) TransVec9_Novel<-c(0,0,0,0,0, 0,0,0,1,0) TransVec10_Novel<-c(0,0,0,0,0, 0,0,0,0,1) TransMat_Novel<-rbind(TransVec1_Novel,TransVec2_Novel,TransVec3_Novel,TransVec4_Novel,TransVec5_Novel, TransVec6_Novel,TransVec7_Novel,TransVec8_Novel,TransVec9_Novel,TransVec10_Novel) rownames(TransMat_Novel)<-rownames(TransMat_Comp) colnames(TransMat_Novel)<-colnames(TransMat_Comp) rowSums(TransMat_Novel) #### #Generate alternate transition matrix if titration scenario being considered #### if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { #Comp arm InitTransVec1_Comp<-c((1-ParamMatrix["p_prob_withdAE_Tx1arm_1L_init","Deterministic"]-ParamMatrix["p_prob_withdother_Tx1arm_1L_init","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx1arm_1L","Deterministic"]), (1-ParamMatrix["p_prob_withdAE_Tx1arm_1L_init","Deterministic"]-ParamMatrix["p_prob_withdother_Tx1arm_1L_init","Deterministic"])*(ParamMatrix["p_prob_AE_Tx1arm_1L","Deterministic"]), ParamMatrix["p_prob_withdAE_Tx1arm_1L_init","Deterministic"], ParamMatrix["p_prob_withdother_Tx1arm_1L_init","Deterministic"], 0, 0,0,0,0,0 ) InitTransVec2_Comp<-c((1-ParamMatrix["p_prob_withdAE_Tx1arm_1L_init","Deterministic"]-ParamMatrix["p_prob_withdother_Tx1arm_1L_init","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx1arm_1L","Deterministic"]), (1-ParamMatrix["p_prob_withdAE_Tx1arm_1L_init","Deterministic"]-ParamMatrix["p_prob_withdother_Tx1arm_1L_init","Deterministic"])*(ParamMatrix["p_prob_AE_Tx1arm_1L","Deterministic"]), ParamMatrix["p_prob_withdAE_Tx1arm_1L_init","Deterministic"], ParamMatrix["p_prob_withdother_Tx1arm_1L_init","Deterministic"], 0, 0,0,0,0,0 ) InitTransMat_Comp<-rbind(InitTransVec1_Comp,InitTransVec2_Comp,TransVec3_Comp,TransVec4_Comp,TransVec5_Comp, TransVec6_Comp,TransVec7_Comp,TransVec8_Comp,TransVec9_Comp,TransVec10_Comp) rownames(InitTransMat_Comp)<-rownames(TransMat_Comp) colnames(InitTransMat_Comp)<-colnames(TransMat_Comp) rowSums(InitTransMat_Comp) #Novel arm InitTransVec1_Novel<-c((1-ParamMatrix["p_prob_withdAE_Tx2arm_1L_init","Deterministic"]-ParamMatrix["p_prob_withdother_Tx2arm_1L_init","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx2arm_1L","Deterministic"]), (1-ParamMatrix["p_prob_withdAE_Tx2arm_1L_init","Deterministic"]-ParamMatrix["p_prob_withdother_Tx2arm_1L_init","Deterministic"])*(ParamMatrix["p_prob_AE_Tx2arm_1L","Deterministic"]), ParamMatrix["p_prob_withdAE_Tx2arm_1L_init","Deterministic"], ParamMatrix["p_prob_withdother_Tx2arm_1L_init","Deterministic"], 0, 0,0,0,0,0 ) InitTransVec2_Novel<-c((1-ParamMatrix["p_prob_withdAE_Tx2arm_1L_init","Deterministic"]-ParamMatrix["p_prob_withdother_Tx2arm_1L_init","Deterministic"])*(1-ParamMatrix["p_prob_AE_Tx2arm_1L","Deterministic"]), (1-ParamMatrix["p_prob_withdAE_Tx2arm_1L_init","Deterministic"]-ParamMatrix["p_prob_withdother_Tx2arm_1L_init","Deterministic"])*(ParamMatrix["p_prob_AE_Tx2arm_1L","Deterministic"]), ParamMatrix["p_prob_withdAE_Tx2arm_1L_init","Deterministic"], ParamMatrix["p_prob_withdother_Tx2arm_1L_init","Deterministic"], 0, 0,0,0,0,0 ) InitTransMat_Novel<-rbind(InitTransVec1_Novel,InitTransVec2_Novel,TransVec3_Novel,TransVec4_Novel,TransVec5_Novel, TransVec6_Novel,TransVec7_Novel,TransVec8_Novel,TransVec9_Novel,TransVec10_Novel) rownames(InitTransMat_Novel)<-rownames(TransMat_Novel) colnames(InitTransMat_Novel)<-colnames(TransMat_Novel) rowSums(InitTransMat_Novel) } ### #create arrays of matrices to allow time-varying transition probabilities TransArrayComp <- array(data=NA,dim=c(10,10,costANDtracematrices_nrows)) #dim=c(nrow,ncol,nmatrix) TransArrayNovel <- array(data=NA,dim=c(10,10,costANDtracematrices_nrows)) #dim=c(nrow,ncol,nmatrix) for (i in 1:costANDtracematrices_nrows) { TransArrayComp[,,i] <-TransMat_Comp TransArrayNovel[,,i]<-TransMat_Novel } #adapt array if titration is under consideration #### if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { for (i in 1:4) { TransArrayComp[,,i] <-InitTransMat_Comp TransArrayNovel[,,i]<-InitTransMat_Novel } } #check rowSums(TransArrayComp[,,4]) rowSums(TransArrayComp[,,8]) rowSums(TransArrayNovel[,,4]) rowSums(TransArrayNovel[,,8]) #Evaluate Model Results_Comp <- Pain_Markov(TransArrayComp,CostMatrix_Comp,UtilityVector_Comp) Results_Novel <- Pain_Markov(TransArrayNovel,CostMatrix_Novel,UtilityVector_Novel) DET_ICER<-(Results_Novel$costs-Results_Comp$costs)/(Results_Novel$qalys-Results_Comp$qalys) } ####################### #PROBABILISTIC ANALYSIS ####################### if (cont.AnalysisType=="Probabilistic"){ #INITIAL VECTOR InitVector<-c(1,0,0,0,0, 0,0,0,0,0) ### #PSA MATRIX ### #N=cont.nruns PROBABILISTIC VALUES DRAWN FROM A SEPARATE MATRIX PSAinputsMatrix<-matrix(NA,nrow=cont.nruns,ncol=44) colnames(PSAinputsMatrix)<-rownames(ParamMatrix) #costs for (i in 1:2) { PSAinputsMatrix[,i]<-ParamMatrix[i,"Deterministic"] } for (i in 3:7) { PSAinputsMatrix[,i]<-rgamma(cont.nruns,shape=ParamMatrix[i,"Alpha"],scale=ParamMatrix[i,"Beta"]) } for (i in 8:11) { PSAinputsMatrix[,i]<-ParamMatrix[i,"Deterministic"] } PSAinputsMatrix[,12]<-rgamma(cont.nruns,shape=ParamMatrix[12,"Alpha"],scale=ParamMatrix[12,"Beta"]) for (i in 13:14) { PSAinputsMatrix[,i]<-ParamMatrix[i,"Deterministic"] } #utilities for (i in 15:16) { PSAinputsMatrix[,i]<-rbeta(cont.nruns,shape1=ParamMatrix[i,"Alpha"],shape2=ParamMatrix[i,"Beta"]) } for (j in 1:cont.nruns) { for (i in 17:18) { PSAinputsMatrix[j,i]<-min(PSAinputsMatrix[j,i-2]*(1+cont.utilitypercimp_NovelTherap),1) } } for (i in 19:20) { PSAinputsMatrix[,i]<-rbeta(cont.nruns,shape1=ParamMatrix[i,"Alpha"],shape2=ParamMatrix[i,"Beta"]) } for (j in 1:cont.nruns) { for (i in 21:22) { PSAinputsMatrix[j,i]<-PSAinputsMatrix[j,i-6]*cont.umult_failed1L } } for (j in 1:cont.nruns) { for (i in 23:24) { PSAinputsMatrix[j,i]<-PSAinputsMatrix[j,i-4]*cont.umult_failed1L } } PSAinputsMatrix[,25]<-0.25*(PSAinputsMatrix[,15]+PSAinputsMatrix[,16]+PSAinputsMatrix[,17]+PSAinputsMatrix[,18]) PSAinputsMatrix[,26]<-PSAinputsMatrix[,20]*cont.umult_failed2L #probabilities PSAinputsMatrix[,27]<-rbeta(cont.nruns,shape1=ParamMatrix[27,"Alpha"],shape2=ParamMatrix[27,"Beta"]) PSAinputsMatrix[,28]<-PSAinputsMatrix[,27]*(1-cont.prop_improv_AE_noveltherapy) for (i in 29:40) { PSAinputsMatrix[,i]<-rbeta(cont.nruns,shape1=ParamMatrix[i,"Alpha"],shape2=ParamMatrix[i,"Beta"]) } for (i in 41:44) { PSAinputsMatrix[,i]<-PSAinputsMatrix[,i-12]*cont.withd_mult_init } #Transpose for ease of coding, below PSAinputsMatrixT<-t(PSAinputsMatrix) rownames(PSAinputsMatrixT)<-colnames(PSAinputsMatrix) #Create PSA REsults Matrix #Results Matrix PSAresultsMatrix <- matrix(NA,ncol=6,nrow=nrow(PSAinputsMatrix)) colnames(PSAresultsMatrix) <- c("Costs_Comp","QALYs_Comp","Costs_Novel","QALYs_Novel","inc_Costs","inc_QALYs") tail(PSAresultsMatrix) #### #MODEL INPUT MATRICES, MODEL EVALUATION and RESULTS STORE# #### #Input matrix data entry, model evaluation for (z in 1:cont.nruns){ #UTILITY VECTORS UtilityVector_Comp<-c(PSAinputsMatrixT["p_u_on1LTx_Tx1_noAE",z],PSAinputsMatrixT["p_u_on1LTx_Tx1_AE",z], PSAinputsMatrixT["p_u_withdrawn1L_AE",z],PSAinputsMatrixT["p_u_withdrawn1L_other",z], PSAinputsMatrixT["p_u_on2LTx_noAE",z],PSAinputsMatrixT["p_u_on2LTx_AE",z], PSAinputsMatrixT["p_u_withdrawn2L_AE",z],PSAinputsMatrixT["p_u_withdrawn2L_other",z], PSAinputsMatrixT["p_u_3L",z],PSAinputsMatrixT["p_u_discontinuation",z] )*cont.CycleProp UtilityVector_Novel<-UtilityVector_Comp UtilityVector_Novel[1]<-PSAinputsMatrixT["p_u_on1LTx_Tx2_noAE",z]*cont.CycleProp UtilityVector_Novel[2]<-PSAinputsMatrixT["p_u_on1LTx_Tx2_AE",z]*cont.CycleProp #COST MATRICES CostMatrix_Comp<-matrix(nrow=costANDtracematrices_nrows,ncol=10) CostMatrix_Comp[,1]<-PSAinputsMatrixT["p_c_cycle_tx_tx1",z]+PSAinputsMatrixT["p_c_cycle_comed_tx1",z] CostMatrix_Comp[,2]<-PSAinputsMatrixT["p_c_cycle_tx_tx1",z]+PSAinputsMatrixT["p_c_cycle_comed_tx1",z]+PSAinputsMatrixT["p_c_cycle_ae",z] CostMatrix_Comp[,3]<-PSAinputsMatrixT["p_c_cycle_withd_AE",z] CostMatrix_Comp[,4]<-PSAinputsMatrixT["p_c_cycle_withd_other",z] CostMatrix_Comp[,5]<-PSAinputsMatrixT["p_c_cycle_2Ltx_tx1arm",z] CostMatrix_Comp[,6]<-PSAinputsMatrixT["p_c_cycle_2Ltx_tx1arm",z]+PSAinputsMatrixT["p_c_cycle_ae",z] CostMatrix_Comp[,7]<-PSAinputsMatrixT["p_c_cycle_withd_AE",z] CostMatrix_Comp[,8]<-PSAinputsMatrixT["p_c_cycle_withd_other",z] CostMatrix_Comp[,9]<-PSAinputsMatrixT["p_c_cycle_3Ltx_tx1modelarm",z] CostMatrix_Comp[,10]<-PSAinputsMatrixT["p_c_cycle_discontinued",z] if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { for (i in 2:5){ CostMatrix_Comp[i,1]<-PSAinputsMatrixT["p_c_cycle_tx_tx1_init",z]+PSAinputsMatrixT["p_c_cycle_comed_tx1",z] CostMatrix_Comp[i,2]<-PSAinputsMatrixT["p_c_cycle_tx_tx1_init",z]+PSAinputsMatrixT["p_c_cycle_comed_tx1",z]+PSAinputsMatrixT["p_c_cycle_ae",z] }} #NovelTherapy arm CostMatrix_Novel<-CostMatrix_Comp CostMatrix_Novel[,1]<-PSAinputsMatrixT["p_c_cycle_tx_tx2",z]+PSAinputsMatrixT["p_c_cycle_comed_tx2",z] CostMatrix_Novel[,2]<-PSAinputsMatrixT["p_c_cycle_tx_tx2",z]+PSAinputsMatrixT["p_c_cycle_comed_tx2",z]+PSAinputsMatrixT["p_c_cycle_ae",z] CostMatrix_Novel[,5]<-PSAinputsMatrixT["p_c_cycle_2Ltx_tx2arm",z] CostMatrix_Novel[,6]<-PSAinputsMatrixT["p_c_cycle_2Ltx_tx2arm",z]+PSAinputsMatrixT["p_c_cycle_ae",z] if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { for (i in 2:5){ CostMatrix_Novel[i,1]<-PSAinputsMatrixT["p_c_cycle_tx_tx2_init",z]+PSAinputsMatrixT["p_c_cycle_comed_tx2",z] CostMatrix_Novel[i,2]<-PSAinputsMatrixT["p_c_cycle_tx_tx2_init",z]+PSAinputsMatrixT["p_c_cycle_comed_tx2",z]+PSAinputsMatrixT["p_c_cycle_ae",z] }} #TRANSITION ARRAYS - 1= transitions from 1LTx NO AEs, etc #Note - 3D arrays are required rather than 2D matrices as different transition matrices are required for early cycles if titration is considered TransVec1_Comp<-c((1-PSAinputsMatrixT["p_prob_withdAE_Tx1arm_1L",z]-PSAinputsMatrixT["p_prob_withdother_Tx1arm_1L",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx1arm_1L",z]), (1-PSAinputsMatrixT["p_prob_withdAE_Tx1arm_1L",z]-PSAinputsMatrixT["p_prob_withdother_Tx1arm_1L",z])*(PSAinputsMatrixT["p_prob_AE_Tx1arm_1L",z]), PSAinputsMatrixT["p_prob_withdAE_Tx1arm_1L",z], PSAinputsMatrixT["p_prob_withdother_Tx1arm_1L",z], 0, 0,0,0,0,0 ) TransVec2_Comp<-c((1-PSAinputsMatrixT["p_prob_withdAE_Tx1arm_1L",z]-PSAinputsMatrixT["p_prob_withdother_Tx1arm_1L",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx1arm_1L",z]), (1-PSAinputsMatrixT["p_prob_withdAE_Tx1arm_1L",z]-PSAinputsMatrixT["p_prob_withdother_Tx1arm_1L",z])*(PSAinputsMatrixT["p_prob_AE_Tx1arm_1L",z]), PSAinputsMatrixT["p_prob_withdAE_Tx1arm_1L",z], PSAinputsMatrixT["p_prob_withdother_Tx1arm_1L",z], 0, 0,0,0,0,0 ) TransVec3_Comp<-c(0,0,0,0, (1-PSAinputsMatrixT["p_prob_discontafter1L",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx1arm_2L",z]), (1-PSAinputsMatrixT["p_prob_discontafter1L",z])*PSAinputsMatrixT["p_prob_AE_Tx1arm_2L",z], 0,0,0, PSAinputsMatrixT["p_prob_discontafter1L",z] ) TransVec4_Comp<-c(0,0,0,0, (1-PSAinputsMatrixT["p_prob_discontafter1L",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx1arm_2L",z]), (1-PSAinputsMatrixT["p_prob_discontafter1L",z])*PSAinputsMatrixT["p_prob_AE_Tx1arm_2L",z], 0,0,0, PSAinputsMatrixT["p_prob_discontafter1L",z] ) TransVec5_Comp<-c(0,0,0,0, (1-PSAinputsMatrixT["p_prob_withdAE_Tx1arm_2L",z]-PSAinputsMatrixT["p_prob_withdother_Tx1arm_2L",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx1arm_2L",z]), (1-PSAinputsMatrixT["p_prob_withdAE_Tx1arm_2L",z]-PSAinputsMatrixT["p_prob_withdother_Tx1arm_2L",z])*(PSAinputsMatrixT["p_prob_AE_Tx1arm_2L",z]), PSAinputsMatrixT["p_prob_withdAE_Tx1arm_2L",z], PSAinputsMatrixT["p_prob_withdother_Tx1arm_2L",z], 0,0 ) TransVec6_Comp<-c(0,0,0,0, (1-PSAinputsMatrixT["p_prob_withdAE_Tx1arm_2L",z]-PSAinputsMatrixT["p_prob_withdother_Tx1arm_2L",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx1arm_2L",z]), (1-PSAinputsMatrixT["p_prob_withdAE_Tx1arm_2L",z]-PSAinputsMatrixT["p_prob_withdother_Tx1arm_2L",z])*(PSAinputsMatrixT["p_prob_AE_Tx1arm_2L",z]), PSAinputsMatrixT["p_prob_withdAE_Tx1arm_2L",z], PSAinputsMatrixT["p_prob_withdother_Tx1arm_2L",z], 0,0 ) TransVec7_Comp<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-PSAinputsMatrixT["p_prob_discontafter2L",z]), ifelse(cont.PatPathway=="Discontinuation",1,PSAinputsMatrixT["p_prob_discontafter2L",z]) ) TransVec8_Comp<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-PSAinputsMatrixT["p_prob_discontafter2L",z]), ifelse(cont.PatPathway=="Discontinuation",1,PSAinputsMatrixT["p_prob_discontafter2L",z]) ) TransVec9_Comp<-c(0,0,0,0,0, 0,0,0,1,0) TransVec10_Comp<-c(0,0,0,0,0, 0,0,0,0,1) TransMat_Comp<-rbind(TransVec1_Comp,TransVec2_Comp,TransVec3_Comp,TransVec4_Comp,TransVec5_Comp, TransVec6_Comp,TransVec7_Comp,TransVec8_Comp,TransVec9_Comp,TransVec10_Comp) colnames(TransMat_Comp)<-c("NoAEs_1L","AEs_1L","WithdAEs_1L","WithdOther_1L","NoAEs_2L","AEs_2L","WithdAEs_2L","WithdOther_1L","3rdL","Discontinuation") rownames(TransMat_Comp)<-colnames(TransMat_Comp) rowSums(TransMat_Comp) #Novel Therapy arm TransVec1_Novel<-c((1-PSAinputsMatrixT["p_prob_withdAE_Tx2arm_1L",z]-PSAinputsMatrixT["p_prob_withdother_Tx2arm_1L",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx2arm_1L",z]), (1-PSAinputsMatrixT["p_prob_withdAE_Tx2arm_1L",z]-PSAinputsMatrixT["p_prob_withdother_Tx2arm_1L",z])*(PSAinputsMatrixT["p_prob_AE_Tx2arm_1L",z]), PSAinputsMatrixT["p_prob_withdAE_Tx2arm_1L",z], PSAinputsMatrixT["p_prob_withdother_Tx2arm_1L",z], 0, 0,0,0,0,0 ) TransVec2_Novel<-c((1-PSAinputsMatrixT["p_prob_withdAE_Tx2arm_1L",z]-PSAinputsMatrixT["p_prob_withdother_Tx2arm_1L",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx2arm_1L",z]), (1-PSAinputsMatrixT["p_prob_withdAE_Tx2arm_1L",z]-PSAinputsMatrixT["p_prob_withdother_Tx2arm_1L",z])*(PSAinputsMatrixT["p_prob_AE_Tx2arm_1L",z]), PSAinputsMatrixT["p_prob_withdAE_Tx2arm_1L",z], PSAinputsMatrixT["p_prob_withdother_Tx2arm_1L",z], 0, 0,0,0,0,0 ) TransVec3_Novel<-c(0,0,0,0, (1-PSAinputsMatrixT["p_prob_discontafter1L",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx2arm_2L",z]), (1-PSAinputsMatrixT["p_prob_discontafter1L",z])*PSAinputsMatrixT["p_prob_AE_Tx2arm_2L",z], 0,0,0, PSAinputsMatrixT["p_prob_discontafter1L",z] ) TransVec4_Novel<-c(0,0,0,0, (1-PSAinputsMatrixT["p_prob_discontafter1L",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx2arm_2L",z]), (1-PSAinputsMatrixT["p_prob_discontafter1L",z])*PSAinputsMatrixT["p_prob_AE_Tx2arm_2L",z], 0,0,0, PSAinputsMatrixT["p_prob_discontafter1L",z] ) TransVec5_Novel<-c(0,0,0,0, (1-PSAinputsMatrixT["p_prob_withdAE_Tx2arm_2L",z]-PSAinputsMatrixT["p_prob_withdother_Tx2arm_2L",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx2arm_2L",z]), (1-PSAinputsMatrixT["p_prob_withdAE_Tx2arm_2L",z]-PSAinputsMatrixT["p_prob_withdother_Tx2arm_2L",z])*(PSAinputsMatrixT["p_prob_AE_Tx2arm_2L",z]), PSAinputsMatrixT["p_prob_withdAE_Tx2arm_2L",z], PSAinputsMatrixT["p_prob_withdother_Tx2arm_2L",z], 0,0 ) TransVec6_Novel<-c(0,0,0,0, (1-PSAinputsMatrixT["p_prob_withdAE_Tx2arm_2L",z]-PSAinputsMatrixT["p_prob_withdother_Tx2arm_2L",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx2arm_2L",z]), (1-PSAinputsMatrixT["p_prob_withdAE_Tx2arm_2L",z]-PSAinputsMatrixT["p_prob_withdother_Tx2arm_2L",z])*(PSAinputsMatrixT["p_prob_AE_Tx2arm_2L",z]), PSAinputsMatrixT["p_prob_withdAE_Tx2arm_2L",z], PSAinputsMatrixT["p_prob_withdother_Tx2arm_2L",z], 0,0 ) TransVec7_Novel<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-PSAinputsMatrixT["p_prob_discontafter2L",z]), ifelse(cont.PatPathway=="Discontinuation",1,PSAinputsMatrixT["p_prob_discontafter2L",z]) ) TransVec8_Novel<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-PSAinputsMatrixT["p_prob_discontafter2L",z]), ifelse(cont.PatPathway=="Discontinuation",1,PSAinputsMatrixT["p_prob_discontafter2L",z]) ) TransVec9_Novel<-c(0,0,0,0,0, 0,0,0,1,0) TransVec10_Novel<-c(0,0,0,0,0, 0,0,0,0,1) TransMat_Novel<-rbind(TransVec1_Novel,TransVec2_Novel,TransVec3_Novel,TransVec4_Novel,TransVec5_Novel, TransVec6_Novel,TransVec7_Novel,TransVec8_Novel,TransVec9_Novel,TransVec10_Novel) rownames(TransMat_Novel)<-rownames(TransMat_Comp) colnames(TransMat_Novel)<-colnames(TransMat_Comp) rowSums(TransMat_Novel) #### #Generate alternate transition matrix if titration scenario being considered #### if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { #Comp arm InitTransVec1_Comp<-c((1-PSAinputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z]-PSAinputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx1arm_1L",z]), (1-PSAinputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z]-PSAinputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z])*(PSAinputsMatrixT["p_prob_AE_Tx1arm_1L",z]), PSAinputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z], PSAinputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z], 0, 0,0,0,0,0 ) InitTransVec2_Comp<-c((1-PSAinputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z]-PSAinputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx1arm_1L",z]), (1-PSAinputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z]-PSAinputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z])*(PSAinputsMatrixT["p_prob_AE_Tx1arm_1L",z]), PSAinputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z], PSAinputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z], 0, 0,0,0,0,0 ) InitTransMat_Comp<-rbind(InitTransVec1_Comp,InitTransVec2_Comp,TransVec3_Comp,TransVec4_Comp,TransVec5_Comp, TransVec6_Comp,TransVec7_Comp,TransVec8_Comp,TransVec9_Comp,TransVec10_Comp) rownames(InitTransMat_Comp)<-rownames(TransMat_Comp) colnames(InitTransMat_Comp)<-colnames(TransMat_Comp) rowSums(InitTransMat_Comp) #Novel arm InitTransVec1_Novel<-c((1-PSAinputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z]-PSAinputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx2arm_1L",z]), (1-PSAinputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z]-PSAinputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z])*(PSAinputsMatrixT["p_prob_AE_Tx2arm_1L",z]), PSAinputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z], PSAinputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z], 0, 0,0,0,0,0 ) InitTransVec2_Novel<-c((1-PSAinputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z]-PSAinputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z])*(1-PSAinputsMatrixT["p_prob_AE_Tx2arm_1L",z]), (1-PSAinputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z]-PSAinputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z])*(PSAinputsMatrixT["p_prob_AE_Tx2arm_1L",z]), PSAinputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z], PSAinputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z], 0, 0,0,0,0,0 ) InitTransMat_Novel<-rbind(InitTransVec1_Novel,InitTransVec2_Novel,TransVec3_Novel,TransVec4_Novel,TransVec5_Novel, TransVec6_Novel,TransVec7_Novel,TransVec8_Novel,TransVec9_Novel,TransVec10_Novel) rownames(InitTransMat_Novel)<-rownames(TransMat_Novel) colnames(InitTransMat_Novel)<-colnames(TransMat_Novel) rowSums(InitTransMat_Novel) } ### #create arrays of matrices to allow time-varying transition probabilities TransArrayComp <- array(data=NA,dim=c(10,10,costANDtracematrices_nrows)) #dim=c(nrow,ncol,nmatrix) TransArrayNovel <- array(data=NA,dim=c(10,10,costANDtracematrices_nrows)) #dim=c(nrow,ncol,nmatrix) for (i in 1:costANDtracematrices_nrows) { TransArrayComp[,,i] <-TransMat_Comp TransArrayNovel[,,i]<-TransMat_Novel } #adapt array if titration is under consideration #### if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { for (i in 1:4) { TransArrayComp[,,i] <-InitTransMat_Comp TransArrayNovel[,,i]<-InitTransMat_Novel } } #check rowSums(TransArrayComp[,,4]) rowSums(TransArrayComp[,,8]) rowSums(TransArrayNovel[,,4]) rowSums(TransArrayNovel[,,8]) #Evaluate Model Results_Comp <- Pain_Markov(TransArrayComp,CostMatrix_Comp,UtilityVector_Comp) Results_Novel <- Pain_Markov(TransArrayNovel,CostMatrix_Novel,UtilityVector_Novel) #copy PSA results to matrix PSAresultsMatrix[z,"Costs_Comp"] <- Results_Comp$costs PSAresultsMatrix[z,"QALYs_Comp"] <- Results_Comp$qalys PSAresultsMatrix[z,"Costs_Novel"] <- Results_Novel$costs PSAresultsMatrix[z,"QALYs_Novel"] <- Results_Novel$qalys PSAresultsMatrix[z,"inc_Costs"] <- Results_Novel$costs-Results_Comp$costs PSAresultsMatrix[z,"inc_QALYs"] <- Results_Novel$qalys-Results_Comp$qalys } #ANALYSE RESULTS #summarise mean results for each recorded output colMeans(PSAresultsMatrix) #PSA ICER PSA_ICER <- mean(PSAresultsMatrix[ ,"inc_Costs"])/mean(PSAresultsMatrix[ ,"inc_QALYs"]) ## SCATTERPLOT plot(PSAresultsMatrix[ ,"inc_QALYs"],PSAresultsMatrix[ ,"inc_Costs"], xlim=c(-0.1,0.2), #column limits ylim=c(0,5000), xaxt="n", #don't show x axis beside title yaxt="n", # "" col="blue", #data points colours bty="n", #don't show border xlab="Incremental QALY gain", #title for the x axis ylab="Incremental costs (£s)") # "" abline(0,20000,lwd=2,lty=2,col="red") # lwd="line width" lty="line type" abline(0,30000,lwd=2,lty=2,col="orange") points(mean(PSAresultsMatrix[,"inc_QALYs"]), mean(PSAresultsMatrix[,"inc_Costs"]), col="green", pch=3, # plotting character (type eg 4 is "x") cex=2) # character expansion axis(1,pos=0) # axis position axis(2,pos=0) title(main="Cost effectiveness plane - (Novel versus Comp) ") legend(x=-0.1, #coordinates to position the legend y=5000, col=c("blue","green","red","orange"), lty=1, cex=0.5, legend=c("PSA datapoint","Mean PSA ICER","£20,000 WTP","£30,000 WTP"), bty="n") ## CEAC lambdas <- seq(0,40000,1000) netBenefits <- matrix(NA, ncol=length(lambdas), nrow=nrow(PSAresultsMatrix)) colnames(netBenefits) <- lambdas #matches each value of lambdas to a column for (i in 1:length(lambdas)){ netBenefits[,i] <- PSAresultsMatrix[,"inc_QALYs"]*lambdas[i] - PSAresultsMatrix[,"inc_Costs"] } eNB <- colMeans(netBenefits) ceacData <- colMeans(netBenefits>0) #returns the proportion of col in which NB>0! How useful plot(lambdas, ceacData, type="l", col="red", xlab="Willingness to pay for a QALY (£)", ylab="P(Cost effective)", main="Cost Effectiveness Acceptability Curve") # lines(lambdas,1-ceacData,col="blue") legend(x=22000, #coordinates to position the legend y=0.8, # col=c("red","blue"), col="red", lty=1, # legend=c("Novel", "Comp"), legend="Novel Therapy", bty="n") } ############## #OWSA ANALYSIS ############## if (cont.AnalysisType=="OWSA"){ #INITIAL VECTOR InitVector<-c(1,0,0,0,0, 0,0,0,0,0) #OWSA INPUT AND OUTPUT MATRICES OWSA_LCI_inputsMatrix<-matrix(NA,nrow=nrow(ParamMatrix),ncol=nrow(ParamMatrix)) colnames(OWSA_LCI_inputsMatrix)<-rownames(ParamMatrix) OWSA_UCI_inputsMatrix<-OWSA_LCI_inputsMatrix for (i in 1:nrow(OWSA_LCI_inputsMatrix)) { OWSA_LCI_inputsMatrix[,i]<-ParamMatrix[i,"Deterministic"] } #Transpose for ease of coding, below OWSA_LCI_inputsMatrixT<-t(OWSA_LCI_inputsMatrix) rownames(OWSA_LCI_inputsMatrixT)<-colnames(OWSA_LCI_inputsMatrix) OWSA_UCI_inputsMatrixT<-OWSA_LCI_inputsMatrixT tail(OWSA_UCI_inputsMatrixT) #Results Matrix OWSA_resultsMatrix <- matrix(NA,ncol=13,nrow=nrow(OWSA_LCI_inputsMatrix)) colnames(OWSA_resultsMatrix) <- c("Costs_Comp_LCI","QALYs_Comp_LCI","Costs_Novel_LCI","QALYs_Novel_LCI","ICER_LCI", "Costs_Comp_UCI","QALYs_Comp_UCI","Costs_Novel_UCI","QALYs_Novel_UCI","ICER_UCI", "INMB_Lower_Bound","INMB_Upper_Bound","INMB_Difference") rownames(OWSA_resultsMatrix) <- rownames(ParamMatrix) tail(OWSA_resultsMatrix) #loop to set input matrices, evaluate model and record results for each OWSA setting for (z in 1:nrow(OWSA_LCI_inputsMatrix)) { #LCI FIRST #adjust input matrix OWSA_LCI_inputsMatrixT[z,z]<-ParamMatrix[z,"LCI"] #specify model input matrices #UTILITY VECTORS UtilityVector_Comp<-c(OWSA_LCI_inputsMatrixT["p_u_on1LTx_Tx1_noAE",z],OWSA_LCI_inputsMatrixT["p_u_on1LTx_Tx1_AE",z], OWSA_LCI_inputsMatrixT["p_u_withdrawn1L_AE",z],OWSA_LCI_inputsMatrixT["p_u_withdrawn1L_other",z], OWSA_LCI_inputsMatrixT["p_u_on2LTx_noAE",z],OWSA_LCI_inputsMatrixT["p_u_on2LTx_AE",z], OWSA_LCI_inputsMatrixT["p_u_withdrawn2L_AE",z],OWSA_LCI_inputsMatrixT["p_u_withdrawn2L_other",z], OWSA_LCI_inputsMatrixT["p_u_3L",z],OWSA_LCI_inputsMatrixT["p_u_discontinuation",z] )*cont.CycleProp UtilityVector_Novel<-UtilityVector_Comp UtilityVector_Novel[1]<-OWSA_LCI_inputsMatrixT["p_u_on1LTx_Tx2_noAE",z]*cont.CycleProp UtilityVector_Novel[2]<-OWSA_LCI_inputsMatrixT["p_u_on1LTx_Tx2_AE",z]*cont.CycleProp #COST MATRICES CostMatrix_Comp<-matrix(nrow=costANDtracematrices_nrows,ncol=10) CostMatrix_Comp[,1]<-OWSA_LCI_inputsMatrixT["p_c_cycle_tx_tx1",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_comed_tx1",z] CostMatrix_Comp[,2]<-OWSA_LCI_inputsMatrixT["p_c_cycle_tx_tx1",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_comed_tx1",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_ae",z] CostMatrix_Comp[,3]<-OWSA_LCI_inputsMatrixT["p_c_cycle_withd_AE",z] CostMatrix_Comp[,4]<-OWSA_LCI_inputsMatrixT["p_c_cycle_withd_other",z] CostMatrix_Comp[,5]<-OWSA_LCI_inputsMatrixT["p_c_cycle_2Ltx_tx1arm",z] CostMatrix_Comp[,6]<-OWSA_LCI_inputsMatrixT["p_c_cycle_2Ltx_tx1arm",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_ae",z] CostMatrix_Comp[,7]<-OWSA_LCI_inputsMatrixT["p_c_cycle_withd_AE",z] CostMatrix_Comp[,8]<-OWSA_LCI_inputsMatrixT["p_c_cycle_withd_other",z] CostMatrix_Comp[,9]<-OWSA_LCI_inputsMatrixT["p_c_cycle_3Ltx_tx1modelarm",z] CostMatrix_Comp[,10]<-OWSA_LCI_inputsMatrixT["p_c_cycle_discontinued",z] if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { for (i in 2:5){ CostMatrix_Comp[i,1]<-OWSA_LCI_inputsMatrixT["p_c_cycle_tx_tx1_init",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_comed_tx1",z] CostMatrix_Comp[i,2]<-OWSA_LCI_inputsMatrixT["p_c_cycle_tx_tx1_init",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_comed_tx1",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_ae",z] }} #NovelTherapy arm CostMatrix_Novel<-CostMatrix_Comp CostMatrix_Novel[,1]<-OWSA_LCI_inputsMatrixT["p_c_cycle_tx_tx2",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_comed_tx2",z] CostMatrix_Novel[,2]<-OWSA_LCI_inputsMatrixT["p_c_cycle_tx_tx2",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_comed_tx2",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_ae",z] CostMatrix_Novel[,5]<-OWSA_LCI_inputsMatrixT["p_c_cycle_2Ltx_tx2arm",z] CostMatrix_Novel[,6]<-OWSA_LCI_inputsMatrixT["p_c_cycle_2Ltx_tx2arm",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_ae",z] if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { for (i in 2:5){ CostMatrix_Novel[i,1]<-OWSA_LCI_inputsMatrixT["p_c_cycle_tx_tx2_init",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_comed_tx2",z] CostMatrix_Novel[i,2]<-OWSA_LCI_inputsMatrixT["p_c_cycle_tx_tx2_init",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_comed_tx2",z]+OWSA_LCI_inputsMatrixT["p_c_cycle_ae",z] }} #TRANSITION ARRAYS - 1= transitions from 1LTx NO AEs, etc #Note - 3D arrays are required rather than 2D matrices as different transition matrices are required for early cycles if titration is considered TransVec1_Comp<-c((1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L",z])*(OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L",z], OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L",z], 0, 0,0,0,0,0 ) TransVec2_Comp<-c((1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L",z])*(OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L",z], OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L",z], 0, 0,0,0,0,0 ) TransVec3_Comp<-c(0,0,0,0, (1-OWSA_LCI_inputsMatrixT["p_prob_discontafter1L",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_discontafter1L",z])*OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z], 0,0,0, OWSA_LCI_inputsMatrixT["p_prob_discontafter1L",z] ) TransVec4_Comp<-c(0,0,0,0, (1-OWSA_LCI_inputsMatrixT["p_prob_discontafter1L",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_discontafter1L",z])*OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z], 0,0,0, OWSA_LCI_inputsMatrixT["p_prob_discontafter1L",z] ) TransVec5_Comp<-c(0,0,0,0, (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_2L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_2L",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_2L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_2L",z])*(OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z]), OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_2L",z], OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_2L",z], 0,0 ) TransVec6_Comp<-c(0,0,0,0, (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_2L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_2L",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_2L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_2L",z])*(OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z]), OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_2L",z], OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_2L",z], 0,0 ) TransVec7_Comp<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-OWSA_LCI_inputsMatrixT["p_prob_discontafter2L",z]), ifelse(cont.PatPathway=="Discontinuation",1,OWSA_LCI_inputsMatrixT["p_prob_discontafter2L",z]) ) TransVec8_Comp<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-OWSA_LCI_inputsMatrixT["p_prob_discontafter2L",z]), ifelse(cont.PatPathway=="Discontinuation",1,OWSA_LCI_inputsMatrixT["p_prob_discontafter2L",z]) ) TransVec9_Comp<-c(0,0,0,0,0, 0,0,0,1,0) TransVec10_Comp<-c(0,0,0,0,0, 0,0,0,0,1) TransMat_Comp<-rbind(TransVec1_Comp,TransVec2_Comp,TransVec3_Comp,TransVec4_Comp,TransVec5_Comp, TransVec6_Comp,TransVec7_Comp,TransVec8_Comp,TransVec9_Comp,TransVec10_Comp) colnames(TransMat_Comp)<-c("NoAEs_1L","AEs_1L","WithdAEs_1L","WithdOther_1L","NoAEs_2L","AEs_2L","WithdAEs_2L","WithdOther_1L","3rdL","Discontinuation") rownames(TransMat_Comp)<-colnames(TransMat_Comp) rowSums(TransMat_Comp) #Novel Therapy arm TransVec1_Novel<-c((1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L",z])*(OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L",z], OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L",z], 0, 0,0,0,0,0 ) TransVec2_Novel<-c((1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L",z])*(OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L",z], OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L",z], 0, 0,0,0,0,0 ) TransVec3_Novel<-c(0,0,0,0, (1-OWSA_LCI_inputsMatrixT["p_prob_discontafter1L",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_discontafter1L",z])*OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z], 0,0,0, OWSA_LCI_inputsMatrixT["p_prob_discontafter1L",z] ) TransVec4_Novel<-c(0,0,0,0, (1-OWSA_LCI_inputsMatrixT["p_prob_discontafter1L",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_discontafter1L",z])*OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z], 0,0,0, OWSA_LCI_inputsMatrixT["p_prob_discontafter1L",z] ) TransVec5_Novel<-c(0,0,0,0, (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_2L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_2L",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_2L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_2L",z])*(OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z]), OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_2L",z], OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_2L",z], 0,0 ) TransVec6_Novel<-c(0,0,0,0, (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_2L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_2L",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_2L",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_2L",z])*(OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z]), OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_2L",z], OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_2L",z], 0,0 ) TransVec7_Novel<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-OWSA_LCI_inputsMatrixT["p_prob_discontafter2L",z]), ifelse(cont.PatPathway=="Discontinuation",1,OWSA_LCI_inputsMatrixT["p_prob_discontafter2L",z]) ) TransVec8_Novel<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-OWSA_LCI_inputsMatrixT["p_prob_discontafter2L",z]), ifelse(cont.PatPathway=="Discontinuation",1,OWSA_LCI_inputsMatrixT["p_prob_discontafter2L",z]) ) TransVec9_Novel<-c(0,0,0,0,0, 0,0,0,1,0) TransVec10_Novel<-c(0,0,0,0,0, 0,0,0,0,1) TransMat_Novel<-rbind(TransVec1_Novel,TransVec2_Novel,TransVec3_Novel,TransVec4_Novel,TransVec5_Novel, TransVec6_Novel,TransVec7_Novel,TransVec8_Novel,TransVec9_Novel,TransVec10_Novel) rownames(TransMat_Novel)<-rownames(TransMat_Comp) colnames(TransMat_Novel)<-colnames(TransMat_Comp) rowSums(TransMat_Novel) #### #Generate alternate transition matrix if titration scenario being considered #### if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { #Comp arm InitTransVec1_Comp<-c((1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z])*(OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z], OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z], 0, 0,0,0,0,0 ) InitTransVec2_Comp<-c((1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z])*(OWSA_LCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z], OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z], 0, 0,0,0,0,0 ) InitTransMat_Comp<-rbind(InitTransVec1_Comp,InitTransVec2_Comp,TransVec3_Comp,TransVec4_Comp,TransVec5_Comp, TransVec6_Comp,TransVec7_Comp,TransVec8_Comp,TransVec9_Comp,TransVec10_Comp) rownames(InitTransMat_Comp)<-rownames(TransMat_Comp) colnames(InitTransMat_Comp)<-colnames(TransMat_Comp) rowSums(InitTransMat_Comp) #Novel arm InitTransVec1_Novel<-c((1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z])*(OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z], OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z], 0, 0,0,0,0,0 ) InitTransVec2_Novel<-c((1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z])*(1-OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), (1-OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z]-OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z])*(OWSA_LCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), OWSA_LCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z], OWSA_LCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z], 0, 0,0,0,0,0 ) InitTransMat_Novel<-rbind(InitTransVec1_Novel,InitTransVec2_Novel,TransVec3_Novel,TransVec4_Novel,TransVec5_Novel, TransVec6_Novel,TransVec7_Novel,TransVec8_Novel,TransVec9_Novel,TransVec10_Novel) rownames(InitTransMat_Novel)<-rownames(TransMat_Novel) colnames(InitTransMat_Novel)<-colnames(TransMat_Novel) rowSums(InitTransMat_Novel) } ### #create arrays of matrices to allow time-varying transition probabilities TransArrayComp <- array(data=NA,dim=c(10,10,costANDtracematrices_nrows)) #dim=c(nrow,ncol,nmatrix) TransArrayNovel <- array(data=NA,dim=c(10,10,costANDtracematrices_nrows)) #dim=c(nrow,ncol,nmatrix) for (i in 1:costANDtracematrices_nrows) { TransArrayComp[,,i] <-TransMat_Comp TransArrayNovel[,,i]<-TransMat_Novel } #adapt array if titration is under consideration #### if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { for (i in 1:4) { TransArrayComp[,,i] <-InitTransMat_Comp TransArrayNovel[,,i]<-InitTransMat_Novel } } #check rowSums(TransArrayComp[,,4]) rowSums(TransArrayComp[,,8]) rowSums(TransArrayNovel[,,4]) rowSums(TransArrayNovel[,,8]) #Evaluate Model Results_Comp <- Pain_Markov(TransArrayComp,CostMatrix_Comp,UtilityVector_Comp) Results_Novel <- Pain_Markov(TransArrayNovel,CostMatrix_Novel,UtilityVector_Novel) #copy PSA results to matrix OWSA_resultsMatrix[z,"Costs_Comp_LCI"] <- Results_Comp$costs OWSA_resultsMatrix[z,"QALYs_Comp_LCI"] <- Results_Comp$qalys OWSA_resultsMatrix[z,"Costs_Novel_LCI"] <- Results_Novel$costs OWSA_resultsMatrix[z,"QALYs_Novel_LCI"] <- Results_Novel$qalys OWSA_resultsMatrix[z,"ICER_LCI"] <- (Results_Novel$costs-Results_Comp$costs)/(Results_Novel$qalys-Results_Comp$qalys) #repeat for UCI #adjust input matrix OWSA_UCI_inputsMatrixT[z,z]<-ParamMatrix[z,"UCI"] #specify model input matrices #UTILITY VECTORS UtilityVector_Comp<-c(OWSA_UCI_inputsMatrixT["p_u_on1LTx_Tx1_noAE",z],OWSA_UCI_inputsMatrixT["p_u_on1LTx_Tx1_AE",z], OWSA_UCI_inputsMatrixT["p_u_withdrawn1L_AE",z],OWSA_UCI_inputsMatrixT["p_u_withdrawn1L_other",z], OWSA_UCI_inputsMatrixT["p_u_on2LTx_noAE",z],OWSA_UCI_inputsMatrixT["p_u_on2LTx_AE",z], OWSA_UCI_inputsMatrixT["p_u_withdrawn2L_AE",z],OWSA_UCI_inputsMatrixT["p_u_withdrawn2L_other",z], OWSA_UCI_inputsMatrixT["p_u_3L",z],OWSA_UCI_inputsMatrixT["p_u_discontinuation",z] )*cont.CycleProp UtilityVector_Novel<-UtilityVector_Comp UtilityVector_Novel[1]<-OWSA_UCI_inputsMatrixT["p_u_on1LTx_Tx2_noAE",z]*cont.CycleProp UtilityVector_Novel[2]<-OWSA_UCI_inputsMatrixT["p_u_on1LTx_Tx2_AE",z]*cont.CycleProp #COST MATRICES CostMatrix_Comp<-matrix(nrow=costANDtracematrices_nrows,ncol=10) CostMatrix_Comp[,1]<-OWSA_UCI_inputsMatrixT["p_c_cycle_tx_tx1",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_comed_tx1",z] CostMatrix_Comp[,2]<-OWSA_UCI_inputsMatrixT["p_c_cycle_tx_tx1",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_comed_tx1",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_ae",z] CostMatrix_Comp[,3]<-OWSA_UCI_inputsMatrixT["p_c_cycle_withd_AE",z] CostMatrix_Comp[,4]<-OWSA_UCI_inputsMatrixT["p_c_cycle_withd_other",z] CostMatrix_Comp[,5]<-OWSA_UCI_inputsMatrixT["p_c_cycle_2Ltx_tx1arm",z] CostMatrix_Comp[,6]<-OWSA_UCI_inputsMatrixT["p_c_cycle_2Ltx_tx1arm",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_ae",z] CostMatrix_Comp[,7]<-OWSA_UCI_inputsMatrixT["p_c_cycle_withd_AE",z] CostMatrix_Comp[,8]<-OWSA_UCI_inputsMatrixT["p_c_cycle_withd_other",z] CostMatrix_Comp[,9]<-OWSA_UCI_inputsMatrixT["p_c_cycle_3Ltx_tx1modelarm",z] CostMatrix_Comp[,10]<-OWSA_UCI_inputsMatrixT["p_c_cycle_discontinued",z] if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { for (i in 2:5){ CostMatrix_Comp[i,1]<-OWSA_UCI_inputsMatrixT["p_c_cycle_tx_tx1_init",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_comed_tx1",z] CostMatrix_Comp[i,2]<-OWSA_UCI_inputsMatrixT["p_c_cycle_tx_tx1_init",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_comed_tx1",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_ae",z] }} #NovelTherapy arm CostMatrix_Novel<-CostMatrix_Comp CostMatrix_Novel[,1]<-OWSA_UCI_inputsMatrixT["p_c_cycle_tx_tx2",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_comed_tx2",z] CostMatrix_Novel[,2]<-OWSA_UCI_inputsMatrixT["p_c_cycle_tx_tx2",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_comed_tx2",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_ae",z] CostMatrix_Novel[,5]<-OWSA_UCI_inputsMatrixT["p_c_cycle_2Ltx_tx2arm",z] CostMatrix_Novel[,6]<-OWSA_UCI_inputsMatrixT["p_c_cycle_2Ltx_tx2arm",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_ae",z] if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { for (i in 2:5){ CostMatrix_Novel[i,1]<-OWSA_UCI_inputsMatrixT["p_c_cycle_tx_tx2_init",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_comed_tx2",z] CostMatrix_Novel[i,2]<-OWSA_UCI_inputsMatrixT["p_c_cycle_tx_tx2_init",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_comed_tx2",z]+OWSA_UCI_inputsMatrixT["p_c_cycle_ae",z] }} #TRANSITION ARRAYS - 1= transitions from 1LTx NO AEs, etc #Note - 3D arrays are required rather than 2D matrices as different transition matrices are required for early cycles if titration is considered TransVec1_Comp<-c((1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L",z])*(OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L",z], OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L",z], 0, 0,0,0,0,0 ) TransVec2_Comp<-c((1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L",z])*(OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L",z], OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L",z], 0, 0,0,0,0,0 ) TransVec3_Comp<-c(0,0,0,0, (1-OWSA_UCI_inputsMatrixT["p_prob_discontafter1L",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_discontafter1L",z])*OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z], 0,0,0, OWSA_UCI_inputsMatrixT["p_prob_discontafter1L",z] ) TransVec4_Comp<-c(0,0,0,0, (1-OWSA_UCI_inputsMatrixT["p_prob_discontafter1L",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_discontafter1L",z])*OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z], 0,0,0, OWSA_UCI_inputsMatrixT["p_prob_discontafter1L",z] ) TransVec5_Comp<-c(0,0,0,0, (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_2L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_2L",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_2L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_2L",z])*(OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z]), OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_2L",z], OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_2L",z], 0,0 ) TransVec6_Comp<-c(0,0,0,0, (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_2L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_2L",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_2L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_2L",z])*(OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_2L",z]), OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_2L",z], OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_2L",z], 0,0 ) TransVec7_Comp<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-OWSA_UCI_inputsMatrixT["p_prob_discontafter2L",z]), ifelse(cont.PatPathway=="Discontinuation",1,OWSA_UCI_inputsMatrixT["p_prob_discontafter2L",z]) ) TransVec8_Comp<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-OWSA_UCI_inputsMatrixT["p_prob_discontafter2L",z]), ifelse(cont.PatPathway=="Discontinuation",1,OWSA_UCI_inputsMatrixT["p_prob_discontafter2L",z]) ) TransVec9_Comp<-c(0,0,0,0,0, 0,0,0,1,0) TransVec10_Comp<-c(0,0,0,0,0, 0,0,0,0,1) TransMat_Comp<-rbind(TransVec1_Comp,TransVec2_Comp,TransVec3_Comp,TransVec4_Comp,TransVec5_Comp, TransVec6_Comp,TransVec7_Comp,TransVec8_Comp,TransVec9_Comp,TransVec10_Comp) colnames(TransMat_Comp)<-c("NoAEs_1L","AEs_1L","WithdAEs_1L","WithdOther_1L","NoAEs_2L","AEs_2L","WithdAEs_2L","WithdOther_1L","3rdL","Discontinuation") rownames(TransMat_Comp)<-colnames(TransMat_Comp) rowSums(TransMat_Comp) #Novel Therapy arm TransVec1_Novel<-c((1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L",z])*(OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L",z], OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L",z], 0, 0,0,0,0,0 ) TransVec2_Novel<-c((1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L",z])*(OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L",z], OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L",z], 0, 0,0,0,0,0 ) TransVec3_Novel<-c(0,0,0,0, (1-OWSA_UCI_inputsMatrixT["p_prob_discontafter1L",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_discontafter1L",z])*OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z], 0,0,0, OWSA_UCI_inputsMatrixT["p_prob_discontafter1L",z] ) TransVec4_Novel<-c(0,0,0,0, (1-OWSA_UCI_inputsMatrixT["p_prob_discontafter1L",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_discontafter1L",z])*OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z], 0,0,0, OWSA_UCI_inputsMatrixT["p_prob_discontafter1L",z] ) TransVec5_Novel<-c(0,0,0,0, (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_2L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_2L",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_2L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_2L",z])*(OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z]), OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_2L",z], OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_2L",z], 0,0 ) TransVec6_Novel<-c(0,0,0,0, (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_2L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_2L",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_2L",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_2L",z])*(OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_2L",z]), OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_2L",z], OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_2L",z], 0,0 ) TransVec7_Novel<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-OWSA_UCI_inputsMatrixT["p_prob_discontafter2L",z]), ifelse(cont.PatPathway=="Discontinuation",1,OWSA_UCI_inputsMatrixT["p_prob_discontafter2L",z]) ) TransVec8_Novel<-c(0,0,0,0,0, 0,0,0, ifelse(cont.PatPathway=="Discontinuation",0,1-OWSA_UCI_inputsMatrixT["p_prob_discontafter2L",z]), ifelse(cont.PatPathway=="Discontinuation",1,OWSA_UCI_inputsMatrixT["p_prob_discontafter2L",z]) ) TransVec9_Novel<-c(0,0,0,0,0, 0,0,0,1,0) TransVec10_Novel<-c(0,0,0,0,0, 0,0,0,0,1) TransMat_Novel<-rbind(TransVec1_Novel,TransVec2_Novel,TransVec3_Novel,TransVec4_Novel,TransVec5_Novel, TransVec6_Novel,TransVec7_Novel,TransVec8_Novel,TransVec9_Novel,TransVec10_Novel) rownames(TransMat_Novel)<-rownames(TransMat_Comp) colnames(TransMat_Novel)<-colnames(TransMat_Comp) rowSums(TransMat_Novel) #### #Generate alternate transition matrix if titration scenario being considered #### if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { #Comp arm InitTransVec1_Comp<-c((1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z])*(OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z], OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z], 0, 0,0,0,0,0 ) InitTransVec2_Comp<-c((1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z])*(OWSA_UCI_inputsMatrixT["p_prob_AE_Tx1arm_1L",z]), OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx1arm_1L_init",z], OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx1arm_1L_init",z], 0, 0,0,0,0,0 ) InitTransMat_Comp<-rbind(InitTransVec1_Comp,InitTransVec2_Comp,TransVec3_Comp,TransVec4_Comp,TransVec5_Comp, TransVec6_Comp,TransVec7_Comp,TransVec8_Comp,TransVec9_Comp,TransVec10_Comp) rownames(InitTransMat_Comp)<-rownames(TransMat_Comp) colnames(InitTransMat_Comp)<-colnames(TransMat_Comp) rowSums(InitTransMat_Comp) #Novel arm InitTransVec1_Novel<-c((1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z])*(OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z], OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z], 0, 0,0,0,0,0 ) InitTransVec2_Novel<-c((1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z])*(1-OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), (1-OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z]-OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z])*(OWSA_UCI_inputsMatrixT["p_prob_AE_Tx2arm_1L",z]), OWSA_UCI_inputsMatrixT["p_prob_withdAE_Tx2arm_1L_init",z], OWSA_UCI_inputsMatrixT["p_prob_withdother_Tx2arm_1L_init",z], 0, 0,0,0,0,0 ) InitTransMat_Novel<-rbind(InitTransVec1_Novel,InitTransVec2_Novel,TransVec3_Novel,TransVec4_Novel,TransVec5_Novel, TransVec6_Novel,TransVec7_Novel,TransVec8_Novel,TransVec9_Novel,TransVec10_Novel) rownames(InitTransMat_Novel)<-rownames(TransMat_Novel) colnames(InitTransMat_Novel)<-colnames(TransMat_Novel) rowSums(InitTransMat_Novel) } ### #create arrays of matrices to allow time-varying transition probabilities TransArrayComp <- array(data=NA,dim=c(10,10,costANDtracematrices_nrows)) #dim=c(nrow,ncol,nmatrix) TransArrayNovel <- array(data=NA,dim=c(10,10,costANDtracematrices_nrows)) #dim=c(nrow,ncol,nmatrix) for (i in 1:costANDtracematrices_nrows) { TransArrayComp[,,i] <-TransMat_Comp TransArrayNovel[,,i]<-TransMat_Novel } #adapt array if titration is under consideration #### if (cont.titration=="no adjustment for first 4 weeks"){ print('no titration adjustment...') } else { for (i in 1:4) { TransArrayComp[,,i] <-InitTransMat_Comp TransArrayNovel[,,i]<-InitTransMat_Novel } } #check rowSums(TransArrayComp[,,4]) rowSums(TransArrayComp[,,8]) rowSums(TransArrayNovel[,,4]) rowSums(TransArrayNovel[,,8]) #Evaluate Model Results_Comp <- Pain_Markov(TransArrayComp,CostMatrix_Comp,UtilityVector_Comp) Results_Novel <- Pain_Markov(TransArrayNovel,CostMatrix_Novel,UtilityVector_Novel) #copy PSA results to matrix OWSA_resultsMatrix[z,"Costs_Comp_UCI"] <- Results_Comp$costs OWSA_resultsMatrix[z,"QALYs_Comp_UCI"] <- Results_Comp$qalys OWSA_resultsMatrix[z,"Costs_Novel_UCI"] <- Results_Novel$costs OWSA_resultsMatrix[z,"QALYs_Novel_UCI"] <- Results_Novel$qalys OWSA_resultsMatrix[z,"ICER_UCI"] <- (Results_Novel$costs-Results_Comp$costs)/(Results_Novel$qalys-Results_Comp$qalys) } #Calculate INB Difference #cont.WTPperQALY set under #CONTROLS section OWSA_resultsMatrix[,"INMB_Lower_Bound"]<-((cont.WTPperQALY*OWSA_resultsMatrix[,"QALYs_Novel_LCI"]-OWSA_resultsMatrix[,"Costs_Novel_LCI"])- (cont.WTPperQALY*OWSA_resultsMatrix[,"QALYs_Comp_LCI"]-OWSA_resultsMatrix[,"Costs_Comp_LCI"])) OWSA_resultsMatrix[,"INMB_Upper_Bound"]<-((cont.WTPperQALY*OWSA_resultsMatrix[,"QALYs_Novel_UCI"]-OWSA_resultsMatrix[,"Costs_Novel_UCI"])- (cont.WTPperQALY*OWSA_resultsMatrix[,"QALYs_Comp_UCI"]-OWSA_resultsMatrix[,"Costs_Comp_UCI"])) OWSA_resultsMatrix[,"INMB_Difference"]<-abs(OWSA_resultsMatrix[,"INMB_Upper_Bound"]-OWSA_resultsMatrix[,"INMB_Lower_Bound"]) OWSA_resultsMatrix_ORDERED<-OWSA_resultsMatrix[rev(order(as.data.frame(OWSA_resultsMatrix)$INMB_Difference)),] OWSA_resultsMatrix_ORDERED_top10<-as.data.frame(OWSA_resultsMatrix_ORDERED[1:10,]) #plot results # REQUIRED PACKAGE ggplot2 library(ggplot2) dataframe <- data.frame(Parameter=rep(rownames(OWSA_resultsMatrix_ORDERED_top10),2),Bound=c(rep("Lower",10),rep("Upper",10)), INMB=c(OWSA_resultsMatrix_ORDERED_top10$INMB_Lower_Bound,OWSA_resultsMatrix_ORDERED_top10$INMB_Upper_Bound), INMBdif=c(OWSA_resultsMatrix_ORDERED_top10$INMB_Difference,OWSA_resultsMatrix_ORDERED_top10$INMB_Difference)) ggplot(dataframe,aes(x=reorder(Parameter,INMBdif),y=INMB)) + geom_bar(stat="identity",position="identity") + coord_flip() + geom_hline(yintercept=OWSA_resultsMatrix["p_c_cycle_tx_tx1","INMB_Lower_Bound"], colour="black", lwd=2) }