The Beta distribution (student stuff)
4 Jun, 2024 at 14:49 | Posted in Statistics & Econometrics | Leave a comment.
Added: And here’s a little Python code yours truly has put together so you can play around and plot Beta distributions:
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import beta
# Given data
total_flips = 100
observed_heads = 60
observed_tails = 40 # Adjusted to match 100 flips
# Calculating the probability of heads and tails
prob_heads = observed_heads / total_flips
prob_tails = observed_tails / total_flips
# Simulating 100 coin flips
flips = np.random.choice(['H', 'T'], size=total_flips, p=[prob_heads, prob_tails])
# Counting the number of heads and tails
count_heads = np.sum(flips == 'H')
count_tails = np.sum(flips == 'T')
# Parameters for the Beta distribution
alpha = count_heads + 1
beta_param = count_tails + 1
# Plotting the Beta distribution
x = np.linspace(0, 1, 1000)
y = beta.pdf(x, alpha, beta_param)
plt.plot(x, y, label=f'Beta({alpha},{beta_param})', color='purple')
plt.xlabel('Probability of Heads')
plt.ylabel('Density')
plt.title('Beta Distribution of Coin Flips')
plt.legend()
plt.show()
# Print the counts as well
print(f'Number of Heads: {count_heads}')
print(f'Number of Tails: {count_tails}')
Leave a Comment »
Blog at WordPress.com.
Entries and Comments feeds.
Leave a comment