Exemplo n.º 1
0
    def combine(self, p_values, ref_p_values=None):
        """
        Takes a list of p_values and combines them into a single p_value by choosing the p_value of the first feature.
        :param p_values: a list of p_values of features.
        :param ref_p_values: p-values of reference observations (if needed).
        :return: The combined p-value.
        """

        p_values = check_p_values(p_values)

        # check that the given position of the feature is valid
        if self.feature_position < 0 or self.feature_position >= p_values.shape[
                1]:
            raise ValueError(
                'The given feature position is invalid! The position should be in [0, %i)'
                % len(p_values))

        # # assert p_values is a list
        # assert type(p_values) == list
        #
        # # check that p_values is not empty
        # if len(p_values) == 0:
        #     raise ValueError('The given list of p_values is empty')
        #
        # # check that all elements in p_values are floats
        # if not all(isinstance(x, (int, float)) for x in p_values):
        #     raise ValueError('The elements in p_values should all be of the type \'float\'')

        combined_p_values = np.take(p_values, self.feature_position, axis=1)

        return combined_p_values
Exemplo n.º 2
0
    def combine(self, p_values, ref_p_values=None):
        """
        Takes a list of p_values and combines them into a single p_value by calculating the average.
        :param p_values: a list of p_values of features.
        :param ref_p_values: p-values of reference observations (if needed).
        :return: The combined p-value.
        """

        p_values = check_p_values(p_values)

        # if type(p_values) == list:
        #    p_values = np.array([p_values])
        # assert p_values is a list
        # assert type(p_values) == list

        # check that p_values is not empty
        # if len(p_values) == 0:
        #    raise ValueError('The given list of p_values is empty')

        # check that all elements in p_values are floats
        # if not all(isinstance(x, (int, float)) for x in p_values):
        #    raise ValueError('The elements in p_values should all be of the type \'float\'')

        combined_p_values = np.mean(p_values, axis=1)

        return combined_p_values
Exemplo n.º 3
0
    def combine(self, p_values, ref_p_values=None):
        """
        Takes a list of p_values and combines them into a single p_value using the Stouffer’s Z-score method.
        :param p_values: a list of p_values of features.
        :param ref_p_values: p-values of reference observations (if needed).
        :return: The combined p-value.
        """

        p_values = check_p_values(p_values)

        # # assert p_values is a list
        # assert type(p_values) == list
        #
        # # check that p_values is not empty
        # if len(p_values) == 0:
        #     raise ValueError('The given list of p_values is empty')
        #
        # # check that all elements in p_values are floats
        # if not all(isinstance(x, (int, float)) for x in p_values):
        #     raise ValueError('The elements in p_values should all be of the type \'float\'')

        combined_p_values = np.apply_along_axis(lambda x: combine_pvalues(x, method='stouffer')[1], axis=1,
                                                arr=p_values)

        return combined_p_values
Exemplo n.º 4
0
    def combine(self, p_values, ref_p_values=None):
        """
        Takes a list of p_values and combines them into a single p_value by calculating the average.
        :param p_values: a list of p_values of features.
        :param ref_p_values: p-values of reference observations.
        :return: The combined p-value.
        """
        ### INPUT VALIDATION

        p_values = check_p_values(p_values)

        # # assert p_values is a list
        # assert type(p_values) == list
        #
        # # check that p_values is not empty
        # if len(p_values) == 0:
        #     raise ValueError('The given list of p_values is empty')
        #
        # # check that all elements in p_values are floats
        # if not all(isinstance(x, (int, float)) for x in p_values):
        #     raise ValueError('The elements in p_values should all be of the type \'float\'')

        # check that ref_p_values are given
        if ref_p_values is None:
            raise ValueError('The empirical combiner needs reference p values to calculate the combined p value!')

        # assert ref_p_values is a ndarray
        assert type(ref_p_values) == np.ndarray

        # check that the reference p_values of each reference observation are all floats (or integers)
        for ref in ref_p_values:
            if not all(isinstance(x, (int, float)) for x in ref):
                raise ValueError('The p_values of each reference observation should all be of the type \'float\'')

        ### FUNCTION CODE

        min_ref_p_values = ref_p_values.min(axis=1)

        combined_p_values = np.apply_along_axis(
            lambda x: self.empirical(min(x), min_ref_p_values, weights=np.ones(len(min_ref_p_values)),
                                     direction=self.direction), axis=1, arr=p_values)

        return combined_p_values