<jupyter_start><jupyter_text>bayespropestimation usage guideThe BayesProportionsEstimation class and its methods use a series of defaults which means that user need not provide any information other than the data for samples A and B.  This notebook covers usage where a user may want to use non-default parameters. Sections Class BayesProportionsEstimation- Alternative beta priors- Define the number of simulations- Set the random seed Method quantile_summary- Include the mean estimate or not- Set quantiles to report- Name the parameters Method hdi_summary- Include mean estimate or note- Set a non-default HDI interval- Name the parameters Method infer_delta_probability- Change the direction of the hypothesis- Add an additional constant to the hypothesis e.g. P(A > (B + constant))- Change the default print_inference- Name the parameters Method infer_delta_bayes_factor- Change the direction of the hypothesis- Add an additional constant to the hypothesis e.g. P(A > (B + constant))- Change the default print_inference- Name the parameters Method posterior_plot- Define the estimation method- Define the vertical line on the delta plot- Use a non-default colour on the plots- Use non-default intervals for the plot- Name the parameters- Explicitly define the fig size<jupyter_code>from bayespropestimation.bayespropestimation import BayesProportionsEstimation
a = [20, 40]
b = [30, 50]<jupyter_output><empty_output><jupyter_text>Class BayesProportionsEstimation- Alternative beta priors<jupyter_code>ExampleBayes = BayesProportionsEstimation(a, b, prior_alpha=0.1, prior_beta=0.9)
print(ExampleBayes.prior_alpha)
print(ExampleBayes.prior_beta)<jupyter_output>0.1
0.9<jupyter_text>- Define the number of simulations<jupyter_code>ExampleBayes = BayesProportionsEstimation(a, b, n=100)
draws = ExampleBayes.get_posteriors()
for i in draws:
    print(len(i))<jupyter_output>100
100
100<jupyter_text>- Set the random seed<jupyter_code>ExampleBayes = BayesProportionsEstimation(a, b, seed=1000)
print(ExampleBayes.seed)<jupyter_output>1000<jupyter_text>Method quantile_summary- Include the mean estimate or not<jupyter_code>ExampleBayes = BayesProportionsEstimation(a, b)
ExampleBayes.quantile_summary(mean=False)<jupyter_output><empty_output><jupyter_text>- Set quantiles to report<jupyter_code>ExampleBayes.quantile_summary(quantiles=[0.01, 0.025, 0.05, 0.95, 0.975, 0.99])<jupyter_output><empty_output><jupyter_text>- Name the parameters<jupyter_code>ExampleBayes.quantile_summary(names = ['Mean of A', 'Mean of B', 'Mean of B - mean of A'])<jupyter_output><empty_output><jupyter_text>Method hdi_summary- Include the mean estimate or not<jupyter_code>ExampleBayes.hdi_summary(mean=False)<jupyter_output><empty_output><jupyter_text>- Set a non-default HDI interval<jupyter_code>ExampleBayes.hdi_summary(interval=0.99)<jupyter_output><empty_output><jupyter_text>- Name the parameters<jupyter_code>ExampleBayes.hdi_summary(names = ['Mean of A', 'Mean of B', 'Mean of B - mean of A'])<jupyter_output><empty_output><jupyter_text>Method infer_delta_probability- Change the direction of the hypothesis<jupyter_code>print(ExampleBayes.infer_delta_probability(direction = 'less than'))<jupyter_output>The probability that theta_b is less than theta_a is 17.05%. Therefore theta_b is probably not less than theta_a.
(0.1705, 'probably not')<jupyter_text>- Add an additional constant to the hypothesis e.g. P(A > (B + constant))<jupyter_code>print(ExampleBayes.infer_delta_probability(value = 0.05))<jupyter_output>The probability that theta_b is greater than theta_a by more than 0.05 is 82.95%. Therefore theta_b is probably greater than theta_a by more than 0.05.
(0.8295, 'probably')<jupyter_text>- Change the default print_inference<jupyter_code>print(ExampleBayes.infer_delta_probability(print_inference = False))<jupyter_output>(0.8295, 'probably')<jupyter_text>- Name the parameters<jupyter_code>print(ExampleBayes.infer_delta_probability(names = ['Mean of A', 'Mean of B', 'Mean of B - mean of A']))<jupyter_output>The probability that Mean of B is greater than Mean of A is 82.95%. Therefore Mean of B is probably greater than Mean of A.
(0.8295, 'probably')<jupyter_text>Method infer_delta_bayes_factor- Change the direction of the hypothesis<jupyter_code>print(ExampleBayes.infer_delta_bayes_factor(direction = 'less than'))<jupyter_output>The calculated bayes factor for the hypothesis that theta_b is less than theta_a versus the hypothesis that theta_a is less than theta_a is 0.20555. Therefore the strength of evidence for this hypothesis is negative.
(0.20554550934297772, 'negative')<jupyter_text>- Add an additional constant to the hypothesis e.g. P(A > (B + constant))<jupyter_code>print(ExampleBayes.infer_delta_bayes_factor(value = 0.05))<jupyter_output>The calculated bayes factor for the hypothesis that theta_b is greater than theta_a by more than 0.05 versus the hypothesis that theta_a is greater than theta_a by more than 0.05 is 2.1407. Therefore the strength of evidence for this hypothesis is barely worth mentioning.
(2.1407035175879394, 'barely worth mentioning')<jupyter_text>- Change the default print_inference<jupyter_code>print(ExampleBayes.infer_delta_bayes_factor(print_inference = False))<jupyter_output>(4.865102639296188, 'substantial')<jupyter_text>- Name the parameters<jupyter_code>print(ExampleBayes.infer_delta_bayes_factor(names = ['Mean of A', 'Mean of B', 'Mean of B - mean of A']))<jupyter_output>The calculated bayes factor for the hypothesis that Mean of B is greater than Mean of A versus the hypothesis that Mean of A is greater than Mean of A is 4.8651. Therefore the strength of evidence for this hypothesis is substantial.
(4.865102639296188, 'substantial')<jupyter_text>Method posterior_plotNote plots aren't displayed in order to minimise file size.- Define the estimation method<jupyter_code>p = ExampleBayes.posterior_plot(method = 'quantile')<jupyter_output><empty_output><jupyter_text>- Define the vertical line on the delta plot<jupyter_code>p = ExampleBayes.posterior_plot(delta_line = 0.05)<jupyter_output><empty_output><jupyter_text>- Use a non-default colour on the plots<jupyter_code>p = ExampleBayes.posterior_plot(col = 'green')<jupyter_output><empty_output><jupyter_text>- Use non-default intervals for the plot.  If using `method` = `'hdi'`:<jupyter_code>p = ExampleBayes.posterior_plot(bounds = 0.99)<jupyter_output><empty_output><jupyter_text>- Use non-default intervals for the plot.  If using `method` = `'quantile'`:<jupyter_code>p = ExampleBayes.posterior_plot(method = 'quantile', bounds = [0.005, 0.995])<jupyter_output><empty_output><jupyter_text>- Name the parameters<jupyter_code>p = ExampleBayes.posterior_plot(names = ['Mean of A', 'Mean of B', 'Mean of B - mean of A'])<jupyter_output><empty_output><jupyter_text>- Explicitly define the fig size<jupyter_code>p = ExampleBayes.posterior_plot(fig_size = (750, 300))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08908460872076235, 'fraction_numerical': 0.030609298296274907, 'mean_word_length': 7.159010600706714, 'pattern_counts': {'":': 0, '<': 90, '<?xml version=': 0, '>': 94, 'https://': 0, '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': '25', 'dir': 'jupyter-structured-clean-dedup', 'id': '70299', 'license': 'MIT', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2199, 'n_words': 649, 'path': 'docs/bayespropestimation_usage.ipynb', 'repo_name': 'oli-chipperfield/bayespropestimation', 'size': '6926'}