return 1 if 0.001 < pvalue < 0.01: return 2 if pvalue < 0.001: return 3 print(ns) print(s) ind = ["Gaussian", "Hessian", "Laplacian", "Ilastik", "MitoSegNet"] # ilastik vs mitonet significance_bar(pos_y=1.1, pos_x=[3, 4], bar_y=0.03, p=star_counter(p_il), y_dist=0.03, distance=0.11) # laplacian vs mitonet significance_bar(pos_y=1.2, pos_x=[2, 4], bar_y=0.03, p=star_counter(p_la), y_dist=0.03, distance=0.11) # hessian vs mitonet significance_bar(pos_y=1.3, pos_x=[1, 4], bar_y=0.03, p=star_counter(p_he), y_dist=0.03, distance=0.11) # gaussian vs mitonet significance_bar(pos_y=1.4, pos_x=[0, 4], bar_y=0.03, p=star_counter(p_ga), y_dist=0.03, distance=0.11) # creating stacked bar graph p1 = plt.bar(ind, ns) s = [1-i for i in ns] p2 = plt.bar(ind, s, bottom=ns) #p2 = plt.bar(ind, s1, bottom=ns, color="rosybrown")
def start_analysis(): desc = descriptor.get() stat_val = stat_value.get() tab1_name = table1_name.get() tab2_name = table2_name.get() ylab = stat_val + " " + desc.lower() ylab_size = 34 xlab = [table1_name.get(), table2_name.get()] new_tab1_name = tab1_name + " normality test p-value" new_tab2_name = tab2_name + " normality test p-value" stat_frame = pd.DataFrame(columns=[ new_tab1_name, new_tab2_name, "Hypothesis test", "Hypothesis test p-value", "Effect size", "N" ]) norm_p, dataframe, pval_l, eff_siz_l, hyp_test, max_vals = self.get_stats( desc, table_path1.get(), table_path2.get(), tab1_name, tab2_name, stat_val) if norm_p != False: # table with p-values and effect sizes ######## stat_frame[new_tab1_name] = [norm_p[0]] stat_frame[new_tab2_name] = [norm_p[1]] stat_frame["Hypothesis test"] = [hyp_test] stat_frame["Hypothesis test p-value"] = pval_l stat_frame["Effect size"] = eff_siz_l stat_frame["N"] = [len(dataframe)] ######## increase = 0 for index, row in stat_frame.iterrows(): if row["Hypothesis test p-value"] > 0.05: p = 0 elif 0.01 < row["Hypothesis test p-value"] < 0.05: p = 1 elif 0.001 < row["Hypothesis test p-value"] < 0.01: p = 2 else: p = 3 max_bar = np.max(max_vals) x1 = 0 x2 = 1 significance_bar(pos_y=max_bar + 0.1 * max_bar + increase, pos_x=[x1, x2], bar_y=max_bar * 0.05, p=p, y_dist=max_bar * 0.02, distance=0.05) increase += max_bar * 0.1 # select plot plot = sb.boxplot(data=dataframe, color="white", fliersize=0) sb.swarmplot(data=dataframe, color="black", size=8) # label the y axis plt.ylabel(ylab, fontsize=ylab_size) # label the x axis plt.xticks(list(range(len(xlab))), xlab) # determine fontsize of x and y ticks plot.tick_params(axis="x", labelsize=28) plot.tick_params(axis="y", labelsize=28) plt.show()
# print p-values based on chi-square test for seg in observed_values: if seg != "MitoSegNet": f_obs = [observed_values["MitoSegNet"].tolist(), observed_values[seg].tolist()] pval = chi2_contingency(f_obs, correction=False)[1] print(seg, pval) ind = ["MitoSegNet", "Pretrained\nFiji U-Net", "Ilastik", "Gaussian", "Hessian", "Laplacian"] dist = 0.1 bar_y = 0.03 significance_bar(pos_y=1.1, pos_x=[0, 1], bar_y=bar_y, p=2, y_dist=bar_y, distance=dist) significance_bar(pos_y=1.2, pos_x=[0, 2], bar_y=bar_y, p=2, y_dist=bar_y, distance=dist) significance_bar(pos_y=1.3, pos_x=[0, 3], bar_y=bar_y, p=3, y_dist=bar_y, distance=dist) significance_bar(pos_y=1.4, pos_x=[0, 4], bar_y=bar_y, p=3, y_dist=bar_y, distance=dist) significance_bar(pos_y=1.5, pos_x=[0, 5], bar_y=bar_y, p=3, y_dist=bar_y, distance=dist) # creating stacked bar graph #""" p1 = plt.bar(ind, ns, color="white", edgecolor="black") p2 = plt.bar(ind, s, bottom=ns, color="black", edgecolor="black") plt.legend((p1[0], p2[0]), ('p>0.05', 'p<0.05'), prop={"size": 20}, bbox_to_anchor=(1, 0.5)) #""" # possiblity to create stacked bar graph showing ns and three different alpha categories
elif 0.01 < row["Hypothesis test p-value"] < 0.05: p = 1 elif 0.001 < row["Hypothesis test p-value"] < 0.01: p = 2 else: p = 3 max_bar = np.max(max_vals) x1= file_list.index(row["Data 1"]) x2 = file_list.index(row["Data 2"]) significance_bar(pos_y=max_bar+0.1*max_bar+increase, pos_x=[x1, x2], bar_y=max_bar*0.05, p=p, y_dist=max_bar*0.02, distance=0.05) increase+=max_bar*0.1 # select plot plot = sb.boxplot(data=dataframe, color="white", fliersize=0) sb.swarmplot(data=dataframe, color="black", size=8) # label the y axis plt.ylabel(ylab, fontsize=ylab_size) # label the x axis plt.xticks(list(range(len(xlab))), xlab) # determine fontsize of x and y ticks
all_data["MitoSegNet"].tolist(), all_data["Finetuned\nFiji U-Net"].tolist() ]) print(dt) #dt.to_excel("soc_posthoc.xlsx") # check effect sizes of segmentations against msn segmentation for seg in seg_list: if seg != "MitoSegNet": print(seg, cohens_d(all_data[seg], all_data["MitoSegNet"])) bar_y = 0.03 significance_bar(pos_y=2.1, pos_x=[0, 2], bar_y=bar_y, p=3, y_dist=bar_y, distance=0.1) significance_bar(pos_y=2.2, pos_x=[0, 3], bar_y=bar_y, p=3, y_dist=bar_y, distance=0.1) significance_bar(pos_y=2.3, pos_x=[0, 4], bar_y=bar_y, p=1, y_dist=bar_y, distance=0.1) significance_bar(pos_y=2.4,
print("\n") print(cohens_d(all_data["Gaussian"], all_data["MitoSegNet"])) print(cohens_d(all_data["Hessian"], all_data["MitoSegNet"])) print(cohens_d(all_data["Laplacian"], all_data["MitoSegNet"])) print(cohens_d(all_data["Ilastik"], all_data["MitoSegNet"])) print(cohens_d(all_data["Finetuned\nFiji U-Net"], all_data["MitoSegNet"])) #print(cohens_d(all_data["Fiji U-Net"], all_data["MitoSegNet"])) pos_y_start = 11 dist_bar_y = 0.2 if p_f < 0.05: significance_bar(pos_y=pos_y_start, pos_x=[0, 1], bar_y=dist_bar_y, p=star_counter(p_f), y_dist=dist_bar_y, distance=0.11) if p_i < 0.05: significance_bar(pos_y=pos_y_start + 0.5, pos_x=[0, 2], bar_y=dist_bar_y, p=star_counter(p_i), y_dist=dist_bar_y, distance=0.11) if p_g < 0.05: significance_bar(pos_y=pos_y_start + 1, pos_x=[0, 3], bar_y=dist_bar_y, p=star_counter(p_g), y_dist=dist_bar_y,
all_data["Finetuned\nFiji U-Net"] = u_l_pt #all_data["Fiji U-Net"] = u_l #all_data.to_csv(path + "/dice_coefficient_table.csv") x = [0, 1] y = [1, 1] # pos_y and pos_x determine position of bar, p sets the number of asterisks, y_dist sets y distance of the asterisk to # bar, and distance sets the distance between two or more asterisks pd = 0.08 significance_bar(pos_y=1, pos_x=[0, 2], bar_y=0.02, p=2, y_dist=0.02, distance=pd) significance_bar(pos_y=1.05, pos_x=[0, 3], bar_y=0.02, p=3, y_dist=0.02, distance=pd) significance_bar(pos_y=1.1, pos_x=[0, 4], bar_y=0.02, p=1, y_dist=0.02, distance=pd) significance_bar(pos_y=1.15,
cohens_d = np.abs(np.average(data1) - np.average(data2)) / p_std return cohens_d print("\n") print(cohens_d(mitosegnet, hess)) print(cohens_d(mitosegnet, gauss)) print(cohens_d(mitosegnet, lap)) print(cohens_d(mitosegnet, il)) significance_bar(pos_y=2.9, pos_x=[0, 4], bar_y=0.1, p=3, y_dist=0.1, distance=0.11) significance_bar(pos_y=2.6, pos_x=[1, 4], bar_y=0.1, p=3, y_dist=0.1, distance=0.11) significance_bar(pos_y=2.3, pos_x=[2, 4], bar_y=0.1, p=3, y_dist=0.1, distance=0.11) significance_bar(pos_y=2,
]) print(dt) #dt.to_excel("ed_posthoc.xlsx") # check effect sizes of segmentations against msn segmentation for seg in seg_list: if seg != "MitoSegNet": print(seg, cohens_d(all_data[seg], all_data["MitoSegNet"])) pos_y_start = 6 dist_bar_y = 0.2 significance_bar(pos_y=pos_y_start + 0.5, pos_x=[0, 2], bar_y=dist_bar_y, p=1, y_dist=dist_bar_y, distance=0.11) significance_bar(pos_y=pos_y_start + 1.3, pos_x=[0, 3], bar_y=dist_bar_y, p=3, y_dist=dist_bar_y, distance=0.11) significance_bar(pos_y=pos_y_start + 2.1, pos_x=[0, 4], bar_y=dist_bar_y, p=1, y_dist=dist_bar_y, distance=0.11) significance_bar(pos_y=pos_y_start + 3.5,
all_data["Laplacian"] ]) #print(dt) #dt.to_excel("dc_posthoc.xlsx") #print(cohens_d(all_data["MitoSegNet"], all_data["Ilastik"])) # pos_y and pos_x determine position of bar, p sets the number of asterisks, y_dist sets y distance of the asterisk to # bar, and distance sets the distance between two or more asterisks dist = 0.08 bar_y = 0.02 significance_bar(pos_y=1, pos_x=[0, 2], bar_y=bar_y, p=2, y_dist=bar_y, distance=dist) significance_bar(pos_y=1.05, pos_x=[0, 3], bar_y=bar_y, p=3, y_dist=bar_y, distance=dist) significance_bar(pos_y=1.1, pos_x=[0, 4], bar_y=bar_y, p=1, y_dist=bar_y, distance=dist) significance_bar(pos_y=1.15,
ga_l.append(i_u_g) h_l.append(i_u_h) la_l.append(i_u_l) il_l.append(i_u_il) u_l_1.append(i_u_m) all_data["Gaussian"] = ga_l all_data["Hessian"] = h_l all_data["Laplacian"] = la_l all_data["Ilastik"] = il_l all_data["MitoSegNet"] = u_l_1 significance_bar(pos_y=1, pos_x=[0, 4], bar_y=0.03, p=1, y_dist=0.02, distance=0.1) sb.boxplot(data=all_data, color="skyblue") #.set(ylabel="Dice coefficient") plt.ylabel("Intersection over Union", size=18) plt.yticks(fontsize=12) plt.xticks(fontsize=12) print(normaltest(all_data["Gaussian"])[1]) print(normaltest(all_data["Hessian"])[1]) print(normaltest(all_data["Laplacian"])[1]) print(normaltest(all_data["Ilastik"])[1]) print(normaltest(all_data["MitoSegNet"])[1])