Exemple #1
0
def chi2_contingency(observed):
    '''
    Chi-square test of independence of variables in a contingency table.

    This function computes the chi-square statistic and p-value for the hypothesis test of 
    independence of the observed frequencies in the contingency table observed.
    
    :param observed: (*array_like*) The contingency table. The table contains the observed 
        frequencies (i.e. number of occurrences) in each category. In the two-dimensional case, 
        the table is often described as an `R x C table`.
    
    :returns: Chi-square statistic and p-value
    '''
    if isinstance(observed, list):
        observed = MIArray(ArrayUtil.array(observed))
    r = StatsUtil.chiSquareTest(observed.asarray())
    return r[0], r[1]
Exemple #2
0
def chi2_contingency(observed):
    '''
    Chi-square test of independence of variables in a contingency table.

    This function computes the chi-square statistic and p-value for the hypothesis test of 
    independence of the observed frequencies in the contingency table observed.
    
    :param observed: (*array_like*) The contingency table. The table contains the observed 
        frequencies (i.e. number of occurrences) in each category. In the two-dimensional case, 
        the table is often described as an `R x C table`.
    
    :returns: Chi-square statistic and p-value
    '''
    if isinstance(observed, list):
        observed = MIArray(ArrayUtil.array(observed))
    r = StatsUtil.chiSquareTest(observed.asarray())
    return r[0], r[1]
Exemple #3
0
def chisquare(f_obs, f_exp=None):
    '''
    Calculates a one-way chi square test.

    The chi square test tests the null hypothesis that the categorical data has the 
    given frequencies.
    
    :param f_obs: (*array_like*) Observed frequencies in each category.
    :param f_exp: (*array_like*) Expected frequencies in each category. By default the categories 
        are assumed to be equally likely.
    
    :returns: Chi-square statistic and p-value
    '''
    if isinstance(f_obs, list):
        f_obs = MIArray(ArrayUtil.array(f_obs))
    if f_exp is None:
        n = len(f_obs)
        f_exp = minum.ones(n) / n * f_obs.sum()
    elif isinstance(f_exp, list):
        f_exp = MIArray(ArrayUtil.array(f_exp))
    r = StatsUtil.chiSquareTest(f_exp.asarray(), f_obs.asarray())
    return r[0], r[1]
Exemple #4
0
def chisquare(f_obs, f_exp=None):
    '''
    Calculates a one-way chi square test.

    The chi square test tests the null hypothesis that the categorical data has the 
    given frequencies.
    
    :param f_obs: (*array_like*) Observed frequencies in each category.
    :param f_exp: (*array_like*) Expected frequencies in each category. By default the categories 
        are assumed to be equally likely.
    
    :returns: Chi-square statistic and p-value
    '''
    if isinstance(f_obs, list):
        f_obs = MIArray(ArrayUtil.array(f_obs))
    if f_exp is None:
        n = len(f_obs)
        f_exp = minum.ones(n) / n * f_obs.sum()
    elif isinstance(f_exp, list):
        f_exp = MIArray(ArrayUtil.array(f_exp))
    r = StatsUtil.chiSquareTest(f_exp.asarray(), f_obs.asarray())
    return r[0], r[1]