B
    ¤ŠãZM  ã               @   sd   d Z ddlmZ ddlZddlmZ ddlmZm	Z	 ddlm
Z
 ddlmZ d	ZG d
d„ deƒZdS )z7Multivariate analysis of variance

author: Yichuan Liu
é    )ÚdivisionN)ÚModelé   )Ú_multivariate_ols_testÚ_hypotheses_doc)Ú_multivariate_ols_fit)ÚMultivariateTestResultszrestructuredtext enc                   s:   e Zd ZdZd
‡ fdd„	Zddd„Zde d	 e_‡  ZS )ÚMANOVAa6  
    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.

    References
    ----------
    .. [*] ftp://public.dhe.ibm.com/software/analytics/spss/documentation/statistics/20.0/en/client/Manuals/IBM_SPSS_Statistics_Algorithms.pdf
    ÚnoneNc                sX   t |jƒdks|jd dkr$tdƒ‚tt| ƒj||f||dœ|—Ž t| j| jƒ| _	d S )Nr   z=There must be more than one dependent variable to fit MANOVA!)ÚmissingÚhasconst)
ÚlenÚshapeÚ
ValueErrorÚsuperr	   Ú__init__r   ÚendogÚexogÚ
_fittedmod)Úselfr   r   r   r   Úkwargs)Ú	__class__© ú>lib/python3.7/site-packages/statsmodels/multivariate/manova.pyr   0   s
    zMANOVA.__init__c       	      C   sð   |d krÌt | dƒrx| jd k	rxt | jdƒrx| jjj}g }x”|D ]6}t | jjd ¡|| d d …f }| ||d g¡ q<W nTg }xNt	| jjd ƒD ]:}d| }t 
d| jjd g¡}d||< | ||d g¡ qŽW t|| j| j| jƒ}t|| j| jƒS )NÚdataÚdesign_infor   zx%d)Úhasattrr   r   Zterm_name_slicesÚnpZeyer   r   ÚappendÚrangeZzerosr   r   Z
exog_namesZendog_namesr   )	r   Z
hypothesesZtermsÚkeyZ
L_contrastÚiÚnameÚLZresultsr   r   r   Úmv_test8   s$    

"zMANOVA.mv_testz2
Linear hypotheses testing

Parameters
----------
zÏ

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
)r
   N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r$   r   Ú__classcell__r   r   )r   r   r	      s
   
r	   )r(   Z
__future__r   Znumpyr   Zstatsmodels.base.modelr   Zmultivariate_olsr   r   r   r   Z__docformat__r	   r   r   r   r   Ú<module>   s   