def test_fitting_beta_binomial(): print("\nTesting Beta-Binomial with n=100, a=2, b=3, loc=1, scale=2:") dist = RVGs.BetaBinomial(n=20, a=2, b=3, loc=1) print(' percentile interval: ', dist.get_percentile_interval(alpha=0.05)) data = np.array(get_samples(dist, np.random)) # method of moment dict_mm_results = RVGs.BetaBinomial.fit_mm(mean=np.mean(data), st_dev=np.std(data), n=20, fixed_location=1) # maximum likelihood dict_ml_results = RVGs.BetaBinomial.fit_ml(data=data, fixed_location=1) print(" Fit:") print(" MM:", dict_mm_results) print(" ML:", dict_ml_results) # plot the fitted distributions Plot.plot_beta_binomial_fit(data=data, fit_results=dict_mm_results, title='Method of Moment') Plot.plot_beta_binomial_fit(data=data, fit_results=dict_ml_results, title='Maximum Likelihood')
print('Fitting a Poisson distribution:', fit_results) # plot the fitted Poisson distribution Plot.plot_poisson_fit(data=cols[0], fit_results=fit_results, x_label='Weekly number of drinks', x_range=(0, 40), bin_width=1) # fit a gamma-Poisson distribution fit_results = RVGs.GammaPoisson.fit_ml(data=cols[0]) print('Fitting a gamma-Poisson distribution:', fit_results) # plot the fitted gamma-Poisson distribution Plot.plot_gamma_poisson_fit(data=cols[0], fit_results=fit_results, x_label='Weekly number of drinks', x_range=(0, 40), bin_width=1) # fit a beta-binomial distribution fit_results = RVGs.BetaBinomial.fit_ml(data=cols[0]) print('Fitting a beta-binomial distribution:', fit_results) # plot the fitted beta-binomial distribution Plot.plot_beta_binomial_fit(data=cols[0], fit_results=fit_results, x_label='Weekly number of drinks', x_range=(0, 40), bin_width=1)