示例#1
0
    def test_procrustes_bad_dimensions(self):

        self.other.samples = self.other.samples.iloc[:, :4]
        self.other.eigvals = self.other.eigvals[:4]
        self.other.proportion_explained = self.other.proportion_explained[:4]

        with self.assertRaisesRegex(ValueError, 'The matrices cannot be '):
            procrustes_analysis(self.reference, self.other)
示例#2
0
    def test_procrustes_bad_dimensions(self):

        self.other.samples = self.other.samples.iloc[:, :4]
        self.other.eigvals = self.other.eigvals[:4]
        self.other.proportion_explained = self.other.proportion_explained[:4]

        with self.assertRaisesRegex(ValueError, 'The matrices cannot be '):
            procrustes_analysis(self.reference, self.other)
示例#3
0
    def test_non_zero_p(self):
        # generated with np.random.seed(3); np.random.randn(4, 6)
        noise = np.array([[
            1.78862847, 0.43650985, 0.09649747, -1.8634927, -0.2773882,
            -0.35475898
        ],
                          [
                              -0.08274148, -0.62700068, -0.04381817,
                              -0.47721803, -1.31386475, 0.88462238
                          ],
                          [
                              0.88131804, 1.70957306, 0.05003364, -0.40467741,
                              -0.54535995, -1.54647732
                          ],
                          [
                              0.98236743, -1.10106763, -1.18504653, -0.2056499,
                              1.48614836, 0.23671627
                          ]])
        self.other.samples += noise

        ref, other, m2_results = procrustes_analysis(self.reference,
                                                     self.other)

        true_m2 = m2_results['true M^2 value'][0]
        true_p_value = m2_results['p-value for true M^2 value'][0]

        skbio.util.assert_ordination_results_equal(ref, self.expected_ref)
        skbio.util.assert_ordination_results_equal(other, self.expected_noise)

        # the p value shouldn't be zero even in the presence of noise
        self.assertAlmostEqual(true_m2, 0.7388121)
        self.assertNotAlmostEqual(true_p_value, 0.001)
示例#4
0
    def test_procrustes(self):
        ref, other, m2_results = procrustes_analysis(self.reference,
                                                     self.other)
        true_m2 = m2_results['true M^2 value'][0]
        true_p_value = m2_results['p-value for true M^2 value'][0]

        skbio.util.assert_ordination_results_equal(ref, self.expected_ref)
        skbio.util.assert_ordination_results_equal(other, self.expected_other)

        self.assertAlmostEqual(true_m2, self.expected_m2)
        self.assertNotAlmostEqual(true_p_value, self.expected_p)
示例#5
0
    def test_zero_permutations_nan_pvalue(self):
        ref, other, m2_results = procrustes_analysis(self.reference,
                                                     self.other,
                                                     permutations='disable')
        true_m2 = m2_results['true M^2 value'][0]
        true_p_value = m2_results['p-value for true M^2 value'][0]

        skbio.util.assert_ordination_results_equal(ref, self.expected_ref)
        skbio.util.assert_ordination_results_equal(other, self.expected_other)

        self.assertAlmostEqual(true_m2, self.expected_m2)
        self.assertTrue(np.isnan(true_p_value))
示例#6
0
    def test_procrustes_id_mismatch(self):
        msg = 'The ordinations represent two different sets of samples'
        self.other.samples.index = pd.Index([':L', ':D', ':)', ':('])
        with self.assertRaisesRegex(ValueError, msg):
            procrustes_analysis(self.reference, self.other)

        self.other.samples.index = pd.Index([':L', 'B', 'C', 'D'])
        with self.assertRaisesRegex(ValueError, msg):
            procrustes_analysis(self.reference, self.other)

        self.other.samples.index = pd.Index(['a', 'b', 'c', 'd'])
        with self.assertRaisesRegex(ValueError, msg):
            procrustes_analysis(self.reference, self.other)
示例#7
0
    def test_procrustes_id_mismatch(self):
        msg = 'The ordinations represent two different sets of samples'
        self.other.samples.index = pd.Index([':L', ':D', ':)', ':('])
        with self.assertRaisesRegex(ValueError, msg):
            procrustes_analysis(self.reference, self.other)

        self.other.samples.index = pd.Index([':L', 'B', 'C', 'D'])
        with self.assertRaisesRegex(ValueError, msg):
            procrustes_analysis(self.reference, self.other)

        self.other.samples.index = pd.Index(['a', 'b', 'c', 'd'])
        with self.assertRaisesRegex(ValueError, msg):
            procrustes_analysis(self.reference, self.other)
示例#8
0
 def test_procrustes_over_dimensions(self):
     with self.assertRaisesRegex(ValueError, 'Cannot fit fewer dimensions '
                                 'than available'):
         procrustes_analysis(self.reference, self.other, 11)
示例#9
0
    def test_procrustes(self):
        ref, other = procrustes_analysis(self.reference, self.other)

        skbio.util.assert_ordination_results_equal(ref, self.expected_ref)
        skbio.util.assert_ordination_results_equal(other, self.expected_other)
示例#10
0
 def test_procrustes_over_dimensions(self):
     with self.assertRaisesRegex(ValueError, 'Cannot fit fewer dimensions '
                                 'than available'):
         procrustes_analysis(self.reference, self.other, 11)
示例#11
0
    def test_procrustes(self):
        ref, other = procrustes_analysis(self.reference, self.other)

        skbio.util.assert_ordination_results_equal(ref, self.expected_ref)
        skbio.util.assert_ordination_results_equal(other, self.expected_other)