!pip install researchpy==0.3.2
Collecting researchpy==0.3.2
Downloading researchpy-0.3.2-py3-none-any.whl (15 kB)
Requirement already satisfied: scipy in /shared-libs/python3.7/py/lib/python3.7/site-packages (from researchpy==0.3.2) (1.7.3)
Requirement already satisfied: patsy in /root/venv/lib/python3.7/site-packages (from researchpy==0.3.2) (0.5.2)
Requirement already satisfied: statsmodels in /root/venv/lib/python3.7/site-packages (from researchpy==0.3.2) (0.13.1)
Requirement already satisfied: pandas in /shared-libs/python3.7/py/lib/python3.7/site-packages (from researchpy==0.3.2) (1.2.5)
Requirement already satisfied: numpy in /shared-libs/python3.7/py/lib/python3.7/site-packages (from researchpy==0.3.2) (1.19.5)
Requirement already satisfied: six in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from patsy->researchpy==0.3.2) (1.16.0)
Requirement already satisfied: python-dateutil>=2.7.3 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from pandas->researchpy==0.3.2) (2.8.2)
Requirement already satisfied: pytz>=2017.3 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pandas->researchpy==0.3.2) (2021.3)
Installing collected packages: researchpy
Successfully installed researchpy-0.3.2
WARNING: You are using pip version 20.1.1; however, version 21.3.1 is available.
You should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.
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()
D66int64
Denkint64
9
98
71
3
116
69
6
122
57
5
108
68
2
117
68
df_plur.head()
D66int64
Denkint64
3
63
67
5
75
57
7
58
67
11
73
60
6
67
60
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')
Execution error
KeyError: 'second_vote'
# 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
Variableobject
Nfloat64
0
Approval
4
1
Plurality
3
2
combined
7
results
Independent t-testobject
Difference (Approval - Plurality) = 10%
Degrees of freedom = 10%
8 others80%
resultsfloat64
0.1654 - 9.8673
0
Difference (Approval - Plurality) =
9.8673
1
Degrees of freedom =
5
2
t =
0.3751
3
Two side test p value =
0.723
4
Difference < 0 p value =
0.6385
5
Difference > 0 p value =
0.3615
6
Cohen's d =
0.2865
7
Hedge's g =
0.2413
8
Glass's delta =
0.2225
9
Pearson's r =
0.1654
sampling_difference = df_appr_mean - \
df_plur_mean
stats.shapiro(sampling_difference)
Execution error
ValueError: Data must be at least length 3.
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()
posx and posy should be finite values
posx and posy should be finite values