<jupyter_start><jupyter_text>Setting up my prior which are bombings/explosions in the South Asia region from 1970 up to and including 2000. I will use Pakistan and Afghanistan and bombings/explosions from 2001 till 2015 to measure the amount of difference of these types of attacks.<jupyter_code>df_prior = dfwhole[(dfwhole.attacktype1 == 3) & (dfwhole.region == 6) & (dfwhole.iyear <= 2000)].
groupby(['iyear', 'country_txt']).attacktype1.count().values
## Confirming it worked.
df_prior
df_prior_mean = df_prior.mean()
print df_prior_mean
df_prior.groupby('country_txt').attacktype1.count()
dfwhole.groupby(['iyear', 'country_txt']).attacktype1.count()<jupyter_output><empty_output><jupyter_text>Setting up prior std on my df_prior<jupyter_code>df_prior_std = df_prior.std()
print df_prior_std
mean_prior_mean = df_prior_mean
mean_prior_std = df_prior_std<jupyter_output><empty_output><jupyter_text>Setting up Afghanistan to be one of my populations from 2001 through 2015.<jupyter_code>afp = dfwhole[(dfwhole.attacktype1 == 3) & (dfwhole.country == 4) & (dfwhole.iyear > 2000)].
groupby(['iyear']).attacktype1.count().values
afp<jupyter_output><empty_output><jupyter_text>Getting mean for Afghanistan.<jupyter_code>afp_mean = afp.mean()
print afp_mean<jupyter_output>331.733333333<jupyter_text>Settinp up the standard deviation for Afghanistan.<jupyter_code>afp_std = afp.std()
print afp_std<jupyter_output>336.369334049<jupyter_text>Setting up Pakistan to be my second population from 2001 through 2015.<jupyter_code>pakp = dfwhole[(dfwhole.attacktype1 == 3) & (dfwhole.country == 153) & (dfwhole.iyear > 2000)].
groupby(['iyear']).attacktype1.count().values<jupyter_output><empty_output><jupyter_text>Getting mean for Pakistan.<jupyter_code>pakp_mean = pakp.mean()
print pakp_mean<jupyter_output>421.266666667<jupyter_text>Setting up the standard deviation for Pakistan.<jupyter_code>## setting up std for Pakistan
pakp_std = pakp.std()
print pakp_std
with pm.Model() as model:
    
    groupPk_mean = pm.Normal('Bombings_Pak_mean', mean_prior_mean, sd=mean_prior_std)
    groupAfg_mean = pm.Normal('Bombings_Afg_mean', mean_prior_mean, sd=mean_prior_std)
std_prior_lower = 0.01
std_prior_upper = 100.0

with model:
    
    groupPak_std = pm.Uniform('Bombings_Pak_std', lower=std_prior_lower, upper=std_prior_upper)
    groupAfg_std = pm.Uniform('Bombings_Afg_std', lower=std_prior_lower, upper=std_prior_upper)
with model:

    groupPak = pm.Normal('Bombings_Pak', mu=groupPk_mean, sd=groupPak_std, observed=pakp)
    groupAfg = pm.Normal('Bombings_Afg', mu=groupAfg_mean, sd=groupAfg_std, observed=afp)

with model:

    diff_of_means = pm.Deterministic('difference of means',groupPk_mean - groupAfg_mean)
    diff_of_stds = pm.Deterministic('difference of stds',groupPak_std - groupAfg_std)
    effect_size = pm.Deterministic('effect size',
                                   diff_of_means / np.sqrt((groupPak_std**2 + groupAfg_std**2) / 2))
with model:
    trace = pm.sample(25000, njobs=4)
pm.plot_posterior(trace[3000:],
                  varnames=['Bombings_Pak_mean', 'Bombings_Afg_mean', 'Bombings_Pak_std', 'Bombings_Afg_std'],
                  color='#87ceeb')
pm.plot_posterior(trace[3000:],
                  varnames=['difference of means', 'difference of stds', 'effect size'],
                  ref_val=0,
                  color='#87ceeb')
pm.summary(trace[3000:],
           varnames=['difference of means', 'difference of stds', 'effect size'])
afgtd = dfwhole[dfwhole.country_txt=='Afghanistan']<jupyter_output><empty_output><jupyter_text>Attacks in Afghanistan by Year<jupyter_code>plt.hist(afgtd['iyear'])
pkgtd = dfwhole[dfwhole.country_txt=='Pakistan']
pkgtd.tail(2)<jupyter_output><empty_output><jupyter_text>Looking at attack types in Pakistan<jupyter_code>pkgtd['attacktype1_txt'].value_counts().head(5)<jupyter_output><empty_output><jupyter_text>Attacks in Pakistan by Year<jupyter_code>plt.hist(pkgtd['iyear'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11946680080482898, 'fraction_numerical': 0.03319919517102616, 'mean_word_length': 6.038938053097345, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '69643', 'license': 'MIT', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1407, 'n_words': 254, 'path': 'Global Terrorism Bayesian Analysis/Global Terrorism Bayesian Analysis.ipynb', 'repo_name': 'NKhan121/Portfolio', 'size': '3976'}