Module Expr Str Import alias identifier ClassDef bases NameLoad body FunctionDef arguments args NameParam defaults kwarg body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign TupleStore NameStore NameStore TupleLoad NameLoad NameLoad Assign NameStore Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore BinOpSub NameLoad NameLoad Assign NameStore Call NameLoad keyword NameLoad keyword NameLoad keyword NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults NameLoad NameLoad body Expr Str If BoolOpOr NameLoad NameLoad body Assign NameStore BinOpSub NameLoad Call AttributeLoad NameLoad attr Num Assign NameStore BinOpSub NameLoad Call AttributeLoad NameLoad attr Num If NameLoad body AugAssignDiv NameStore Call AttributeLoad NameLoad attr Num AugAssignDiv NameStore Call AttributeLoad NameLoad attr Num Assign NameStore Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad attr NameLoad Assign NameStore Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Expr Call AttributeLoad NameLoad attr Return SubscriptLoad NameLoad Slice Num decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults NameLoad NameLoad body Expr Str ImportFrom alias Assign TupleStore NameStore NameStore AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore AttributeLoad NameLoad attr Assign NameStore Call NameLoad NameLoad NameLoad keyword NameLoad Assign NameStore BinOpMult NameLoad NameLoad If NameLoad body Assign NameStore BinOpAdd Call AttributeLoad NameLoad attr BinOpSub NameLoad NameLoad Num Assign NameStore BinOpMult NameLoad SubscriptLoad NameLoad Index Num Assign NameStore BinOpMult NameLoad BinOpDiv SubscriptLoad NameLoad Index Num BinOpSub Num SubscriptLoad NameLoad Index Num Return TupleLoad NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad NameLoad NameLoad NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad orelse Assign NameStore SubscriptLoad Call AttributeLoad NameLoad attr Call NameLoad NameLoad NameLoad Slice Num Assign NameStore BinOpMult BinOpSub NameLoad NameLoad BinOpSub NameLoad NameLoad Assign NameStore BinOpMult NameLoad Call AttributeLoad SubscriptLoad NameLoad Slice Num attr Assign NameStore BinOpMult NameLoad Call AttributeLoad SubscriptLoad BinOpDiv NameLoad BinOpSub Num NameLoad Slice Num attr Return TupleLoad NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad NameLoad NameLoad NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Expr Str Assign TupleStore NameStore NameStore AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore AttributeLoad NameLoad attr Assign NameStore Call NameLoad NameLoad NameLoad keyword NameLoad Assign NameStore BinOpPow NameLoad Num Assign NameStore BinOpDiv NameLoad BinOpSub Num NameLoad Assign NameStore BinOpMult NameLoad NameLoad Assign NameStore BinOpMult NameLoad BinOpSub BinOpSub NameLoad NameLoad NameLoad Assign NameStore Call NameLoad NameLoad NameLoad Assign NameStore BinOpMult Num BinOpSub NameLoad NameLoad Assign NameStore BinOpMult Num BinOpSub BinOpSub NameLoad NameLoad Num Assign NameStore BinOpMult NameLoad NameLoad Assign NameStore NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr BinOpDiv Num BinOpAdd Num NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Dict Assign SubscriptStore NameLoad Index Str NameLoad Assign SubscriptStore NameLoad Index Str NameLoad Assign SubscriptStore NameLoad Index Str NameLoad Assign SubscriptStore NameLoad Index Str NameLoad Assign SubscriptStore NameLoad Index Str NameLoad Assign SubscriptStore NameLoad Index Str NameLoad Assign SubscriptStore NameLoad Index Str NameLoad Assign SubscriptStore NameLoad Index Str NameLoad Return NameLoad decorator_list
N/A N/A Tools for multivariate analysis


Author : Josef Perktold
License : BSD-3



TODO:

- names of functions, currently just "working titles"

 N/A numpy np Bunch N/A dict N/A __init__ N/A N/A self N/A kw N/A N/A N/A N/A dict __init__ self kw N/A N/A self __dict__ self N/A N/A partial_project N/A N/A endog exog N/A N/A N/A helper function to get linear projection or partialling out of variables

    endog variables are projected on exog variables

    Parameters
    ----------
    endog : ndarray
        array of variables where the effect of exog is partialled out.
    exog : ndarray
        array of variables on which the endog variables are projected.

    Returns
    -------
    res : instance of Bunch with

        - params : OLS parameter estimates from projection of endog on exog
        - fittedvalues : predicted values of endog given exog
        - resid : residual of the regression, values of endog with effect of
          exog partialled out

    Notes
    -----
    This is no-frills mainly for internal calculations, no error checking or
    array conversion is performed, at least for now.

     N/A N/A x1 x2 N/A endog exog N/A params N/A N/A N/A N/A N/A np linalg pinv x2 dot x1 N/A predicted N/A N/A x2 dot params N/A residual N/A x1 predicted N/A res N/A Bunch params params fittedvalues predicted resid residual N/A res N/A cancorr N/A N/A x1 x2 demean standardize N/A True False N/A N/A canonical correlation coefficient beween 2 arrays

    Parameters
    ----------
    x1, x2 : ndarrays, 2_D
        two 2-dimensional data arrays, observations in rows, variables in columns
    demean : bool
         If demean is true, then the mean is subtracted from each variable
    standardize : bool
         If standardize is true, then each variable is demeaned and divided by
         its standard deviation. Rescaling does not change the canonical
         correlation coefficients.

    Returns
    -------
    ccorr : ndarray, 1d
        canonical correlation coefficients, sorted from largest to smallest.
        Note, that these are the square root of the eigenvalues.

    Notes
    -----
    This is a helper function for other statistical functions. It only
    calculates the canonical correlation coefficients and does not do a full
    canoncial correlation analysis

    The canonical correlation coefficient is calculated with the generalized
    matrix inverse and does not raise an exception if one of the data arrays
    have less than full column rank.

    See Also
    --------
    cc_ranktest
    cc_stats
    CCA not yet

     N/A N/A demean standardize N/A N/A x1 N/A x1 N/A N/A x1 mean 0 N/A x2 N/A x2 N/A N/A x2 mean 0 N/A standardize N/A N/A x1 N/A N/A x1 std 0 N/A x2 N/A N/A x2 std 0 N/A t1 N/A N/A N/A N/A N/A np linalg pinv x1 dot x2 N/A t2 N/A N/A N/A N/A N/A np linalg pinv x2 dot x1 N/A m N/A N/A t1 dot t2 N/A cc N/A N/A np sqrt N/A N/A N/A np linalg eigvals m N/A N/A N/A cc sort N/A N/A cc N/A -1 N/A cc_ranktest N/A N/A x1 x2 demean fullrank N/A True False N/A N/A rank tests based on smallest canonical correlation coefficients

    Anderson canonical correlations test (LM test) and
    Cragg-Donald test (Wald test)
    Assumes homoskedasticity and independent observations, overrejects if
    there is heteroscedasticity or autocorrelation.

    The Null Hypothesis is that the rank is k - 1, the alternative hypothesis
    is that the rank is at least k.


    Parameters
    ----------
    x1, x2 : ndarrays, 2_D
        two 2-dimensional data arrays, observations in rows, variables in columns
    demean : bool
         If demean is true, then the mean is subtracted from each variable.
    fullrank : bool
         If true, then only the test that the matrix has full rank is returned.
         If false, the test for all possible ranks are returned. However, no
         the p-values are not corrected for the multiplicity of tests.

    Returns
    -------
    value : float
        value of the test statistic
    p-value : float
        p-value for the test Null Hypothesis tha the smallest canonical
        correlation coefficient is zero. based on chi-square distribution
    df : int
        degrees of freedom for thechi-square distribution in the hypothesis test
    ccorr : ndarray, 1d
        All canonical correlation coefficients sorted from largest to smallest.

    Notes
    -----
    Degrees of freedom for the distribution of the test statistic are based on
    number of columns of x1 and x2 and not on their matrix rank.
    (I'm not sure yet what the interpretation of the test is if x1 or x2 are of
    reduced rank.)

    See Also
    --------
    cancorr
    cc_stats

     scipy stats N/A N/A nobs1 k1 N/A x1 shape N/A N/A nobs2 k2 N/A x2 shape N/A cc N/A cancorr x1 x2 demean demean N/A cc2 N/A cc cc N/A fullrank N/A N/A df N/A N/A N/A np abs N/A k1 k2 1 N/A value N/A nobs1 N/A cc2 N/A -1 N/A w_value N/A nobs1 N/A N/A cc2 N/A -1 N/A 1.0 N/A cc2 N/A -1 N/A N/A value N/A N/A N/A stats chi2 sf value df df cc w_value N/A N/A N/A stats chi2 sf w_value df N/A N/A r N/A N/A N/A np arange N/A min k1 k2 N/A -1 N/A df N/A N/A k1 r N/A k2 r N/A values N/A nobs1 N/A N/A N/A cc2 N/A -1 cumsum N/A w_values N/A nobs1 N/A N/A N/A N/A cc2 N/A 1.0 cc2 N/A -1 cumsum N/A N/A values N/A N/A N/A stats chi2 sf values df df cc w_values N/A N/A N/A stats chi2 sf w_values df N/A cc_stats N/A N/A x1 x2 demean N/A True N/A N/A MANOVA statistics based on canonical correlation coefficient

    Calculates Pillai's Trace, Wilk's Lambda, Hotelling's Trace and
    Roy's Largest Root.

    Parameters
    ----------
    x1, x2 : ndarrays, 2_D
        two 2-dimensional data arrays, observations in rows, variables in columns
    demean : bool
         If demean is true, then the mean is subtracted from each variable.

    Returns
    -------
    res : dict
        Dictionary containing the test statistics.

    Notes
    -----

    same as `canon` in Stata

    missing: F-statistics and p-values

    TODO: should return a results class instead
    produces nans sometimes, singular, perfect correlation of x1, x2 ?

     N/A N/A nobs1 k1 N/A x1 shape N/A N/A nobs2 k2 N/A x2 shape N/A cc N/A cancorr x1 x2 demean demean N/A cc2 N/A cc 2 N/A lam N/A cc2 N/A 1 cc2 N/A df_model N/A k1 k2 N/A df_resid N/A k1 N/A N/A nobs1 k2 demean N/A s N/A min df_model k1 N/A m N/A 0.5 N/A df_model k1 N/A n N/A 0.5 N/A N/A df_resid k1 1 N/A df1 N/A k1 df_model N/A df2 k2 N/A pt_value N/A N/A cc2 sum N/A wl_value N/A N/A np product N/A 1 N/A 1 lam N/A ht_value N/A N/A lam sum N/A rm_value N/A N/A lam max N/A res N/A N/A N/A res N/A canonical correlation coefficient cc N/A N/A res N/A eigenvalues lam N/A N/A res N/A Pillai's Trace pt_value N/A N/A res N/A Wilk's Lambda wl_value N/A N/A res N/A Hotelling's Trace ht_value N/A N/A res N/A Roy's Largest Root rm_value N/A N/A res N/A df_resid df_resid N/A N/A res N/A df_m m N/A res N/A