ó
áp7]c           @   sˆ   d  Z  d d l m Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d l m
 Z
 m Z d	 Z d
 e f d „  ƒ  YZ d S(   s7   Multivariate analysis of variance

author: Yichuan Liu
iÿÿÿÿ(   t   divisionN(   t   Modeli   (   t   MultivariateTestResults(   t   _multivariate_ols_fit(   t   _multivariate_ols_testt   _hypotheses_docs   restructuredtext ent   MANOVAc           B   sC   e  Z d  Z d d d „ Z d „  Z d d „ Z d e d e _ RS(   sB  
    Multivariate analysis of variance

    The implementation of MANOVA is based on multivariate regression and does
    not assume that the explanatory variables are categorical. Any type of
    variables as in regression is allowed.

    Parameters
    ----------
    endog : array_like
        Dependent variables. A nobs x k_endog array where nobs is
        the number of observations and k_endog is the number of dependent
        variables.
    exog : array_like
        Independent variables. A nobs x k_exog array where nobs is the
        number of observations and k_exog is the number of independent
        variables. An intercept is not included by default and should be added
        by the user. Models specified using a formula include an intercept by
        default.

    Attributes
    ----------
    endog : array
        See Parameters.
    exog : array
        See Parameters.

    Notes
    -----
    MANOVA is used though the `mv_test` function, and `fit` is not used.

    The ``from_formula`` interface is the recommended method to specify
    a model and simplifies testing without needing to manually configure
    the contrast matrices.

    References
    ----------
    .. [*] ftp://public.dhe.ibm.com/software/analytics/spss/documentation/statistics/20.0/en/client/Manuals/IBM_SPSS_Statistics_Algorithms.pdf
    t   nonec         K   s{   t  | j ƒ d k s( | j d d k r7 t d ƒ ‚ n  t t |  ƒ j | | d | d | | t |  j |  j ƒ |  _	 d  S(   Ni   s=   There must be more than one dependent variable to fit MANOVA!t   missingt   hasconst(
   t   lent   shapet
   ValueErrort   superR   t   __init__R   t   endogt   exogt
   _fittedmod(   t   selfR   R   R   R	   t   kwargs(    (    s>   lib/python2.7/site-packages/statsmodels/multivariate/manova.pyR   ;   s
    (
c         C   s   t  d ƒ ‚ d  S(   NsK   fit is not needed to use MANOVA. Callmv_test directly on a MANOVA instance.(   t   NotImplementedError(   R   (    (    s>   lib/python2.7/site-packages/statsmodels/multivariate/manova.pyt   fitC   s    c   	      C   sU  | d  k r!t |  d ƒ r¨ |  j d  k	 r¨ t |  j d ƒ r¨ |  j j j } g  } xÊ | D]I } t j |  j j d ƒ | | d  d  … f } | j	 | | d  g ƒ qX Wq!g  } xp t
 |  j j d ƒ D]U } d | } t j d |  j j d g ƒ } d | d | f <| j	 | | d  g ƒ qÅ Wn  t | |  j |  j |  j ƒ } t | |  j |  j ƒ S(   Nt   datat   design_infoi   s   x%di    (   t   Nonet   hasattrR   R   t   term_name_slicest   npt   eyeR   R   t   appendt   ranget   zerosR   R   t
   exog_namest   endog_namesR   (	   R   t
   hypothesest   termst   keyt
   L_contrastt   it   namet   Lt   results(    (    s>   lib/python2.7/site-packages/statsmodels/multivariate/manova.pyt   mv_testG   s$    -
s2   
Linear hypotheses testing

Parameters
----------
s  

Returns
-------
results: MultivariateTestResults

Notes
-----
Testing the linear hypotheses

    L * params * M = 0

where `params` is the regression coefficient matrix for the
linear model y = x * params

If the model is not specified using the formula interfact, then the hypotheses
test each included exogenous variable, one at a time. In most applications
with categorical variables, the ``from_formula`` interface should be preferred
when specifying a model since it provides knowledge about the model when
specifying the hypotheses.
N(   t   __name__t
   __module__t   __doc__R   R   R   R*   R   (    (    (    s>   lib/python2.7/site-packages/statsmodels/multivariate/manova.pyR      s   '	(   R-   t
   __future__R    t   numpyR   t   statsmodels.base.modelR   t   multivariate_olsR   R   R   R   t   __docformat__R   (    (    (    s>   lib/python2.7/site-packages/statsmodels/multivariate/manova.pyt   <module>   s   