hyunjimoon / VaccineMisinf

2 stars 0 forks source link

baseline parameter? #16

Open hyunjimoon opened 1 year ago

hyunjimoon commented 1 year ago
 for VaxInc_val in hparam_vi: #[0]:#, 1, 1.01]:
        if use_vengine:
            param_new_val_list = []
            for item in log_file:
                try:
                    param_base = vst_text.get_value(f'{posterior_out}', item)
                except TypeError:  # if we can't find param in optimization output, pull it out of model directly, should be done form mdl but is currently from .tab generated from vensim
                    param_base = vst_text.get_value(f'{datahp_mdl}', item)
                    # df = pd.read_csv(f"{test_file}", sep="\t",
                    #                      index_col=0)  # raw values (all params outside .out, manually generated from .mdl/ can read from .mdl)
                    # param_base = df.loc[item][0]
                param_new_val_list.append(param_base * percent_change)  # TODO: make this function with list param for rgn
            setval_lst = [("VaxInc", VaxInc_val)] + [(param_name, param_new_val) for param_name, param_new_val in zip(param_name_list, param_new_val_list)]
hyunjimoon commented 1 year ago

what should the coords for f1_pcst, f2_pcst be and could we .sum(dim="space) for f1_vvpp or should it happen in x_csth level (to x_cth)? but then the above code for changing parameters and VaxInc, creating 23*3 csv files is confusing. why doesn't GDP cost for time t for state s for vaxinc=0 (x_csth or `x_cth) doesn't have parameter slot?

'f1_vvpp': {"dims": ("f1_vvpp"), "data": f1_vvpp}, #normalized vaccine value (by population)
'f2_sens': {"dims": ("f2_sens"), "data": f2_sens}, #value
'param_scal': {"dims": ("param_scal"), "data": param_lst},
'costcomp_tvec': {"dims": ("costcomp_tvec"), "data": costcomp_tvec},
'noncost_tvec': {"dims": ("noncost_tvec"), "data": noncost_tvec},
'space': {"dims": ("space"), "data": state_names},
'time': {"dims": ("time"), "data": time},
'hparam_vax_amt': {"dims": ("hparam_vax_amt"), "data": [va for va in hparam_vax_amt]},
'hparam_vax_time': {"dims": ("hparam_vax_time"), "data": [str(vt) for vt in hparam_vax_time]}
},

"data_vars": { # 5+3 three vdot_ coordinate is only needed for data variables with 'p' coordinate
"x_csth": {"dims": ("costcomp_tvec", "space", "time", "hparam_vax_amt"), "data": np.zeros(shape=(len(costcomp_tvec), len(state_names), len(time), len(hparam_vax_amt)))},
"x_nsth": {"dims": ("noncost_tvec", "space", "time", "hparam_vax_amt"), "data": np.zeros(shape=(len(noncost_tvec), len(state_names), len(time), len(hparam_vax_amt)))},

"f1_pcst": {"dims": ("f1_vvpp", "param_scal", "costcomp_tvec", "space", "time",), "data": np.zeros(shape=(len(f1_vvpp), len(param_lst), len(costcomp_tvec), len(state_names), len(time)))}, #marginal vaccine value per person
"f2_pcst": {"dims": ("f2_sens", "param_scal", "costcomp_tvec", "space", "time",), "data": np.zeros(shape=(len(f2_sens), len(param_lst), len(costcomp_tvec), len(state_names), len(time)))}, #marginal vaccine value per person w.r.t. parameter

image

param_name = "baseline"
VaxInc_val = 1.01
param_vv_raw = pd.read_csv(f"CSV/Covidparam_{param_name}_{VaxInc_val}.csv", index_col=0).T
vi_r2s = {1.01: '1.01', 1: '1', 0:  '0',}

def calc_vvdiff_by_pop(raw_values: pd.DataFrame) -> pd.DataFrame:
    values_normalized_by_pop = pd.DataFrame()
    columns_to_adjust = [
        "Cost of Deaths Cumulative",
        "Cost of GDP Cumulative",
        "Cost of Hospitalizations Cumulative"
    ]
    population_column = "Vaccine Taking Population"
    locations = [f"[{state}]" for state in state_names]
    locations += [" All"]
    for location in locations:
        for column in columns_to_adjust:
            values_normalized_by_pop[column + location] = raw_values[column + location] / raw_values[
                population_column + location]
    return values_normalized_by_pop

param_vv = calc_vvdiff_by_pop(param_vv_raw)

vv["x_cth"].loc[{"costcomp_tvec": "death", "hparam_vax_amt": vi_r2s[VaxInc_val],}] = param_vv_raw["Cost of Deaths Cumulative All"].values.flatten()
vv["x_cth"].loc[{ "param_scal": param_name, "costcomp_tvec": "gdp"}] = param_vv_raw["Cost of GDP Cumulative All"].values.flatten()
vv["x_csth"].loc[{"hparam_vax_amt": vi_r2s[VaxInc_val], "param_scal": param_name, "costcomp_tvec": "hospitalization"}] = param_vv_raw["Cost of Hospitalizations Cumulative All"].values.flatten()

vv["x_nsth"].loc[{"hparam_vax_amt": vi_r2s[VaxInc_val], "param_scal": param_name,"noncost_tvec": "population"}] = param_vv_raw["Vaccine Taking Population All"].values.flatten()

for state in state_names:
    vv["f_pcst"].loc[{"f1_vvpp": vi_r2s[VaxInc_val], "param_scal": param_name,"costcomp_tvec": "death", "space": state}] = param_vv[f"Cost of Deaths Cumulative[{state}]"].values.flatten()
    vv["f_pcst"].loc[{"f1_vvpp": vi_r2s[VaxInc_val], "param_scal": param_name,"costcomp_tvec": "gdp", "space": state}] = param_vv[f"Cost of GDP Cumulative[{state}]"].values.flatten()
    vv["f_pcst"].loc[{"f1_vvpp": vi_r2s[VaxInc_val], "param_scal": param_name,"costcomp_tvec": "hospitalization", "space": state}] = param_vv[f"Cost of Hospitalizations Cumulative[{state}]"].values.flatten()

    vv["f_pnst"].loc[{"f1_vvpp": vi_r2s[VaxInc_val], "param_scal": param_name, "noncost_tvec": "population", "space": state}] = param_vv_raw[f"Vaccine Taking Population[{state}]"].values.flatten()

vv["f1_pcst"].loc[{"f1_vvpp": "avv"}] = (vv["f_pcst"].loc[{"f1_vvpp": "vi_base"}] - vv["f_pcst"].loc[{"f1_vvpp": "vi_zero"}]) / (vv["f_pnst"].loc[{"f1_vvpp": "vi_base", "noncost_tvec": "population" }] - vv["f_pnst"].loc[{"f1_vvpp": "vi_zero","noncost_tvec": "population"}])
vv["f1_pcst"].loc[{"f1_vvpp": "mvv"}] = (vv["f_pcst"].loc[{"f1_vvpp": "vi_1dot1"}] - vv["f_pcst"].loc[{"f1_vvpp": "vi_base"}]) / (vv["f_pnst"].loc[{"f1_vvpp": "vi_1dot1","noncost_tvec": "population"}] - vv["f_pnst"].loc[{"f1_vvpp": "vi_base","noncost_tvec": "population"}])

# does "baseline" be regarded as one parameter do we need separate data_variable for "f_c"? (on top of "f_pc") vv["f_pc"].loc[{"f1_vvpp": vi_r2s[VaxInc_val], "param_scal": param_name, "costcomp_tvec": "death"}]
vv["f_pct"].loc[{"f1_vvpp": vi_r2s[VaxInc_val], "param_scal": param_name, "costcomp_tvec": "death"}] = param_vv["Cost of Deaths Cumulative All"].values.flatten()
vv["f_pct"].loc[{"f1_vvpp": vi_r2s[VaxInc_val], "param_scal": param_name, "costcomp_tvec": "gdp"}] = param_vv["Cost of GDP Cumulative All"].values.flatten()
vv["f_pct"].loc[{"f1_vvpp": vi_r2s[VaxInc_val], "param_scal": param_name, "costcomp_tvec": "hospitalization"}] = param_vv["Cost of Hospitalizations Cumulative All"].values.flatten()

vv["f_pnt"].loc[{"f1_vvpp": vi_r2s[VaxInc_val], "param_scal": param_name,"noncost_tvec": "population"}] = param_vv_raw["Vaccine Taking Population All"].values.flatten()

vv['f2_pct'] =  vv['f2_pcst'].sum(dim="space") #tf6
vv['f2_pst'] =  vv['f2_pcst'].sum(dim="costcomp_tvec") #tf6
vv['f2_pt'] =  vv['f2_pct'].sum(dim="costcomp_tvec") #tf7
vv['f2_ch'] = vv['f2_pct'].loc[{'param_scal':"baseline", "time":vv["time"][-1]}] #tf8

# vv["f_c"].loc[{"f1_vvpp": "mvv", "costcomp_tvec": "death"}] = param_vv["Cost of Deaths Cumulative All"].values.flatten()
vv["f_pct"].loc[{"f1_vvpp": "avv", "param_scal": param_name, "costcomp_tvec": "gdp"}] = param_vv["Cost of GDP Cumulative All"].values.flatten()
vv["f_pct"].loc[{"f1_vvpp": vi_r2s[VaxInc_val], "param_scal": param_name, "costcomp_tvec": "hospitalization"}] = param_vv["Cost of Hospitalizations Cumulative All"].values.flatten()
vv["f_pct"].loc[{"costcomp_tvec": "total" }]= vv["f_pct"].sum(dim = "costcomp_tvec")
hyunjimoon commented 1 year ago

image image

q2. btw the two calc, delta over delta is what we should be doing, right?

hyunjimoon commented 1 year ago
image