Closed mmaughan0 closed 5 months ago
Ok, it's a frequent error: all your variables must be defined within the function define_parameters
, and not in the global environment
ok - I ran into that issue before with the PSA so I understand what you mean - but in that DSA both of those variables work individually. Is it really the same issue?
yes I modified your code locally, and it's working
ok - do you have any insight as to why it would run one at a time?
Ok now I am confusing myself a little bit. So we have both PSA and DSA, and you are saying that both need to be within a modify parameter statement, however
PSA Corrections and comment: 1) I corrected my issue with the PSA by taking a variable OUT of the par_mod <- modify statement, specifically par_mod <- modify( par_mod,
cost_tx_start = Avg_2024_SoC_Pt_Cost + Tx_cost + CCL_Cost_pp + Training_cost_pp, cost_tx_end = Avg_2024_SoC_Pt_Cost, n_days = 11, cost_tx_cycle_REGN_EB3 = ifelse( state_time < n_days-9.9, ## we first defined in n days in the probability matrix to cut off the KM curve at 10 days. For that reason we have to use it as a reference point cost_tx_start, cost_tx_end) ) -
The PSA would not work if Tx_Cost was modified in the statement above. It did work when I added Tx_Cost to the statement below, which as you will notice is NOT in a parmod statement state_sick_REGN_Eb3 <- define_state( cost_total = Tx_cost + CCL_Cost_pp + Training_cost_pp + Avg_2024_SoC_Pt_Cost, qaly = 0)
DSA Corrections and Comment: I have Tx_Cost and SoC Cost within a par_mod statement and not within a par_mod statement, however it only runs when I have it in the statement below one at a time. The error I am getting does not seem to have anything to do with how I define the parameter.
def_dsa <- define_dsa( Tx_cost, 0, 10000)
Thanks!
The issue is with these variables: Per_Survivor_Cost = 830 Per_Dead_Cost = 321 Avg_2014_Pt_Cost = (Per_Survivor_Cost/11.2 + Per_Dead_Cost/4.2)/2
CPI_Multiplier_2014_2024 = 1.32
Avg_2024_SoC_Pt_Cost = CPI_Multiplier_2014_2024 * Avg_2014_Pt_Cost
Per_Survivor_Cost_low = 446 Per_Dead_Cost_low = 185 Avg_2014_Pt_Cost_low = (Per_Survivor_Cost_low/11.2 + Per_Dead_Cost_low/4.2)/2
Avg_2024_SoC_Pt_Cost_low = CPI_Multiplier_2014_2024 * Avg_2014_Pt_Cost_low
CI_Per_Surv_cost = 862-800 CI_Per_Dead_cost = 351-292 CI_Per_Surv_cost_low = 466-428 CI_Per_Dead_cost_low = 202-169
BF_RN_ann_wage = 3702 BF_CN_ann_wage = 2823 Zambia_RN_ann_wage = 6476 Nigeria_RN_ann_wage = 8709 Ghana_RN_ann_wage = 7680
BF_ratio_RN_CN = BF_RN_ann_wage/BF_CN_ann_wage
Zambia_CN_ann_wage = Zambia_RN_ann_wage/BF_ratio_RN_CN Nigeria_CN_ann_wage = Nigeria_RN_ann_wage/BF_ratio_RN_CN Ghana_CN_ann_wage = Ghana_RN_ann_wage/BF_ratio_RN_CN
RN_pct_DC = 78/102
Ghana_avg_wage = RN_pct_DCGhana_RN_ann_wage + (1-RN_pct_DC)Ghana_CN_ann_wage Zambia_avg_wage = RN_pct_DCZambia_RN_ann_wage + (1-RN_pct_DC)Zambia_CN_ann_wage Nigeria_avg_wage = RN_pct_DCNigeria_RN_ann_wage + (1-RN_pct_DC)Nigeria_CN_ann_wage BF_avg_wage = RN_pct_DCBF_RN_ann_wage + (1-RN_pct_DC)BF_CN_ann_wage
Regional_avg_wage = mean(Ghana_avg_wage, Zambia_avg_wage, Nigeria_avg_wage, BF_avg_wage)
working_days_per_year = 250
Regional_daily_wage = Regional_avg_wage/working_days_per_year
Total_ETU_Patients = 600 Confirmed_cases = prevalence* Total_ETU_Patients
Training_cost_pp = Regional_daily_wage*102/Confirmed_cases
LY_point_est = 43.2
Mild_Prev = 14/191 Mild_DW = .004
Moderate_Prev = 2/191 Moderate_DW = .033
Blindness_Prev = 10/191 Blindness_DW = .195
DW_Vision_Impair = Mild_PrevMild_DW + Moderate_PrevModerate_DW + Blindness_Prev*Blindness_DW
Tx_cost = 500
TLC_Cost= 6890 Days_Operation = 120 Resupply_Cost_ETU = 92
Amortization_Rate = Days_Operation/(3655) Refrigeration_Cost = TLC_Cost Amortization_Rate CCL_cost_ETU = Resupply_Cost_ETU + Refrigeration_Cost
CCL_Cost_pp = CCL_cost_ETU/Confirmed_cases
which are defined outside define_parameters
ok - I am going to dig into this and put all of these variables into a par_mod statement - will report back if I cannot get it to work.
Would it be fair to say that the fact that only one variable would work at a time in the DSA is just a downstream effect of not definining the variables within a parameter? If I fix the problem it shouldnt matter, but I am just curious at this point. It seems an interesting side effect.
It's not a side effect, really. That is the way heemod is coded: relying heavily on non standard evaluation and capturing the calling environment.
You can consult reprex below - issue is that DSA will not run with multiple variables. I have tried many variables individually and the code runs just fine but the second I add another one I get this error:
> Error in [.data.frame(x$complete_parameters, 1, dsa$variables): undefined columns selected
I consulted Flipovic-Perucci, Zarca and Isabelle Durand-Zaleski's Paper "Markov Models for Health Ecomonc Evaluations: THe R Package heemod" for correct syntax.
Note that many of these values are dummies that I threw in just to get the reprex to run without errors (excluding the final one of course)
Created on 2024-03-06 with reprex v2.1.0