Skip to content

Commit

Permalink
Merge 2bdcab3 into 388d017
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmorrow committed Apr 6, 2019
2 parents 388d017 + 2bdcab3 commit fa27b8e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
30 changes: 22 additions & 8 deletions sci_analysis/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .stats import VectorStatistics, GroupStatistics, GroupStatisticsStacked, CategoricalStatistics


def determine_analysis_type(data, other=None, groups=None, labels=None):
def determine_analysis_type(data, other=None, groups=None, labels=None, order=None, dropna=None):
"""Attempts to determine the type of data and returns the corresponding sci_analysis Data object.
Parameters
Expand All @@ -21,6 +21,10 @@ def determine_analysis_type(data, other=None, groups=None, labels=None):
The group names to include if data is determined to be a Vector.
labels : array-like or None
The sequence of data point labels.
order : array-like
The order that categories in sequence should appear.
dropna : bool
Remove all occurances of numpy NaN.
Returns
-------
Expand Down Expand Up @@ -61,10 +65,10 @@ def determine_analysis_type(data, other=None, groups=None, labels=None):
else:
return Vector(data, labels=labels)
else:
return Categorical(data)
return Categorical(data, order=order, dropna=dropna)


def analyse(xdata, ydata=None, groups=None, labels=None, **kwargs):
def analyse(xdata, ydata=None, groups=None, labels=None, alpha=0.05, order=None, dropna=None, **kwargs):
"""
Alias for analyze.
Expand All @@ -80,6 +84,10 @@ def analyse(xdata, ydata=None, groups=None, labels=None, **kwargs):
The sequence of data point labels.
alpha : float
The sensitivity to use for hypothesis tests.
order : array-like
The order that categories in sequence should appear.
dropna : bool
Remove all occurances of numpy NaN.
Returns
-------
Expand All @@ -97,10 +105,10 @@ def analyse(xdata, ydata=None, groups=None, labels=None, **kwargs):
xdata : dict(array-like(num)), ydata : None --- Location Test(unstacked)
xdata : array-like(num), ydata : None, groups : array-like --- Location Test(stacked)
"""
return analyze(xdata, ydata=ydata, groups=groups, labels=labels, **kwargs)
return analyze(xdata, ydata=ydata, groups=groups, labels=labels, alpha=alpha, order=order, dropna=dropna, **kwargs)


def analyze(xdata, ydata=None, groups=None, labels=None, alpha=0.05, **kwargs):
def analyze(xdata, ydata=None, groups=None, labels=None, alpha=0.05, order=None, dropna=None, **kwargs):
"""
Automatically performs a statistical analysis based on the input arguments.
Expand All @@ -116,6 +124,10 @@ def analyze(xdata, ydata=None, groups=None, labels=None, alpha=0.05, **kwargs):
The sequence of data point labels.
alpha : float
The sensitivity to use for hypothesis tests.
order : array-like
The order that categories in sequence should appear.
dropna : bool
Remove all occurances of numpy NaN.
Returns
-------
Expand Down Expand Up @@ -190,9 +202,9 @@ def analyze(xdata, ydata=None, groups=None, labels=None, alpha=0.05, **kwargs):
return tested if debug else None

if ydata is not None:
_data = determine_analysis_type(xdata, other=ydata, groups=groups, labels=labels)
_data = determine_analysis_type(xdata, other=ydata, groups=groups, labels=labels, order=order, dropna=dropna)
else:
_data = determine_analysis_type(xdata, groups=groups, labels=labels)
_data = determine_analysis_type(xdata, groups=groups, labels=labels, order=order, dropna=dropna)

if is_vector(_data) and not _data.other.empty:
# Correlation and Linear Regression
Expand Down Expand Up @@ -273,8 +285,10 @@ def analyze(xdata, ydata=None, groups=None, labels=None, alpha=0.05, **kwargs):
return tested if debug else None
else:
tested.append('Frequencies')
if labels is None:
labels = True

# Show the histogram and stats
GraphFrequency(_data, **kwargs)
GraphFrequency(_data, labels=labels, **kwargs)
CategoricalStatistics(xdata, **kwargs)
return tested if debug else None
27 changes: 27 additions & 0 deletions sci_analysis/test/test_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,33 @@ def test_142_stacked_oneway_missing_groups(self):
save_to='{}test_analyze_142'.format(self.save_path)),
['Stacked Oneway', 'TTest'])

def test_143_categorical_ordered(self):
input_array = ['one', 'two', 'one', 'three', 'one', 'three', 'three', 'one']
self.assertEqual(analyze(
input_array,
order=['one', 'two', 'three'],
debug=True,
save_to='{}test_analyze_143'.format(self.save_path)
), ['Frequencies'])

def test_144_categorical_no_labels(self):
input_array = ['one', 'two', 'one', 'three', 'one', 'three', 'three', 'one']
self.assertEqual(analyze(
input_array,
labels=False,
debug=True,
save_to='{}test_analyze_144'.format(self.save_path)
), ['Frequencies'])

def test_145_categorical_with_grid(self):
input_array = ['one', 'two', 'one', 'three', 'one', 'three', 'three', 'one']
self.assertEqual(analyze(
input_array,
grid=True,
debug=True,
save_to='{}test_analyze_145'.format(self.save_path)
), ['Frequencies'])


if __name__ == '__main__':
unittest.main()

0 comments on commit fa27b8e

Please sign in to comment.