From 61aed4c3a9aa34a5318cb4cc37a406d126362dc8 Mon Sep 17 00:00:00 2001 From: Kanae Kochigami Date: Mon, 6 Nov 2017 16:18:39 +0900 Subject: [PATCH 1/5] add more sample --- statistics/src/chi_squared_test_draw_graph.py | 17 ++++++++++++----- statistics/src/sample_chi_squared_test.py | 9 +++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/statistics/src/chi_squared_test_draw_graph.py b/statistics/src/chi_squared_test_draw_graph.py index d39eb86..1793d87 100755 --- a/statistics/src/chi_squared_test_draw_graph.py +++ b/statistics/src/chi_squared_test_draw_graph.py @@ -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 """ @@ -61,9 +62,12 @@ def draw_graph(self, data, label, title, xlabel, ylabel, tight_layout=False, p=N # 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[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), (round (y_data2[0] * 100.0)) * 0.01, 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), (round (y_data2[1] * 100.0)) * 0.01, ha='center', va='top', fontsize=28) + else: + plt.text(left[1] - 0.02, y_data1[1] + (y_data2[1] / 2.0), (round (y_data2[1] * 100.0)) * 0.01, ha='center', va='top', fontsize=28) """ add x label in each bar """ @@ -71,7 +75,10 @@ def draw_graph(self, data, label, title, xlabel, ylabel, tight_layout=False, p=N """ 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) diff --git a/statistics/src/sample_chi_squared_test.py b/statistics/src/sample_chi_squared_test.py index 34e87dc..82cf3a3 100755 --- a/statistics/src/sample_chi_squared_test.py +++ b/statistics/src/sample_chi_squared_test.py @@ -14,7 +14,12 @@ 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 + # data = np.array([[26, 27],[7, 10]]) + # Q3 children + data = np.array([[43, 28],[19, 52]]) + # Q3 adults + #data = np.array([[8, 12],[11, 9]]) + d.draw_graph(data, ["Condition1", "Condition2"], "test", "x", "y", tight_layout=True, mode="paired") # TODO # draw table From ade9aac19a889d353e275d701ebc37b7dfd9c58c Mon Sep 17 00:00:00 2001 From: Kanae Kochigami Date: Mon, 6 Nov 2017 18:36:31 +0900 Subject: [PATCH 2/5] add sample --- statistics/src/sample_chi_squared_test.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/statistics/src/sample_chi_squared_test.py b/statistics/src/sample_chi_squared_test.py index 82cf3a3..530ab87 100755 --- a/statistics/src/sample_chi_squared_test.py +++ b/statistics/src/sample_chi_squared_test.py @@ -16,10 +16,27 @@ d = ChiSquaredTestDrawGraph() # Q2 # data = np.array([[26, 27],[7, 10]]) - # Q3 children + # Q2 children data = np.array([[43, 28],[19, 52]]) + # Q2 adults + # data = np.array([[8, 12],[11, 9]]) + # Q3 children + # data = np.array([[4, 7],[4, 10]]) # Q3 adults - #data = np.array([[8, 12],[11, 9]]) - d.draw_graph(data, ["Condition1", "Condition2"], "test", "x", "y", tight_layout=True, mode="paired") + # data = np.array([[4, 6],[3, 7]]) + # enquette + # data = np.array([[20, 9],[18, 9]]) + # data = np.array([[21, 9],[17, 9]]) + + # data = np.array([[7, 22],[16, 11]]) + # data = np.array([[15, 15],[8, 18]]) + + # data = np.array([[16, 13],[12, 15]]) + # data = np.array([[16, 14],[12, 14]]) + + # data = np.array([[9, 20],[15, 12]]) + data = np.array([[15, 12],[11, 15]]) + + d.draw_graph(data, ["Condition1", "Condition2"], "test", "x", "y", tight_layout=True, mode="unpaired") # TODO # draw table From f90bbb3e877d10b25750cc6276344d46c2ad813b Mon Sep 17 00:00:00 2001 From: Kanae Kochigami Date: Sat, 11 Nov 2017 23:26:58 +0900 Subject: [PATCH 3/5] add raw data display --- statistics/src/chi_squared_test_draw_graph.py | 8 ++++---- statistics/src/sample_chi_squared_test.py | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/statistics/src/chi_squared_test_draw_graph.py b/statistics/src/chi_squared_test_draw_graph.py index 1793d87..6f3bff2 100755 --- a/statistics/src/chi_squared_test_draw_graph.py +++ b/statistics/src/chi_squared_test_draw_graph.py @@ -60,14 +60,14 @@ def draw_graph(self, data, label, title, xlabel, ylabel, tight_layout=False, mod 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[0][i]) +")"), ha='center', va='top', fontsize=28) - plt.text(left[0] - 0.02, y_data1[0] + (y_data2[0] / 2.0), (round (y_data2[0] * 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[1][0]) +")"), 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), (round (y_data2[1] * 100.0)) * 0.01, ha='center', va='top', fontsize=28) + 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), (round (y_data2[1] * 100.0)) * 0.01, ha='center', va='top', fontsize=28) + 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 """ diff --git a/statistics/src/sample_chi_squared_test.py b/statistics/src/sample_chi_squared_test.py index 530ab87..ea5b9e0 100755 --- a/statistics/src/sample_chi_squared_test.py +++ b/statistics/src/sample_chi_squared_test.py @@ -17,9 +17,9 @@ # Q2 # data = np.array([[26, 27],[7, 10]]) # Q2 children - data = np.array([[43, 28],[19, 52]]) + # data = np.array([[43, 28],[19, 52]]) # Q2 adults - # data = np.array([[8, 12],[11, 9]]) + data = np.array([[8, 12],[11, 9]]) # Q3 children # data = np.array([[4, 7],[4, 10]]) # Q3 adults @@ -35,8 +35,9 @@ # data = np.array([[16, 14],[12, 14]]) # data = np.array([[9, 20],[15, 12]]) - data = np.array([[15, 12],[11, 15]]) - - d.draw_graph(data, ["Condition1", "Condition2"], "test", "x", "y", tight_layout=True, mode="unpaired") + # data = np.array([[15, 12],[11, 15]]) + + # 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 From 8809ed190c3c00dcd631e98eb8b1fff8b43d9e31 Mon Sep 17 00:00:00 2001 From: Kanae Kochigami Date: Mon, 13 Nov 2017 17:29:58 +0900 Subject: [PATCH 4/5] fix display bug --- statistics/src/chi_squared_test_draw_graph.py | 4 +- statistics/src/sample_chi_squared_test.py | 45 ++++++++++++++----- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/statistics/src/chi_squared_test_draw_graph.py b/statistics/src/chi_squared_test_draw_graph.py index 6f3bff2..0a57664 100755 --- a/statistics/src/chi_squared_test_draw_graph.py +++ b/statistics/src/chi_squared_test_draw_graph.py @@ -60,9 +60,9 @@ def draw_graph(self, data, label, title, xlabel, ylabel, tight_layout=False, mod 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, str(str((round (y_data1[i] * 100.0)) * 0.01) + " ("+ str(data[0][i]) +")"), 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[0] + (y_data2[0] / 2.0), str(str((round (y_data2[0] * 100.0)) * 0.01) + " ("+ str(data[1][0]) +")"), 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) diff --git a/statistics/src/sample_chi_squared_test.py b/statistics/src/sample_chi_squared_test.py index ea5b9e0..38c8214 100755 --- a/statistics/src/sample_chi_squared_test.py +++ b/statistics/src/sample_chi_squared_test.py @@ -14,30 +14,53 @@ print "python sample_chi_squared_test.py" else: d = ChiSquaredTestDrawGraph() - # Q2 - # data = np.array([[26, 27],[7, 10]]) # Q2 children - # data = np.array([[43, 28],[19, 52]]) + data = np.array([[43, 28],[19, 52]]) # Q2 adults - data = np.array([[8, 12],[11, 9]]) - # Q3 children - # data = np.array([[4, 7],[4, 10]]) - # Q3 adults - # data = np.array([[4, 6],[3, 7]]) + # 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]]) - # data = np.array([[15, 12],[11, 15]]) + # 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") + 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 From 8aa085c90505065b798f16b9f1198de25afc3002 Mon Sep 17 00:00:00 2001 From: Kanae Kochigami Date: Tue, 16 Jan 2018 10:07:29 +0900 Subject: [PATCH 5/5] print chi value --- statistics/src/sample_chi_squared_test.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/statistics/src/sample_chi_squared_test.py b/statistics/src/sample_chi_squared_test.py index 38c8214..4d6a02e 100755 --- a/statistics/src/sample_chi_squared_test.py +++ b/statistics/src/sample_chi_squared_test.py @@ -15,30 +15,30 @@ else: d = ChiSquaredTestDrawGraph() # Q2 children - data = np.array([[43, 28],[19, 52]]) + #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]]) + #data = np.array([[20, 9],[18, 9]]) # q1. female (30), male (26) - # data = np.array([[21, 9],[17, 9]]) + #data = np.array([[21, 9],[17, 9]]) # q2. adults (29), children (27) - # data = np.array([[7, 22],[16, 11]]) + #data = np.array([[7, 22],[16, 11]]) # q2. female (30), male (26) - # data = np.array([[15, 15],[8, 18]]) + #data = np.array([[15, 15],[8, 18]]) # q3. adults (29), children (27) - # data = np.array([[16, 13],[12, 15]]) + #data = np.array([[16, 13],[12, 15]]) # q3. female (30), male (26) - # data = np.array([[16, 14],[12, 14]]) + #data = np.array([[16, 14],[12, 14]]) # q4. adults (29), children (27) - # data = np.array([[9, 20],[15, 12]]) + #data = np.array([[9, 20],[15, 12]]) # q4. female (30), male (26) - # data = np.array([[13, 17],[11, 15]]) + 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")