file_path = 'Combination.xlsx'
df = pd.read_excel(file_path, sheet_name = 0, header=None)
Combination_cpt = df.to_numpy().T
Combination_cpt.shape
bins = np.array([0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120])
num_states_plf = len(bins) - 1
num_states_slf = len(bins) - 1
lookup_table_COM = {}
for i, j in itertools.product(range(num_states_plf), range(num_states_slf)):
idx = i * num_states_slf + j
lookup_table_COM[(i, j)] = Combination_cpt[idx]
with pm.Model() as model:
PoA = pm.Triangular('PoA', lower=0, c=0.3, upper=1)
CF = pm.Lognormal('CF', mu=4.5, sigma=0.2)
TEF = pm.Deterministic('TEF', CF * PoA)
vulnerability = pm.Normal('vulnerability', mu=1, sigma=0.5)
MPLEF = pm.Deterministic('MPLEF', TEF * vulnerability)
CoSL = pm.Normal('CoSL', mu=0.7, sigma=0.2)
PLF = pm.Poisson('PLF', mu=MPLEF)
SLF = pm.Binomial('SLF', n=PLF, p=CoSL)
plf_bin = np.digitize(PLF.eval(), bins) - 1
slf_bin = np.digitize(SLF.eval(), bins) - 1
current_state = (plf_bin, slf_bin)
p_combination = lookup_table_COM.get(current_state)
combination = pm.Categorical('combination', p=p_combination)
trace = pm.sample(1000, tune=1000)
Combination.csv (37.2 KB)
I tried the OrderedLogistic / Probit distributions as you suggested, but it doesn’t seem to achieve the effect I want. I tried another method, but there are issues with sampling in the “combination” node. Could it be a problem with the node definition?

