'Test the hand-computed example in factor.demean.'

def test_normalizations_hand_computed(self):

    f = self.f
    m = Mask()
    c = C()
    str_c = C(dtype=categorical_dtype, missing_value=None)
    factor_data = array([[1.0, 2.0, 3.0, 4.0], [1.5, 2.5, 3.5, 1.0], [2.0, 3.0, 4.0, 1.5], [2.5, 3.5, 1.0, 2.0]])
    filter_data = array([[False, True, True, True], [True, False, True, True], [True, True, False, True], [True, True, True, False]], dtype=bool)
    classifier_data = array([[1, 1, 2, 2], [1, 1, 2, 2], [1, 1, 2, 2], [1, 1, 2, 2]], dtype=int64_dtype)
    string_classifier_data = LabelArray(classifier_data.astype(str).astype(object), missing_value=None)
    terms = {'vanilla': f.demean(), 'masked': f.demean(mask=m), 'grouped': f.demean(groupby=c), 'grouped_str': f.demean(groupby=str_c), 'grouped_masked': f.demean(mask=m, groupby=c), 'grouped_masked_str': f.demean(mask=m, groupby=str_c)}
    expected = {'vanilla': array([[(-1.5), (-0.5), 0.5, 1.5], [(-0.625), 0.375, 1.375, (-1.125)], [(-0.625), 0.375, 1.375, (-1.125)], [0.25, 1.25, (-1.25), (-0.25)]]), 'masked': array([[nan, (-1.0), 0.0, 1.0], [(-0.5), nan, 1.5, (-1.0)], [(-0.166), 0.833, nan, (-0.666)], [0.166, 1.166, (-1.333), nan]]), 'grouped': array([[(-0.5), 0.5, (-0.5), 0.5], [(-0.5), 0.5, 1.25, (-1.25)], [(-0.5), 0.5, 1.25, (-1.25)], [(-0.5), 0.5, (-0.5), 0.5]]), 'grouped_masked': array([[nan, 0.0, (-0.5), 0.5], [0.0, nan, 1.25, (-1.25)], [(-0.5), 0.5, nan, 0.0], [(-0.5), 0.5, 0.0, nan]])}
    expected['grouped_str'] = expected['grouped']
    expected['grouped_masked_str'] = expected['grouped_masked']
    self.check_terms(terms, expected, initial_workspace={f: factor_data, c: classifier_data, str_c: string_classifier_data, m: filter_data}, mask=self.build_mask(self.ones_mask(shape=factor_data.shape)), check=partial(check_allclose, atol=0.001))
