Skip to content

Commit

Permalink
Merge b7750d6 into cf1093e
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmorrow committed Jan 3, 2019
2 parents cf1093e + b7750d6 commit 111fef1
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 50 deletions.
2 changes: 1 addition & 1 deletion sci_analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# from sci_analysis.analysis import analysis
# from sci_analysis.graphs import graph
# from sci_analysis.data import data
__all__ = ["data", "analysis", "graph"]
__all__ = ["data", "analysis", "graphs"]
from .analysis import analyze, analyse
# from .analysis.analysis import Comparison, NormTest, TTest, LinearRegression,\
# Correlation, Anova, Kruskal, EqualVariance, VectorStatistics, GroupStatistics
19 changes: 11 additions & 8 deletions sci_analysis/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,19 @@ def analyze(xdata, ydata=None, groups=None, labels=None, alpha=0.05, **kwargs):
tested.append('Distribution')

# Show the histogram and stats
if 'sample' in kwargs:
out_stats = VectorStatistics(_data, sample=kwargs['sample'], display=False)
else:
out_stats = VectorStatistics(_data, display=False)
out_stats = VectorStatistics(_data, sample=kwargs.get('sample', False), display=False)
if 'distribution' in kwargs:
distro = kwargs['distribution']
distro_class = getattr(__import__('scipy.stats',
globals(),
locals(),
[distro], 0), distro)
distro_class = getattr(
__import__(
'scipy.stats',
globals(),
locals(),
[distro],
0,
),
distro,
)
parms = distro_class.fit(xdata)
fit = KSTest(xdata, distribution=distro, parms=parms, alpha=alpha, display=False)
tested.append('KSTest')
Expand Down
2 changes: 1 addition & 1 deletion sci_analysis/analysis/hypo_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def run(self):
args = self._data.groups.values()
if len(args) <= 1:
raise NoDataError("At least one of the inputs is empty or non-numeric.")
u_value, p_value = mannwhitneyu(*args)
u_value, p_value = mannwhitneyu(*args, alternative='less')
self._results.update({self._statistic_name: u_value, 'p value': p_value * 2, 'alpha': self._alpha})

@property
Expand Down
4 changes: 2 additions & 2 deletions sci_analysis/analysis/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class GroupStatistics(Analysis):
_num_of_groups = 'Number of Groups'

def __init__(self, *args, **kwargs):
groups = kwargs['groups'] if 'groups' in kwargs else None
display = kwargs['display'] if 'display' in kwargs else True
groups = kwargs.get('groups', None)
display = kwargs.get('display', False)
if is_dict(args[0]):
_data, = args
elif is_group(args,):
Expand Down
44 changes: 23 additions & 21 deletions sci_analysis/graphs/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,18 @@ def __init__(self, data, **kwargs):
:param _save_to: Save the graph to the specified path.
:return: pass
"""
self._bins = kwargs['bins'] if 'bins' in kwargs else 20
self._distribution = kwargs['distribution'] if 'distribution' in kwargs else 'norm'
self._box_plot = kwargs['boxplot'] if 'boxplot' in kwargs else True
self._cdf = kwargs['cdf'] if 'cdf' in kwargs else False
self._fit = kwargs['fit'] if 'fit' in kwargs else False
self._mean = kwargs['mean'] if 'mean' in kwargs else None
self._std = kwargs['std_dev'] if 'std_dev' in kwargs else None
self._sample = kwargs['sample'] if 'sample' in kwargs else True
self._title = kwargs['title'] if 'title' in kwargs else 'Distribution'
self._save_to = kwargs['save_to'] if 'save_to' in kwargs else None
yname = "Probability"
name = 'Data'
if 'name' in kwargs:
name = kwargs['name']
elif 'xname' in kwargs:
name = kwargs['xname']
self._bins = kwargs.get('bins', 20)
self._distribution = kwargs.get('distribution', 'norm')
self._box_plot = kwargs.get('boxplot', True)
self._cdf = kwargs.get('cdf', False)
self._fit = kwargs.get('fit', False)
self._mean = kwargs.get('mean')
self._std = kwargs.get('std_dev')
self._sample = kwargs.get('sample', False)
self._title = kwargs.get('title', 'Distribution')
self._save_to = kwargs.get('save_to')
yname = kwargs.get('yname', 'Probability')
name = kwargs.get('name') or kwargs.get('xname') or 'Data'

super(GraphHisto, self).__init__(data, xname=name, yname=yname)

Expand All @@ -110,10 +106,16 @@ def fit_distro(self):
Third value - The cdf y-axis points
"""
distro_class = getattr(__import__('scipy.stats',
globals(),
locals(),
[self._distribution], 0), self._distribution)
distro_class = getattr(
__import__(
'scipy.stats',
globals(),
locals(),
[self._distribution],
0,
),
self._distribution
)
parms = distro_class.fit(self._data.data)
distro = linspace(distro_class.ppf(0.001, *parms), distro_class.ppf(0.999, *parms), 100)
distro_pdf = distro_class.pdf(distro, *parms)
Expand Down Expand Up @@ -167,7 +169,7 @@ def draw(self):

# Set the title
title = self._title
if self._mean is not None and self._std is not None:
if self._mean and self._std:
if self._sample:
title = r"{}{}$\bar x = {:.4f}, s = {:.4f}$".format(title, "\n", self._mean, self._std)
else:
Expand Down
8 changes: 4 additions & 4 deletions sci_analysis/test/test_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ def test_124_distribution_label(self):
save_to='{}test_analyze_124'.format(self.save_path)),
['Distribution', 'NormTest'])

def test_125_distribution_population(self):
"""Perform a distribution analysis with population set"""
def test_125_distribution_sample(self):
"""Perform a distribution analysis with sample set"""
np.random.seed(self._seed)
input_array = st.norm.rvs(size=200)
self.assertEqual(analyze(input_array,
sample=False,
title='Population Stats',
sample=True,
title='Sample Stats',
debug=True,
save_to='{}test_analyze_125'.format(self.save_path)),
['Distribution', 'NormTest'])
Expand Down
2 changes: 1 addition & 1 deletion sci_analysis/test/test_graph_histo.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_114_mean_std_and_sample(self):
self.assertTrue(GraphHisto(input_array,
mean=mean,
std_dev=std,
sample=False,
sample=True,
save_to='{}test_histo_114'.format(self.save_path)))

def test_115_distribution(self):
Expand Down
24 changes: 12 additions & 12 deletions sci_analysis/test/test_mannwhitney.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def test_MannWhitney_matched(self):
-------------------
alpha = 0.0500
u value = 4976.0000
p value = 0.9542
u value = 5024.0000
p value = 1.0477
H0: Locations are matched
"""
self.assertGreater(exp.p_value, alpha, "FAIL: MannWhitney Type I error")
self.assertAlmostEqual(exp.statistic, 4976.0, delta=0.0001, msg="FAIL: MannWhitney statistic incorrect")
self.assertAlmostEqual(exp.u_value, 4976.0, delta=0.0001, msg="FAIL: MannWhitney u_value incorrect")
self.assertAlmostEqual(exp.p_value, 0.9542, delta=0.0001, msg="FAIL: MannWhitney p_value incorrect")
self.assertAlmostEqual(exp.statistic, 5024.0, delta=0.0001, msg="FAIL: MannWhitney statistic incorrect")
self.assertAlmostEqual(exp.u_value, 5024.0, delta=0.0001, msg="FAIL: MannWhitney u_value incorrect")
self.assertAlmostEqual(exp.p_value, 1.0477, delta=0.0001, msg="FAIL: MannWhitney p_value incorrect")
self.assertEqual(str(exp), output)

def test_MannWhitney_unmatched(self):
Expand Down Expand Up @@ -75,8 +75,8 @@ def test_MannWhitney_matched_just_above_min_size(self):
-------------------
alpha = 0.0500
u value = 219.0000
p value = 0.9799
u value = 222.0000
p value = 1.0401
H0: Locations are matched
"""
Expand Down Expand Up @@ -144,15 +144,15 @@ def test_MannWhitney_vector_input(self):
-------------------
alpha = 0.0500
u value = 4976.0000
p value = 0.9542
u value = 5024.0000
p value = 1.0477
H0: Locations are matched
"""
self.assertGreater(exp.p_value, alpha, "FAIL: MannWhitney Type I error")
self.assertAlmostEqual(exp.statistic, 4976.0, delta=0.0001, msg="FAIL: MannWhitney statistic incorrect")
self.assertAlmostEqual(exp.u_value, 4976.0, delta=0.0001, msg="FAIL: MannWhitney u_value incorrect")
self.assertAlmostEqual(exp.p_value, 0.9542, delta=0.0001, msg="FAIL: MannWhitney p_value incorrect")
self.assertAlmostEqual(exp.statistic, 5024.0, delta=0.0001, msg="FAIL: MannWhitney statistic incorrect")
self.assertAlmostEqual(exp.u_value, 5024.0, delta=0.0001, msg="FAIL: MannWhitney u_value incorrect")
self.assertAlmostEqual(exp.p_value, 1.0477, delta=0.0001, msg="FAIL: MannWhitney p_value incorrect")
self.assertEqual(str(exp), output)

def test_MannWhitney_missing_second_arg(self):
Expand Down

0 comments on commit 111fef1

Please sign in to comment.