-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ACCLAB/v0.1.3
v0.1.3
- Loading branch information
Showing
20 changed files
with
325 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
from .api import plot | ||
from .bootstrap_tools import bootstrap | ||
|
||
__version__="0.1.2" | ||
__version__="0.1.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
#!/usr/bin/python | ||
# -*-coding: utf-8 -*- | ||
# Author: Joses Ho | ||
# Email : [email protected] | ||
|
||
|
||
|
||
def plot(data, idx, | ||
|
@@ -732,5 +737,9 @@ def plot(data, idx, | |
value=np.nan).dropna(axis=1) | ||
# Reset seaborn aesthetic parameters. | ||
sns.set() | ||
|
||
if swarm_label is not None: | ||
fig.axes[0].set_ylabel(swarm_label) | ||
|
||
# Return the figure and the results DataFrame. | ||
return fig, bootlist_df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
#!/usr/bin/python | ||
# -*-coding: utf-8 -*- | ||
# Author: Joses Ho | ||
# Email : [email protected] | ||
|
||
|
||
from __future__ import division | ||
|
||
|
||
|
@@ -160,7 +166,7 @@ def __init__(self, x1, x2=None, | |
|
||
else: | ||
diff = True | ||
tx = x2-x1 | ||
tx = x2 - x1 | ||
ttest_single = 'NIL' | ||
ttest_2_ind = 'NIL' | ||
ttest_2_paired = ttest_rel(x1,x2)[1] | ||
|
@@ -183,6 +189,7 @@ def __init__(self, x1, x2=None, | |
|
||
elif x2 is not None and paired is False: | ||
diff = True | ||
x2 = pd.Series(x2).dropna() | ||
# Generate statarrays for both arrays. | ||
ref_statarray = sns.algorithms.bootstrap(x1, **sns_bootstrap_kwargs) | ||
exp_statarray = sns.algorithms.bootstrap(x2, **sns_bootstrap_kwargs) | ||
|
@@ -290,6 +297,8 @@ def bca(data, alphas, statarray, statfunction, ostat, reps): | |
Subroutine called to calculate the BCa statistics. | ||
Borrowed heavily from scikits.bootstrap code. | ||
''' | ||
import warnings | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import seaborn as sns | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
#!/usr/bin/python | ||
# -*-coding: utf-8 -*- | ||
# Author: Joses Ho | ||
# Email : [email protected] | ||
|
||
# CONVENIENCE FUNCTIONS THAT DON'T DIRECTLY DEAL WITH PLOTTING OR | ||
# BOOTSTRAP COMPUTATIONS ARE PLACED HERE. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
""" | ||
A set of convenience functions used for producing plots in `dabest`. | ||
#!/usr/bin/python | ||
# -*-coding: utf-8 -*- | ||
# Author: Joses Ho | ||
# Email : [email protected] | ||
# A set of convenience functions used for producing plots in `dabest`. | ||
|
||
Author: Joses W. Ho | ||
Email: [email protected] | ||
License: MIT | ||
""" | ||
|
||
|
||
import matplotlib.pyplot as plt | ||
|
@@ -14,6 +13,7 @@ | |
from .misc_tools import merge_two_dicts | ||
|
||
|
||
|
||
def halfviolin(v, half = 'right', color = 'k'): | ||
for b in v['bodies']: | ||
mVertical = np.mean(b.get_paths()[0].vertices[:, 0]) | ||
|
@@ -33,6 +33,8 @@ def halfviolin(v, half = 'right', color = 'k'): | |
mHorizontal, np.inf) | ||
b.set_color(color) | ||
|
||
|
||
|
||
def align_yaxis(ax1, v1, ax2, v2): | ||
"""adjust ax2 ylimit so that v2 in ax2 is aligned to v1 in ax1""" | ||
# Taken from | ||
|
@@ -50,90 +52,7 @@ def rotate_ticks(axes, angle=45, alignment='right'): | |
tick.set_rotation(angle) | ||
tick.set_horizontalalignment(alignment) | ||
|
||
def tufte_summary_line(df, x, y, type='mean_sd', | ||
offset=0.3, ax=None, **kwargs): | ||
'''Convenience function to plot sumamry statistics (mean and standard | ||
deviation, or median and 25th & 75th percentiles) for ach group in the `x` | ||
column of `df`. This style is inspired by Edward Tufte. | ||
Keywords | ||
-------- | ||
data: pandas DataFrame. | ||
This DataFrame should be in 'long' format. | ||
x, y: string. | ||
x and y columns to be plotted. | ||
type: {'mean_sd', 'median_quartiles'}, default 'mean_sd' | ||
Plots the summary statistics for each group. If 'mean_sd', then the | ||
mean and standard deviation of each group is plotted as a notched | ||
line beside each group. If 'median_quantile', then the | ||
median and 25th and 75th percentiles of each group is plotted | ||
instead. | ||
offset: float, default 0.4 | ||
The x-offset of the summary line. | ||
offset: matplotlib Axes, default None | ||
If specified, the axes to plot on. | ||
kwargs: dict, default None | ||
Dictionary with kwargs passed to `matplotlib.patches.FancyArrow`. | ||
See docs at | ||
https://matplotlib.org/api/_as_gen/ | ||
matplotlib.patches.FancyArrow.html#matplotlib.patches.FancyArrow | ||
''' | ||
import matplotlib.patches as mpatches | ||
|
||
if ax is None: | ||
ax = plt.gca() | ||
|
||
means = df.groupby(x)[y].mean() | ||
sd = df.groupby(x)[y].std() | ||
lower_sd = means - sd | ||
upper_sd = means + sd | ||
|
||
medians = df.groupby(x)[y].median() | ||
quantiles = df.groupby(x)[y].quantile([0.25, 0.75]).unstack() | ||
lower_quartiles = quantiles[0.25] | ||
upper_quartiles = quantiles[0.75] | ||
|
||
if type == 'mean_sd': | ||
central_measures = means | ||
low = lower_sd | ||
high = upper_sd | ||
elif type == 'median_quartiles': | ||
central_measures = medians | ||
low = lower_quartiles | ||
high = upper_quartiles | ||
|
||
total_width = 0.05 # the horizontal span of the line, aka `linewidth`. | ||
|
||
for k, m in enumerate(central_measures): | ||
|
||
kwargs['dx'] = 0 | ||
kwargs['width'] = total_width | ||
kwargs['head_width'] = total_width | ||
kwargs['length_includes_head'] = True | ||
|
||
if type == 'mean_sd': | ||
dy_low = dy_high = sd[k] | ||
elif type == 'median_quartiles': | ||
dy_low = m - low[k] | ||
dy_high = high[k] - m | ||
|
||
arrow = mpatches.FancyArrow(x=offset+k, y=low[k], | ||
dy=dy_low, | ||
head_length=0.3*dy_low, | ||
**kwargs) | ||
ax.add_patch(arrow) | ||
|
||
arrow = mpatches.FancyArrow(x=offset+k, y=high[k], | ||
dy=-dy_high, | ||
head_length=0.3*dy_high, | ||
**kwargs) | ||
ax.add_patch(arrow) | ||
|
||
def get_swarm_spans(coll): | ||
""" | ||
|
@@ -147,6 +66,8 @@ def get_swarm_spans(coll): | |
except ValueError: | ||
return None | ||
|
||
|
||
|
||
def gapped_lines(data, x, y, | ||
type='mean_sd', | ||
offset=0.3, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
```{r} | ||
library(dplyr) | ||
library(ggplot2) | ||
df = filter(CO2, conc == '1000') | ||
ggplot(df, aes(x = Type, | ||
y = uptake, | ||
color = Treatment)) + | ||
geom_point() + | ||
ggtitle('CO2 conc = 1000 mL/L') + | ||
xlab('City') + ylab('CO2 uptake') | ||
``` | ||
|
||
|
||
```{r} | ||
library(reticulate) | ||
``` | ||
|
||
|
||
```{python} | ||
import matplotlib.pyplot as plt | ||
import dabest | ||
f1, results = dabest.plot(data=r.df, fig_size=(5,7), | ||
x='Type', y='uptake', | ||
swarm_label='CO2 uptake', | ||
color_col='Treatment', | ||
idx=['Quebec', 'Mississippi'] | ||
) | ||
f1.savefig('dabest-plot-CO2.png', bbox_inches='tight') | ||
``` | ||
|
||
```{r} | ||
py_results = py$results | ||
mean_diff = py_results$stat_summary | ||
ci_low = py_results$bca_ci_low | ||
ci_high = py_results$bca_ci_high | ||
# Print results, with all numerical values formatted to 2 decimal places. | ||
sprintf("Mean Difference = %.2f [95CI %.2f, %.2f]", | ||
mean_diff, ci_low, ci_high) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% extends "!layout.html" %} | ||
|
||
{%- block extrahead %} | ||
{{ super() }} | ||
<!-- Global site tag (gtag.js) - Google Analytics --> | ||
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-120627927-1"></script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
|
||
gtag('config', 'UA-120627927-1'); | ||
</script> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.