ó
áp7]c           @  s¼  d  Z  d d l m Z d d l m Z d d l m Z d d l Z d „  Z	 d „  Z
 d „  Z e d	 „ Z e d
 „ Z d d e d „ Z d d „ Z d d „ Z d „  Z d d „ Z d e f d „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ e d k r¸e ƒ  Z e j ƒ  e j ƒ  e j ƒ  d d l j  Z! d d d g d Z" d d d g Z# d d  g Z$ e e# e$ ƒ Z% e& e% ƒ e j' d! ƒ Z( e j' d! ƒ d" Z) e j' d! ƒ d# d# Z* d e" k rôe e) ƒ \ Z+ Z, e e* ƒ \ Z- Z. n  d e" k r3e j/ e) d$ d% d& ƒZ) e j/ e* d$ d% d& ƒZ* n  e) j0 d& Z1 e e) ƒ \ Z+ Z, e e* ƒ \ Z- Z. e e+ e- d' d ƒZ2 e e+ e- d' d( ƒZ3 e e+ e- d' d) ƒZ4 e& e j5 e2 j6 e2 ƒ e j7 e2 j8 d& ƒ ƒ k j9 ƒ  ƒ d* d+ g d Z: d, d- g d& Z; e; e j< j= e1 ƒ Z> e: e j' d d. ƒ Z? e2 e? j8 d ƒ e> Z@ e3 e? j8 d ƒ e> ZA e4 e? j8 d ƒ e> ZB e! jC e@ e2 ƒ jD ƒ  ZE e! jC e@ e4 ƒ jD ƒ  ZF eE jG ZH eF jG ZI e! jC eB e2 ƒ jD ƒ  ZJ e! jC eB e4 ƒ jD ƒ  ZK eJ jG ZL eK jG ZM e jN jO e4 e2 d/ d ƒd& ZP e jN jO e2 e4 d/ d ƒd& ZQ e& e j5 eQ eM ƒ eL ƒ e& e j5 eP eH ƒ eI ƒ e e2 e4 ƒ ZR e& e jS e jT e2 eR jU e4 ƒ ƒ ƒ ƒ e& e jS e jT e4 eR jV e2 ƒ ƒ ƒ ƒ e& e jS e jT eM eR jW eL ƒ ƒ ƒ ƒ e jS e jT eI eR jW eH ƒ ƒ ƒ e e# e$ ƒ \ ZX ZY ZZ Z[ Z\ Z] e& d0 ƒ e& d1 ƒ e& eZ ƒ e& eJ j^ eY ƒ j_ ƒ e& d2 ƒ e& d3 ƒ e& e\ ƒ e& eJ j^ e[ ƒ j_ ƒ eJ j` e[ ƒ e ja e jb d5 ƒ e jc d# ƒ f ƒ Zd eF je d4 Zf eE j^ eR jU ed ƒ ƒ j_ Zg e& e jS e jT ef eg ƒ ƒ ƒ e eB e) e* ƒ Zh e& eh ji ƒ  j_ ƒ e& eh ji ƒ  jj ƒ e& eh jk ƒ  jl ƒ e& eh jk ƒ  jj ƒ e& eh jm d ƒ d& j_ ƒ e& eh jm d# ƒ d& j_ ƒ e& eh jn ƒ  ƒ n  d S(6   sò  functions to work with contrasts for multiple tests

contrast matrices for comparing all pairs, all levels to reference level, ...
extension to 2-way groups in progress

TwoWay: class for bringing two-way analysis together and try out
various helper functions


Idea for second part
- get all transformation matrices to move in between different full rank
  parameterizations
- standardize to one parameterization to get all interesting effects.

- multivariate normal distribution
  - exploit or expand what we have in LikelihoodResults, cov_params, f_test,
    t_test, example: resols_dropf_full.cov_params(C2)
  - connect to new multiple comparison for contrast matrices, based on
    multivariate normal or t distribution (Hothorn, Bretz, Westfall)

iÿÿÿÿ(   t   print_function(   t   assert_equal(   t   zipNc         C  sx   g  } xb t  |  ƒ D]T } xK t  | d |  ƒ D]6 } t j |  ƒ } d | | <d | | <| j | ƒ q- Wq Wt j | ƒ S(   sæ   contrast or restriction matrix for all pairs of nm variables

    Parameters
    ----------
    nm : int

    Returns
    -------
    contr : ndarray, 2d, (nm*(nm-1)/2, nm)
       contrast matrix for all pairwise comparisons

    i   iÿÿÿÿ(   t   ranget   npt   zerost   appendt   array(   t   nmt   contrt   it   jt	   contr_row(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   contrast_allpairs!   s    

c         C  s4   t  j t  j |  d ƒ t  j |  d ƒ f ƒ } | S(   sç   contrast or restriction matrix for all against first comparison

    Parameters
    ----------
    nm : int

    Returns
    -------
    contr : ndarray, 2d, (nm-1, nm)
       contrast matrix for all against first comparisons

    i   (   R   t   column_stackt   onest   eye(   R   R	   (    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   contrast_all_one7   s    0c         C  s$   t  j |  ƒ t  j |  |  f ƒ |  S(   så   contrast or restriction matrix for all against mean comparison

    Parameters
    ----------
    nm : int

    Returns
    -------
    contr : ndarray, 2d, (nm-1, nm)
       contrast matrix for all against mean comparisons

    (   R   R   R   (   R   (    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   contrast_diff_meanG   s    c         C  s]   |  d k rO | s/ t  j |  ƒ d k r+ d Sd St  j |  ƒ d k rH d Sd Sn
 t |  ƒ Sd  S(   Niÿÿÿÿi    i   t   +t   -t    (   iÿÿÿÿi    i   (   R   t   signt   str(   t   xt   noplus(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   signstrV   s
     c      
   C  s•   | r t  d  d  d ƒ } n t  d  ƒ } g  |  D]] } d j g  t | | ƒ | D]4 \ } } | d k rN d t | d t ƒ| f ^ qN ƒ ^ q. } | S(   NiÿÿÿÿR   i    s   %s%sR   (   t   slicet   Nonet   joinR   R   t   True(   t	   contrastst   namest   reverset   slt   rowt   ct   vt   labels(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   contrast_labels`   s    gc      
   C  s£  t  |  ƒ } t  | ƒ } g  |  D]# } | D] } d | | f ^ q) q }	 t j d | f ƒ }
 d |
 d
 <| sŠ t j |
 t | ƒ f } n t j |
 t | ƒ f } t j | d t j | ƒ ƒ } t | |	 d t	 ƒ} g  | D]f } d j
 g  t | |	 ƒ d d d … D]4 \ } } | d k rd t | d	 t	 ƒ| f ^ qƒ ^ qß } t j d | f ƒ } d | d <| st j | t | ƒ f } n t j | t | ƒ f } t j t j | ƒ | d ƒ } g  | D]f } d j
 g  t | |	 ƒ d d d … D]4 \ } } | d k röd t | d	 t	 ƒ| f ^ qöƒ ^ qÍ} | d k	 r‡| d k	 r‡t | ƒ \ } } t | ƒ \ } } t | | ƒ } n d } |	 | | | | | f S(   sˆ  build contrast matrices for products of two categorical variables

    this is an experimental script and should be converted to a class

    Parameters
    ----------
    names1, names2 : lists of strings
        contains the list of level labels for each categorical variable
    intgroup1, intgroup2 : ndarrays     TODO: this part not tested, finished yet
        categorical variable


    Notes
    -----
    This creates a full rank matrix. It does not do all pairwise comparisons,
    parameterization is using contrast_all_one to get differences with first
    level.

    ? does contrast_all_pairs work as a plugin to get all pairs ?

    s   %s_%si   i    R!   R   Niÿÿÿÿs   %s%sR   (   i    i    (   i    i    (   t   lenR   R   t   r_R   R   t   kronR   R'   R   R   R   R   R   t   dummy_1dt   dummy_product(   t   names1t   names2t	   intgroup1t	   intgroup2t   pairst   n1t   n2R
   R   t
   names_prodt   ee1t   ddt   contrast_prodt   names_contrast_prod0R#   R$   R%   t   names_contrast_prodt   ee2t   dd2t   contrast_prod2t   names_contrast_prod2t   d1t   _t   d2t   dummy(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   contrast_productj   s6    0
p
p	c         C  sØ   | d k ru g  t |  j ƒ  d ƒ D] } d | ^ q# } |  d d … d f t j |  j ƒ  d ƒ k j t ƒ | f St j |  ƒ } g  | D] } | d t | ƒ ^ q‹ } |  d d … d f | k j t ƒ | f Sd S(   s  dummy variable for id integer groups

    Parameters
    ----------
    x : ndarray, 1d
        categorical variable, requires integers if varname is None
    varname : string
        name of the variable used in labels for category levels

    Returns
    -------
    dummy : ndarray, 2d
        array of dummy variables, one column for each level of the
        category (full set)
    labels : list of strings
        labels for the columns, i.e. levels of each category


    Notes
    -----
    use tools.categorical instead for more more options

    See Also
    --------
    statsmodels.tools.categorical

    Examples
    --------
    >>> x = np.array(['F', 'F', 'M', 'M', 'F', 'F', 'M', 'M', 'F', 'F', 'M', 'M'],
          dtype='|S1')
    >>> dummy_1d(x, varname='gender')
    (array([[1, 0],
           [1, 0],
           [0, 1],
           [0, 1],
           [1, 0],
           [1, 0],
           [0, 1],
           [0, 1],
           [1, 0],
           [1, 0],
           [0, 1],
           [0, 1]]), ['gender_F', 'gender_M'])

    i   s   level_%dNs   _%s(	   R   R   t   maxR   t   aranget   astypet   intt   uniqueR   (   R   t   varnameR
   R&   t   grouplabels(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyR+   ¬   s    .-<'t   fullc         C  s¶  | d k r^ |  d d … d d … d f | d d … d d d … f j |  j d d ƒ } nT| d k rt |  d d … d d … f | d d … d d … f ƒ } t j t j |  j d t ƒ |  d d … d d … f | d d … d d … f | f ƒ } n° | d k r¦t |  d d … d d … f | d d … d d … f ƒ } t j t j |  j d t ƒ |  d d … d d … f | d d … d d … f | f ƒ } n t d ƒ ‚ | S(	   sŸ  dummy variable from product of two dummy variables

    Parameters
    ----------
    d1, d2 : ndarray
        two dummy variables, assumes full set for methods 'drop-last'
        and 'drop-first'
    method : {'full', 'drop-last', 'drop-first'}
        'full' returns the full product, encoding of intersection of
        categories.
        The drop methods provide a difference dummy encoding:
        (constant, main effects, interaction effects). The first or last columns
        of the dummy variable (i.e. levels) are dropped to get full rank
        dummy matrix.

    Returns
    -------
    dummy : ndarray
        dummy variable for product, see method

    RJ   Ni    iÿÿÿÿs	   drop-lasts
   drop-firsti   s   method not recognized(	   R   t   reshapet   shapeR,   R   R   R   RF   t
   ValueError(   R>   R@   t   methodR6   t   d12rlt   d12r(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyR,   ã   s    R;];]c   
      C  s	  |  j  \ } } t j t j |  d d ƒd k ƒ \ } } t j t j |  d d ƒd k ƒ \ } } t j | ƒ } t j d g | f | k j ƒ  s¼ t j | | d g f | k j ƒ  rË t d ƒ ‚ n  t j d g | d f } t j | d | g f }	 | |	 f S(   s¬  start and endpoints of groups in a sorted dummy variable array

    helper function for nested categories

    Examples
    --------
    >>> d1 = np.array([[1, 0, 0],
                       [1, 0, 0],
                       [1, 0, 0],
                       [1, 0, 0],
                       [0, 1, 0],
                       [0, 1, 0],
                       [0, 1, 0],
                       [0, 1, 0],
                       [0, 0, 1],
                       [0, 0, 1],
                       [0, 0, 1],
                       [0, 0, 1]])
    >>> dummy_limits(d1)
    (array([0, 4, 8]), array([ 4,  8, 12]))

    get group slices from an array

    >>> [np.arange(d1.shape[0])[b:e] for b,e in zip(*dummy_limits(d1))]
    [array([0, 1, 2, 3]), array([4, 5, 6, 7]), array([ 8,  9, 10, 11])]
    >>> [np.arange(d1.shape[0])[b:e] for b,e in zip(*dummy_limits(d1))]
    [array([0, 1, 2, 3]), array([4, 5, 6, 7]), array([ 8,  9, 10, 11])]
    t   axisi    i   iÿÿÿÿs   dummy variable is not sorted(   RL   R   t   nonzerot   diffRD   R)   t   allRM   (
   t   dt   nobst   nvarst   start1t   col1t   end1t   col1_t   cct   startt   end(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   dummy_limits  s    **#'c         C  sË  | d k r | St  |  ƒ \ } } t  | ƒ \ } } t j | | ƒ } t j | | ƒ } | | k }	 | |	 }
 | |	 } | d k rt |  d d … d d … f | d d … d d … f ƒ } t j t j |  j d t ƒ |  d d … d d … f | d d … | f f ƒ } n§ | d k r²t |  d d … d d … f | d d … d d … f ƒ } t j t j |  j d t ƒ |  d d … d d … f | d d … |
 f f ƒ } n t d ƒ ‚ | |
 | f S(	   sÙ  unfinished and incomplete mainly copy past dummy_product
    dummy variable from product of two dummy variables

    Parameters
    ----------
    d1, d2 : ndarray
        two dummy variables, d2 is assumed to be nested in d1
        Assumes full set for methods 'drop-last' and 'drop-first'.
    method : {'full', 'drop-last', 'drop-first'}
        'full' returns the full product, which in this case is d2.
        The drop methods provide an effects encoding:
        (constant, main effects, subgroup effects). The first or last columns
        of the dummy variable (i.e. levels) are dropped to get full rank
        encoding.

    Returns
    -------
    dummy : ndarray
        dummy variable for product, see method

    RJ   s	   drop-lastNiÿÿÿÿi    s
   drop-firsti   s   method not recognized(	   R_   R   t   in1dR,   R   R   RL   RF   RM   (   R>   R@   RN   RX   RZ   t   start2t   end2t   firstt   lastt   equalt	   col_dropft	   col_droplRO   R6   RP   (    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   dummy_nested4  s"    ;T;Tt   DummyTransformc           B  s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s  Conversion between full rank dummy encodings


    y = X b + u
    b = C a
    a = C^{-1} b

    y = X C a + u

    define Z = X C, then

    y = Z a + u

    contrasts:

    R_b b = r

    R_a a = R_b C a = r

    where R_a = R_b C

    Here C is the transform matrix, with dot_left and dot_right as the main
    methods, and the same for the inverse transform matrix, C^{-1}

    Note:
     - The class was mainly written to keep left and right straight.
     - No checking is done.
     - not sure yet if method names make sense


    c         C  sH   t  j j | | d d ƒd |  _ t  j j | | d d ƒd |  _ d S(   s\   C such that d1 C = d2, with d1 = X, d2 = Z

        should be (x, z) in arguments ?
        t   rcondiÿÿÿÿi    N(   R   t   linalgt   lstsqt   transf_matrixt   invtransf_matrix(   t   selfR>   R@   (    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   __init__„  s    "c         C  s   t  j |  j | ƒ S(   s    b = C a
        (   R   t   dotRm   (   Ro   t   a(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   dot_leftŒ  s    c         C  s   t  j | |  j ƒ S(   s    z = x C
        (   R   Rq   Rm   (   Ro   R   (    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt	   dot_right‘  s    c         C  s   t  j |  j | ƒ S(   s    a = C^{-1} b
        (   R   Rq   Rn   (   Ro   t   b(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   inv_dot_left–  s    c         C  s   t  j | |  j ƒ S(   s    x = z C^{-1}
        (   R   Rq   Rn   (   Ro   t   z(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   inv_dot_right›  s    (   t   __name__t
   __module__t   __doc__Rp   Rs   Rt   Rv   Rx   (    (    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyRi   c  s   				c         C  sq   t  j |  ƒ }  |  j d } t d ƒ g d g | d t d ƒ g } |  d | | j d ƒ d | j d ƒ S(   sn  groupmeans using dummy variables

    Parameters
    ----------
    x : array_like, ndim
        data array, tested for 1,2 and 3 dimensions
    d : ndarray, 1d
        dummy variable, needs to have the same length
        as x in axis 0.

    Returns
    -------
    groupmeans : ndarray, ndim-1
        means for each group along axis 0, the levels
        of the groups are the last axis

    Notes
    -----
    This will be memory intensive if there are many levels
    in the categorical variable, i.e. many columns in the
    dummy variable. In this case it is recommended to use
    a more efficient version.

    i   i   .i    g      ð?N(   .N(   R   t   asarrayt   ndimR   R   t   sum(   R   RU   RW   t   sli(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   groupmean_d¤  s    +t   TwoWayc           B  sG   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   sý  a wrapper class for two way anova type of analysis with OLS


    currently mainly to bring things together

    Notes
    -----
    unclear: adding multiple test might assume block design or orthogonality

    This estimates the full dummy version with OLS.
    The drop first dummy representation can be recovered through the
    transform method.

    TODO: add more methods, tests, pairwise, multiple, marginal effects
    try out what can be added for userfriendly access.

    missing: ANOVA table

    c         C  s¾  | j  d |  _ | d  k r+ d } d } n | \ } } t | | ƒ \ |  _ |  _ \ } } t | | ƒ \ |  _ |  _ \ }	 }
 | j  d |  _ } |	 j  d |  _	 } t
 | |
 ƒ } | \ } } } } } } | \ |  _ |  _ |  _ |  _ |  _ } t | |	 d d ƒ} t | |	 d d ƒ} t | | ƒ |  _ | j  d |  _ | |  _ t j | | ƒ j ƒ  |  _ |  j j |  _ |  j j |  j ƒ |  _ d | d | d |  _ |  j |  j |  _ d  S(   Ni    Rr   Ru   i   RN   RJ   s
   drop-first(   RL   RV   R   R+   R>   t	   d1_labelsR@   t	   d2_labelst   nlevel1t   nlevel2RB   t
   prod_labelt   C1t   C1_labelt   C2t   C2_labelR,   Ri   t	   transformRW   t   exogt   smt   OLSt   fitt   resolst   paramsRv   t   params_dropft   start_interactiont   n_interaction(   Ro   t   endogt   factor1t   factor2t   varnamest   vname1t   vname2R>   R‚   R@   Rƒ   R„   R…   t   rest   prodlabR‡   t   C1labR‰   t   C2labR?   t   dp_fullt   dp_dropf(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyRp   Û  s,    	%%'	c         C  s\   |  j  } t j t j | |  j | f ƒ t j | ƒ f ƒ } |  j j | ƒ } | |  _ | S(   s7   contrast/restriction matrix for no interaction
        (	   R”   R   t   hstackR   RW   R   R‹   Rx   t   R_nointer_transf(   Ro   t   niat	   R_nointerR¢   (    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt	   r_nointerý  s
    	4	c         C  sn   |  j  } t j t j | |  j | f ƒ t j | ƒ f ƒ } |  j j | ƒ } | |  _ |  j	 j
 | ƒ } | S(   s1   ttests for no-interaction terms are zero
        (   R”   R   R¡   R   RW   R   R‹   Rx   R¢   R   t   t_test(   Ro   R£   R¤   R¢   t   t_res(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   ttest_interaction  s    	4	c         C  s   |  j  ƒ  } |  j j | ƒ S(   s1   ttests for no-interaction terms are zero
        (   R¥   R   t   f_test(   Ro   R¢   (    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   ftest_interaction  s    c         C  sH   | d k r( |  j  j |  j ƒ |  j f S|  j  j |  j ƒ |  j f Sd  S(   Ni   (   R   R¦   R‡   Rˆ   R‰   RŠ   (   Ro   t	   factorind(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   ttest_conditional_effect  s    c         C  sx   d d l  m } |  j j |  j |  j ƒ } |  j } |  j } d } t d d g |  j ƒ } | | | | d | d | ƒS(   Niÿÿÿÿ(   t   SimpleTables!   Estimated Coefficients by factorst	   data_fmtss   %#10.4gt   titlet   txt_fmt(	   t   statsmodels.iolibR­   R‘   RK   R„   R…   R‚   Rƒ   t   dict(   Ro   R­   t
   params_arrt   stubst   headersR¯   t	   table_fmt(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   summary_coeff  s    		N(
   Ry   Rz   R{   R   Rp   R¥   R¨   Rª   R¬   R·   (    (    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyR   Ç  s   "	
			t   TestContrastToolsc           B  s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C  sÇ   d d d g |  _  d d g |  _ t j d d d g d d d g d d d g d d d g d d d g d d d g d d d g d d d g d d d g d d d g d d d g d d d g g ƒ |  _ d  S(   Nt   a0t   a1t   a2t   b0t   b1i   i    (   t   v1namet   v2nameR   R   R>   (   Ro   (    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyRp   0  s    c         C  s÷   t  j d d d d d d d d d d d d g d d ƒ} t  j d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g g ƒ d d g } } t | d	 d
 ƒ\ } } t | | ƒ t | | ƒ d  S(   Nt   Ft   Mt   dtypes   |S1i   i    t   gender_Ft   gender_MRH   t   gender(   R   R   R+   R   (   Ro   R   RU   R&   t   res_dt
   res_labels(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   test_dummy_1d@  s"    0											c      
   C  sb  t  |  j |  j ƒ } d g d } d d d d d d g | d <t j d	 d
 d d
 d
 d
 g d
 d	 d
 d d
 d
 g d	 d
 d
 d
 d d
 g d
 d	 d
 d
 d
 d g g ƒ | d <d d d d g | d <t j d	 d d
 d
 d
 d
 g d
 d
 d	 d d
 d
 g d
 d
 d
 d
 d	 d g g ƒ | d <d d d g | d <x; t d ƒ D]- } t j j | | | | d t | ƒ ƒq-Wd  S(   Ni    i   t   a0_b0t   a0_b1t   a1_b0t   a1_b1t   a2_b0t   a2_b1g      ð¿g        g      ð?i   s   a1_b0-a0_b0s   a1_b1-a0_b1s   a2_b0-a0_b0s   a2_b1-a0_b1i   i   s   a0_b1-a0_b0s   a1_b1-a1_b0s   a2_b1-a2_b0i   i   t   err_msg(	   RB   R¾   R¿   R   R   R   t   testingR   R   (   Ro   t   res_cpt   res_tt   ii(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   test_contrast_productS  s    ""c         C  sW   t  |  j ƒ \ } } t | t j d d d g ƒ ƒ t | t j d d d g ƒ ƒ d  S(   Ni    i   i   i   (   R_   R>   R   R   R   (   Ro   Ru   t   e(    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   test_dummy_limitsc  s    (   Ry   Rz   Rp   RÈ   RÔ   RÖ   (    (    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyR¸   .  s   			t   __main__t   smallt   largei   R¹   Rº   R»   R¼   R½   i   i   i   i   RQ   i    RN   s	   drop-lasts
   drop-firstg      ð?g{®Gáz„?gü©ñÒMbP?gš™™™™™¹?i   Rj   s"   
tvalues for no effect of factor 1s/   each test is conditional on a level of factor 2s"   
tvalues for no effect of factor 2s/   each test is conditional on a level of factor 1iþÿÿÿ(   i   i   (o   R{   t
   __future__R    t   numpy.testingR   t   statsmodels.compat.pythonR   t   numpyR   R   R   R   t   FalseR   R'   R   RB   R+   R,   R_   Rh   t   objectRi   R€   R   R¸   Ry   t   ttRÔ   RÈ   RÖ   t   statsmodels.apit   apiR   t   examplesR¾   R¿   RÑ   t   printRD   t   yt   x1t   x2R>   R‚   R@   Rƒ   t   repeatRL   RV   t   dd_fullt   dd_droplt   dd_dropfRq   t   Tt   diagR~   RT   t   effect_sizet   noise_scalet   randomt   randnt   noiset   betat
   ydata_fullt   ydata_droplt   ydata_dropfRŽ   R   t   resols_full_fullt   resols_full_dropfR‘   t
   params_f_ft   params_f_dft   resols_dropf_fullt   resols_dropf_dropft   params_df_ft   params_df_dfRk   Rl   t   tr_oft   tr_fot   transf_f_dfRC   t   absRx   Rt   Rv   Rœ   R‡   R   R‰   Rž   R?   R¦   t   tvaluet
   cov_paramsR¡   R   R   t   R_nointt   tvaluest   inter_directt   inter_transft   twR¨   t   pvalueRª   t   fvalueR¬   R·   (    (    (    sG   lib/python2.7/site-packages/statsmodels/sandbox/stats/contrast_tools.pyt   <module>   s¼   			

B7%	,/A	#g=	



7				))!





' î