Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions statistics/src/chi_squared_test_draw_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ class ChiSquaredTestDrawGraph:
xlabel: string.
ylabel: string.
tight_layout: bool. if execute tight_layout, set True.
mode: string. paried or unpaired
p: float.
"""
def draw_graph(self, data, label, title, xlabel, ylabel, tight_layout=False, p=None):
def draw_graph(self, data, label, title, xlabel, ylabel, tight_layout=False, mode="paired", p=None):
"""
fig: make figure instance
"""
Expand Down Expand Up @@ -59,19 +60,25 @@ def draw_graph(self, data, label, title, xlabel, ylabel, tight_layout=False, p=N
ax = plt.gca()
for i in range(len(y_data1)):
# x, y, displaying y value, width position, height position (va="top": bottom of (x, y))
plt.text(left[i] - 0.02, y_data1[i] / 2.0, (round (y_data1[i] * 100.0)) * 0.01, ha='center', va='top', fontsize=28)
plt.text(left[i] - 0.02, y_data1[i] / 2.0, str(str((round (y_data1[i] * 100.0)) * 0.01) + " ("+ str(data[i][0]) +")"), ha='center', va='top', fontsize=28)

plt.text(left[0] - 0.02, y_data1[i] - (y_data2[0] / 2.0), (round (y_data2[0] * 100.0)) * 0.01, ha='center', va='top', fontsize=28)
# avoid overlapping with legend
plt.text(left[1] - 0.1, y_data1[1] - (y_data2[1] / 2.0), (round (y_data2[1] * 100.0)) * 0.01, ha='center', va='top', fontsize=28)
plt.text(left[0] - 0.02, y_data1[0] + (y_data2[0] / 2.0), str(str((round (y_data2[0] * 100.0)) * 0.01) + " ("+ str(data[0][1]) +")"), ha='center', va='top', fontsize=28)
if y_data1[1] + y_data2[1] * 0.5 > 80.0:
# avoid overlapping with legend
plt.text(left[1] - 0.1, y_data1[1] + (y_data2[1] / 2.0), str(str((round (y_data2[1] * 100.0)) * 0.01) + " ("+ str(data[1][1]) +")"), ha='center', va='top', fontsize=28)
else:
plt.text(left[1] - 0.02, y_data1[1] + (y_data2[1] / 2.0), str(str((round (y_data2[1] * 100.0)) * 0.01) + " ("+ str(data[1][1]) +")"), ha='center', va='top', fontsize=28)
"""
add x label in each bar
"""
plt.xticks(left, label)
"""
add title, label
"""
new_title = title + "\n(N = " + str(data[0][0] + data[0][1] + data[1][0] + data[1][1]) + " for total (" + str(label[0]) + ": " + str(data[0][0] + data[0][1]) + ", " + str(label[1]) + ": " + str(data[1][0] + data[1][1]) + "),\n * p < 0.05, ** p < 0.01)"
if mode == "unpaired":
new_title = title + "\n(N = " + str(data[0][0] + data[0][1] + data[1][0] + data[1][1]) + " for total (" + str(label[0]) + ": " + str(data[0][0] + data[0][1]) + ", " + str(label[1]) + ": " + str(data[1][0] + data[1][1]) + "),\n * p < 0.05, ** p < 0.01)"
elif mode == "paired":
new_title = title + "\n(N = " + str(data[0][0] + data[0][1]) + " for each type, * p < 0.05, ** p < 0.01)"
plt.title(new_title)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
Expand Down
50 changes: 48 additions & 2 deletions statistics/src/sample_chi_squared_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,53 @@
print "python sample_chi_squared_test.py"
else:
d = ChiSquaredTestDrawGraph()
data = np.array([[1625, 5],[1022, 11]])
d.draw_graph(data, ["Condition1", "Condition2"], "test", "x", "y", tight_layout=True)
# Q2 children
#data = np.array([[43, 28],[19, 52]])
# Q2 adults
# data = np.array([[8, 12],[11, 9]])

# enquette
# q1. adults (29), children (27)
#data = np.array([[20, 9],[18, 9]])
# q1. female (30), male (26)
#data = np.array([[21, 9],[17, 9]])

# q2. adults (29), children (27)
#data = np.array([[7, 22],[16, 11]])
# q2. female (30), male (26)
#data = np.array([[15, 15],[8, 18]])

# q3. adults (29), children (27)
#data = np.array([[16, 13],[12, 15]])
# q3. female (30), male (26)
#data = np.array([[16, 14],[12, 14]])

# q4. adults (29), children (27)
#data = np.array([[9, 20],[15, 12]])
# q4. female (30), male (26)
data = np.array([[13, 17],[11, 15]])

# q1. adults-children
# d.draw_graph(data, ["Adults", "Children"], "The ratio of people who want to use a robot which helps doing household chores", "condition", "percentage", tight_layout=True, mode="unpaired")
# q1. female-male
# d.draw_graph(data, ["Female", "Male"], "The ratio of people who want to use a robot which helps doing household chores", "condition", "percentage", tight_layout=True, mode="unpaired")

# q2. adults-children
#d.draw_graph(data, ["Adults", "Children"], "The ratio of people who want to use a robot which can be a companion for its user", "condition", "percentage", tight_layout=True, mode="unpaired")
# q2. female-male
# d.draw_graph(data, ["Female", "Male"], "The ratio of people who want to use a robot which can be a companion for its user", "condition", "percentage", tight_layout=True, mode="unpaired")

# q3. adults-children
# d.draw_graph(data, ["Adults", "Children"], "The ratio of people who want to use a robot which takes care of its user's health", "condition", "percentage", tight_layout=True, mode="unpaired")
# q3. female-male
# d.draw_graph(data, ["Female", "Male"], "The ratio of people who want to use a robot which takes care of its user's health", "condition", "percentage", tight_layout=True, mode="unpaired")

# q4. adults-children
# d.draw_graph(data, ["Adults", "Children"], "The ratio of people who want to use a robot which its user can raise it", "condition", "percentage", tight_layout=True, mode="unpaired")
# q4. female-male
# d.draw_graph(data, ["Female", "Male"], "The ratio of people who want to use a robot which its user can raise it", "condition", "percentage", tight_layout=True, mode="unpaired")

d.draw_graph(data, ["Touch", "Speak"], "The ratio of children who touched or spoke to the robot \n on their own accord", "condition", "percentage", tight_layout=True, mode="paired")
# d.draw_graph(data, ["Touch", "Speak"], "The ratio of adults who touched or spoke to the robot \n on their own accord", "condition", "percentage", tight_layout=True, mode="paired")
# TODO
# draw table