social_divide_stats.py 847 B

1234567891011121314151617181920212223242526272829303132333435
  1. import pandas as pd
  2. import numpy as np
  3. from scipy.stats import beta
  4. q = 0.2
  5. fit = pd.read_parquet("output/social_divide_samples.parquet")
  6. results = []
  7. for i, cat in enumerate(['th','exp','ph']):
  8. alphas = fit[f'alphas.{i+1}'].values
  9. betas = fit[f'betas.{i+1}'].values
  10. lows = np.zeros(len(fit))
  11. highs = np.zeros(len(fit))
  12. for j in range(len(fit)):
  13. lows[j] = beta.cdf(q, alphas[j], betas[j])
  14. highs[j] = 1-beta.cdf(1-q, alphas[j], betas[j])
  15. print(lows)
  16. print(highs)
  17. results.append({
  18. 'cat': cat,
  19. 'low': np.mean(lows),
  20. 'high': np.mean(highs),
  21. 'alpha': np.mean(alphas),
  22. 'beta': np.mean(betas)
  23. })
  24. results = pd.DataFrame(results)
  25. results['total'] = results['low']+results['high']
  26. results.to_csv("models/social_divide/entrenchment.csv")
  27. print(results)