ACCLAB / DABEST-python

Data Analysis with Bootstrapped ESTimation
https://acclab.github.io/DABEST-python/
Apache License 2.0
341 stars 47 forks source link

Median rather than mean - Multi two groups #50

Closed AnaFVicente closed 5 years ago

AnaFVicente commented 5 years ago

Hello, Regarding Multi two-group estimation plot, is it possible to plot the median ± standard deviation of the measurements for each group, instead of the mean? Thanks in advance

josesho commented 5 years ago

Hi,

Sorry for the delay! It is possible to plot median and quartiles for each group. Simply use the group_summaries keyword when plotting. (You can see the documentation for more info.)

np.random.seed(55555) # Fix the seed so the results are replicable.
Ns = 20 # The number of samples taken from each population

# Create samples
c1 = norm.rvs(loc=3, scale=0.2, size=Ns)
t1 = norm.rvs(loc=3.5, scale=0.4, size=Ns)

c2 = norm.rvs(loc=3.2, scale=0.5, size=Ns)
t2 = norm.rvs(loc=3.5, scale=0.75, size=Ns)

df = pd.DataFrame({'Control 1' : c1, 
                   'Test 1'    : t1,

                   'Control 2' : c2, 
                   'Test 2'    : t2,
                  })

# Run dabest analysis
df_analysis = dabest.load(df, 
                          idx=(('Control 1', 'Test 1'),
                               ('Control 2', 'Test 2')), 
                         )

fig_means = df_analysis.mean_diff.plot(group_summaries='mean_sd');
fig_means.suptitle("Means and SDs")

fig_medians = df_analysis.mean_diff.plot(group_summaries='median_quartiles');
fig_medians.suptitle("Medians and quartiles")

image image