# -*- coding: utf-8 -*- """ Created on Sun Jan 9 10:26:00 2022 @author: Rene """ import numpy as np import matplotlib.pyplot as plt def h_1(Jury_Sample): n = len(Jury_Sample) value=(np.sum(Jury_Sample)-np.min(Jury_Sample)-np.max(Jury_Sample))/(n-2) return(value) def h_2(Jury_Sample): value = np.median(Jury_Sample) return(value) N_Jurors= 7 Score = 8 jury_scores = np.repeat(Score,N_Jurors) jury_scores = jury_scores + np.random.uniform(-0.5,0.5,N_Jurors,) jury_scores print(h_1(jury_scores)) print(h_2(jury_scores)) m = 1000 M = np.zeros(m) T = np.zeros(m) for i in np.arange(0,m): jury_scores = np.repeat(Score,N_Jurors) jury_scores = jury_scores + np.random.uniform(-0.5,0.5,N_Jurors,) T[i] = np.abs(h_1(jury_scores)-Score) M[i] = np.abs(h_2(jury_scores)-Score) P_M_better = np.sum(M|T|) = $'+ f'{1-P_M_better:0.3f}' plt.text(0.025,0.375,text_str,horizontalalignment = 'left',verticalalignment = 'center', color = 'black') text_str = r'$M$ is better' plt.text(0.475,0.125,text_str,horizontalalignment = 'right',verticalalignment = 'center', color = 'black') text_str = r'$Pr(|M|<|T|) = $'+ f'{P_M_better:0.3f}' plt.text(0.475,0.075,text_str,horizontalalignment = 'right',verticalalignment = 'center', color = 'black') #*************************************************************************************** LB_x = -0.3 UB_x = 0.3 off_set_x = 0.05*(UB_x-LB_x) x_lims = (LB_x-off_set_x,UB_x+off_set_x) LB_y = 0 UB_y = 7 off_set_y = 0.05*(UB_y-LB_y) y_lims = (LB_y-off_set_y,UB_y+off_set_y) Panel = Figure.add_subplot(1,2,2) plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('$|M|-|T|$') plt.ylabel('Density') text_str = r'Jury Rule Evaluation' plt.title(text_str) plt.axvline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.hist(M-T,density = 'True',color = 'red',alpha=0.5,edgecolor = 'black') text_str = r'$M$ is better' plt.text(-0.3,6.5,text_str,horizontalalignment = 'left',verticalalignment = 'center', color = 'black') text_str = r'$Pr(|M|<|T|) = $' plt.text(-0.3,6,text_str,horizontalalignment = 'left',verticalalignment = 'center', color = 'black') text_str = f'{P_M_better:0.3f}' plt.text(-0.3,5.5,text_str,horizontalalignment = 'left',verticalalignment = 'center', color = 'black') text_str = r'$T$ is better' plt.text(0.3,6.5,text_str,horizontalalignment = 'right',verticalalignment = 'center', color = 'black') text_str = r'$Pr(|M|>|T|) = $' plt.text(0.3,6,text_str,horizontalalignment = 'right',verticalalignment = 'center', color = 'black') text_str = f'{1-P_M_better:0.3f}' plt.text(0.3,5.5,text_str,horizontalalignment = 'right',verticalalignment = 'center', color = 'black') plt.savefig('Jury_Sampler.png', dpi=300)