
    M/Ph                     r    d 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	 ddlm
Z
mZ d	Z G d
 de          ZdS )z7Multivariate analysis of variance

author: Yichuan Liu
    N)Substitution)Model   )MultivariateTestResults)_multivariate_ols_fit)_multivariate_ols_test_hypotheses_doczrestructuredtext enc                   Z     e Zd ZdZdZd	 fd	Zd Z ee          d
d            Z	 xZ
S )MANOVAaN  
    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 : ndarray
        See Parameters.
    exog : ndarray
        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
    Nnonec                     t          |j                  dk    s|j        d         dk    rt          d           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super__init__r   endogexog
_fittedmod)selfr   r   r   r   kwargs	__class__s         _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/multivariate/manova.pyr   zMANOVA.__init__;   s    u{q  EKNa$7$7 / 0 0 0 	Bg.6	B 	B:@	B 	B 	B/
DIFF    c                      t          d          )NzKfit is not needed to use MANOVA. Callmv_test directly on a MANOVA instance.)NotImplementedError)r   s    r   fitz
MANOVA.fitC   s    ! #K L L 	Lr   )hypotheses_docFc                    |t          | d          r| j        t          | j        d          rn| j        j        j        }g }|D ]W}|r|dk    rt	          j        | j        j        d                   ||         ddf         }|                    ||dg           Xnng }t          | j        j        d                   D ]L}d|z  }t	          j
        d| j        j        d         g          }d|d|f<   |                    ||dg           Mt          || j        | j        | j                  }	t          |	| j        | j                  S )aT  
        Linear hypotheses testing

        Parameters
        ----------
        %(hypotheses_doc)s
        skip_intercept_test : bool
            If true, then testing the intercept is skipped, the model is not
            changed.
            Note: If a term has a numerically insignificant effect, then
            an exception because of emtpy arrays may be raised. This can
            happen for the intercept if the data has been demeaned.

        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datadesign_info	Interceptr   zx%dr   )hasattrr"   r#   term_name_slicesnpeyer   r   appendrangezerosr   r   
exog_namesendog_namesr   )
r   
hypothesesskip_intercept_testtermskey
L_contrastinameLresultss
             r   mv_testzMANOVA.mv_testG   ss   D f%% 7$)*?	=99 +@	->
  ? ?C* !sk/A/A !#	(:!;!;E#JM!JJ%%sJ&=>>>>	?  
tyq122 7 7A A;D!TY_Q%7!899AAadG%%tQo6666(T_)-$:JL L 'w0@'+8 8 	8r   )r   N)NF)__name__
__module____qualname____doc___formula_max_endogr   r   r   r	   r7   __classcell__)r   s   @r   r   r      s        ' 'P G G G G G GL L L \11178 78 78 2178 78 78 78 78r   r   )r;   numpyr'   statsmodels.compat.pandasr   statsmodels.base.modelr   multivariate_olsr   r   r   r	   __docformat__r    r   r   <module>rD      s         2 2 2 2 2 2 ( ( ( ( ( ( 5 5 5 5 5 5 3 3 3 3 3 3 E E E E E E E E%o8 o8 o8 o8 o8U o8 o8 o8 o8 o8r   