Skip to content

Instantly share code, notes, and snippets.

@wiccy46
Created July 22, 2019 16:56
Show Gist options
  • Select an option

  • Save wiccy46/5c34cd3b57ba68b2141043776401e4ba to your computer and use it in GitHub Desktop.

Select an option

Save wiccy46/5c34cd3b57ba68b2141043776401e4ba to your computer and use it in GitHub Desktop.
[withinErrBar]Within subject error bar #python #DataAnalysis
def within_subject_errorbar(df, ci_r = 1.96):
df["Subject average"] = df.mean(axis = 1)
df_grand_avg = df["Subject average"].mean()
df["New condition1"] = df["condition1"] - df["Subject average"] + df_grand_avg
df["New condition2"] = df["condition2"] - df["Subject average"] + df_grand_avg
std_vo, std_me = df["New condition1"].std(), df["New condition2"].std()
se_vo, se_me = std_vo/sqrt(df.shape[0]), std_me/sqrt(df.shape[0])
err_vo, err_me = se_vo * ci_r, se_me * ci_r
return err_vo, err_me
# Barplot
graph = sns.factorplot(x="Result Type", y="Accuracy", hue="Condition", data=massAndVolume
, kind="bar", palette="RdBu_r", ci = None)
# draw significance
plt.ylim(0, 1.)
col = 'k'
x0, x1 = -0.2, 0.2
h0 = 0.8
y0 = 0.6
y1 = 0.75
plt.plot([x0,x0,x1,x1], [y0 , h0 , h0, y1], lw = 2, c = col)
plt.text((x0+x1)*.5, h0, '*', ha = 'center', va = 'bottom', color = col, fontsize = 12 )
# draw error bar.
(_, caps, _) = plt.errorbar([-0.2, 0.2], [massVoMean, massMeMean], yerr = [massErr, massErr],
elinewidth = 2, ecolor = "k", fmt = ' ',capsize = 4)
for cap in caps:
cap.set_color('k')
cap.set_markeredgewidth(2)
(_, caps, _) = plt.errorbar([0.8, 1.2], [volumeVoMean, volumeMeMean], yerr = [volumeErr, volumeErr],
elinewidth = 2, ecolor = "k", fmt = ' ',capsize = 4)
for cap in caps:
cap.set_color('k')
cap.set_markeredgewidth(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment