<jupyter_start><jupyter_text>Missing data Noticed in the above that `hci` and `hospital_beds` had missing data, which could be causing the issues with model initialization. My assumption is that we are seeing this now because countries which weren't reporting COVID-19 before are now, and those countries lack World Bank info on those two covariates.<jupyter_code>full_covariates = [x for x in df.columns if 'normalized' in x]
covariates = list(set(full_covariates) - set(['hospital_beds_normalized','hci_normalized']))
def initialize_model(df, covariates):

    NUM_COVARIATES = len(covariates)
    
    n = len(df)

    covid_mortality_model = pm.Model()

    with covid_mortality_model:

        # Priors:
        mu_0 = pm.Beta('mu_0', alpha=0.3, beta=10)
        sig_0 = pm.Uniform('sig_0', lower=0.0, upper=mu_0 * (1 - mu_0))
        beta = pm.Normal('beta', mu=0, sigma=5, shape=NUM_COVARIATES)
        sigma = pm.HalfNormal('sigma', sigma=5)

        # Model mu from country-wise covariates:
        # Apply logit transformation so logistic regression performed
        mu_0_logit = np.log(mu_0 / (1 - mu_0))
        mu_est = mu_0_logit + pm.math.dot(df[covariates].values, beta)
#         mu_est = mu_0_logit + \
#             beta[0] * df['days_since_first_case_normalized'].values + \
#             beta[1] * df['cpi_score_2019_normalized'].values + \
#             beta[2] * df['healthcare_oop_expenditure_normalized'].values + \
#             beta[3] * df['hospital_beds_normalized'].values + \
#             beta[4] * df['hci_normalized'].values + \
#             beta[3] * df['population_perc_over65_normalized'].values + \
#             beta[4] * df['population_perc_rural_normalized'].values + \
#             beta[5] * df['population_perc_diabetic'].values 
            
        mu_model_logit = pm.Normal('mu_model_logit',
                                   mu=mu_est,
                                   sigma=sigma,
                                   shape=n)
        # Transform back to probability space:
        mu_model = np.exp(mu_model_logit) / (np.exp(mu_model_logit) + 1)

        # tau_i, mortality rate for each country
        # Parametrize with (mu, sigma)
        # instead of (alpha, beta) to ease interpretability.
        tau = pm.Beta('tau', mu=mu_model, sigma=sig_0, shape=n)
        # tau = pm.Beta('tau', mu=mu_0, sigma=sig_0, shape=n)

        # Binomial likelihood:
        d_obs = pm.Binomial('d_obs',
                            n=df['cases'].values,
                            p=tau,
                            observed=df['deaths'].values)

    return covid_mortality_model
model = initialize_model(df, covariates)
## In order to run this, you will need to brew install graphviz on your machine (for Mac users)
pm.model_to_graphviz(model)
trace = train_model.train_model(model)
pm.traceplot(trace)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11130434782608696, 'fraction_numerical': 0.014608695652173913, 'mean_word_length': 2.5201958384332923, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '420000', 'license': 'MIT', 'n_tokens_mistral': 961, 'n_tokens_neox': 906, 'n_words': 206, 'path': 'notebooks/1.0_je_initial-model.ipynb', 'repo_name': 'ParivedaChiFinesse/covid19-mortality-rate', 'size': '2875'}