!pip install researchpy==0.3.2
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import researchpy as rp
import scipy.stats as stats
import statsmodels.api as sm
# Loading in the files
df_appr = pd.read_csv('voting_sim approval voting-table.csv',index_col = 0,sep=',')
df_plur = pd.read_csv('voting_sim plurality voting-table.csv',index_col = 0,sep=',')
df_appr_strat = pd.read_csv('voting_sim approval strategic voting-table.csv',index_col = 0,sep=',')
df_plur_strat = pd.read_csv('voting_sim plurality voting strategic-table.csv',index_col = 0,sep=',')
# Renaming the columns:
df_appr = df_appr.rename(columns={'count links with [color = red]': df_appr.iloc[0][0],\
'count links with [color = green]': df_appr.iloc[0][1],\
'count links with [color = blue]': df_appr.iloc[0][2],\
'count turtles with [color = black]': 'Geen stem'})
df_appr_strat = df_appr_strat.rename(columns={'count links with [color = red]': df_appr_strat.iloc[0][0],\
'count links with [color = green]': df_appr_strat.iloc[0][1],\
'count links with [color = blue]': df_appr_strat.iloc[0][2],\
'count turtles with [color = black]': 'Geen stem'})
df_plur = df_plur.rename(columns={'count turtles with [color = red]': df_plur.iloc[0][0],\
'count turtles with [color = green]': df_plur.iloc[0][1],\
'count turtles with [color = blue]': df_plur.iloc[0][2]})
df_plur_strat = df_plur_strat.rename(columns={'count turtles with [color = red]': df_plur_strat.iloc[0][0],\
'count turtles with [color = green]': df_plur_strat.iloc[0][1],\
'count turtles with [color = blue]': df_plur_strat.iloc[0][2]})
# Deleting the step before the voting has happened
df_appr = df_appr[df_appr['[step]'] != 0]
df_plur = df_plur[df_plur['[step]'] != 0]
# Dropping unnecessary columns
df_appr = df_appr.drop(['partij1','partij2', 'partij3', 'number_of_voters', '[step]'], axis = 1)
df_plur = df_plur.drop(['partij1','partij2', 'partij3', 'number_of_voters', '[step]'], axis = 1)
df_appr_strat = df_appr_strat[df_appr_strat['[step]'] != 0]
df_plur_strat = df_plur_strat[df_plur_strat['[step]'] != 0]
df_appr_strat = df_appr_strat.drop(['partij1','partij2', 'partij3', 'number_of_voters', 'radius', 'third_vote','[step]'], axis = 1)
df_plur_strat = df_plur_strat.drop(['partij1','partij2', 'partij3', 'number_of_voters', 'radius', '[step]'], axis = 1)
T-test
df_appr.head()
df_plur.head()
rp.ttest(group1= df_appr_strat['first_vote']['second_vote'], group1_name= 'Approval Strategic',
group2= df_plur_strat['first_vote']['second_vote'], group2_name= 'Plurality Strategic')
# Get a summary of the values in
df_appr_mean = df_appr.mean()
df_plur_mean = df_plur.mean()
summary, results = rp.ttest(group1= df_appr.mean(), group1_name= 'Approval',
group2= df_plur.mean(), group2_name= 'Plurality')
summary
results
sampling_difference = df_appr_mean - \
df_plur_mean
stats.shapiro(sampling_difference)
fig = plt.figure(figsize= (20, 10))
ax = fig.add_subplot(111)
normality_plot, stat = stats.probplot(sampling_difference, plot= plt, rvalue= True)
ax.set_title("Probability plot of sampling difference", fontsize= 20)
ax.set
plt.show()