Skip to content

Commit

Permalink
Adding appropriate imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mortonjt committed Jul 28, 2016
1 parent 9d8e5bf commit c378361
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 13 additions & 1 deletion gneiss/_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# The full license is in the file COPYING.txt, distributed with this software.
# ----------------------------------------------------------------------------
import pandas as pd
from skbio.stats.composition import ilr_inv


class RegressionResults():
Expand Down Expand Up @@ -63,7 +64,9 @@ def _check_projection(self, project):
Parameters
----------
project : bool
Specifies if a projection into the Aitchison simplex can be performed.
Specifies if a projection into the Aitchison simplex can be
performed.
Raises
------
ValueError:
Expand Down Expand Up @@ -97,6 +100,15 @@ def coefficients(self, project=False):
A table of values where columns are coefficients, and the index
is either balances or proportions, depending on the value of
`project`.
Raises
------
ValueError:
Cannot perform projection into Aitchison simplex if `basis`
is not specified.
ValueError:
Cannot perform projection into Aitchison simplex
if `feature_names` is not specified.
"""
self._check_projection(project)
coef = pd.DataFrame()
Expand Down
13 changes: 8 additions & 5 deletions gneiss/tests/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
# ----------------------------------------------------------------------------
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import statsmodels.formula.api as smf
import unittest
from gneiss._summary import RegressionResults
from skbio.stats.composition import _gram_schmidt_basis, ilr_inv


class TestRegressionResults(unittest.TestCase):
Expand Down Expand Up @@ -75,18 +77,19 @@ def test_check_projection(self):
res._check_projection(True)

def test_regression_results_coefficient(self):
exp_coef = pd.DataFrame({'Intercept' : [1.447368, -0.052632],
'X' : [0.539474, 1.289474]},
exp_coef = pd.DataFrame({'Intercept': [1.447368, -0.052632],
'X': [0.539474, 1.289474]},
index=['Y1', 'Y2'])
res = RegressionResults(self.results)
pdt.assert_frame_equal(res.coefficients(), exp_coef,
check_exact=False,
check_less_precise=True)

def test_regression_results_coefficient_projection(self):
exp_coef = pd.DataFrame({'Intercept' : ilr_inv(np.array([[1.447368, -0.052632]])),
'X' : ilr_inv(np.array([[0.539474, 1.289474]]))},
index=['Z1', 'Z2', 'Z3'])
exp_coef = pd.DataFrame(
{'Intercept': ilr_inv(np.array([[1.447368, -0.052632]])),
'X': ilr_inv(np.array([[0.539474, 1.289474]]))},
index=['Z1', 'Z2', 'Z3'])
feature_names = ['Z1', 'Z2', 'Z3']
basis = _gram_schmidt_basis(3)
res = RegressionResults(self.results, basis=basis,
Expand Down

0 comments on commit c378361

Please sign in to comment.