<jupyter_start><jupyter_text>1. Career choices Source: https://github.com/pymc-devs/resources/blob/master/Rethinking_2/Chp_11.ipynb<jupyter_code># simulate career choices among 500 individuals
N = 500  # number of individuals
income = np.array([1, 2, 5])  # expected income of each career
score = 0.5 * income  # score for each career, based on income
# converts scores to probabilities:
p = softmax(score)

# now simulate choice
# outcome career holds event type values, not counts
career = np.random.multinomial(1, p, size=N)3
career = np.where(career == 1)[1]
career[:11], score, p
with pm.Model() as m1_1:
    a = pm.Normal("a", 0, 1, shape=2)
    b = pm.HalfNormal("b", 0.5)
    
    income_0 = pm.Data("income_0", value=1)
    income_1 = pm.Data("income_1", value=2)
    income_2 = pm.Data("income_2", value=5)
    
    s0 = a[0] + b * income_0
    s1 = a[1] + b * income_1
    s2 = 0.0 + b * income_2
    
    s = pm.math.stack([s0, s1, s2])
    p_ = pm.Deterministic("p", tt.nnet.softmax(s))
    
    career_obs = pm.Categorical('career', p=p_, observed=career)
    trace1_1 = pm.sample(tune=2000, target_accept=0.99, random_seed=RANDOM_SEED)
az.summary(trace1_1)
p_org = trace1_1["p"]<jupyter_output><empty_output><jupyter_text>ASSUMPTION: When income_1 is double<jupyter_code>with m1_1:
    pm.set_data({"income_1": 4})
    ppc = pm.sample_posterior_predictive(trace1_1, var_names=["a", "p"])
p_new = ppc["p"]
p_diff = p_new - p_org
az.summary({"p_diff": p_diff}, kind="stats")
type(trace1_1), type(ppc)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1510045366169799, 'fraction_numerical': 0.046662346079066754, 'mean_word_length': 4.342560553633218, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '428407', 'license': 'Apache-2.0', 'n_tokens_mistral': 655, 'n_tokens_neox': 622, 'n_words': 134, 'path': '_00_rethink_stats_counterfactuals.ipynb', 'repo_name': 'danhphan/bayesian_inferences', 'size': '1543'}