<s> '''<STR_LIT>''' <EOL> from __future__ import print_function <EOL> from statsmodels . compat . python import zip <EOL> import numpy as np <EOL> def contrast_allpairs ( nm ) : <EOL> '''<STR_LIT>''' <EOL> contr = [ ] <EOL> for i in range ( nm ) : <EOL> for j in range ( i + <NUM_LIT:1> , nm ) : <EOL> contr_row = np . zeros ( nm ) <EOL> contr_row [ i ] = <NUM_LIT:1> <EOL> contr_row [ j ] = - <NUM_LIT:1> <EOL> contr . append ( contr_row ) <EOL> return np . array ( contr ) <EOL> def contrast_all_one ( nm ) : <EOL> '''<STR_LIT>''' <EOL> contr = np . column_stack ( ( np . ones ( nm - <NUM_LIT:1> ) , - np . eye ( nm - <NUM_LIT:1> ) ) ) <EOL> return contr <EOL> def contrast_diff_mean ( nm ) : <EOL> '''<STR_LIT>''' <EOL> return np . eye ( nm ) - np . ones ( ( nm , nm ) ) / nm <EOL> def signstr ( x , noplus = False ) : <EOL> if x in [ - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] : <EOL> if not noplus : <EOL> return '<STR_LIT:+>' if np . sign ( x ) >= <NUM_LIT:0> else '<STR_LIT:->' <EOL> else : <EOL> return '<STR_LIT>' if np . sign ( x ) >= <NUM_LIT:0> else '<STR_LIT:->' <EOL> else : <EOL> return str ( x ) <EOL> def contrast_labels ( contrasts , names , reverse = False ) : <EOL> if reverse : <EOL> sl = slice ( None , None , - <NUM_LIT:1> ) <EOL> else : <EOL> sl = slice ( None ) <EOL> labels = [ '<STR_LIT>' . join ( [ '<STR_LIT>' % ( signstr ( c , noplus = True ) , v ) <EOL> for c , v in zip ( row , names ) [ sl ] if c != <NUM_LIT:0> ] ) <EOL> for row in contrasts ] <EOL> return labels <EOL> def contrast_product ( names1 , names2 , intgroup1 = None , intgroup2 = None , pairs = False ) : <EOL> '''<STR_LIT>''' <EOL> n1 = len ( names1 ) <EOL> n2 = len ( names2 ) <EOL> names_prod = [ '<STR_LIT>' % ( i , j ) for i in names1 for j in names2 ] <EOL> ee1 = np . zeros ( ( <NUM_LIT:1> , n1 ) ) <EOL> ee1 [ <NUM_LIT:0> , <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> if not pairs : <EOL> dd = np . r_ [ ee1 , - contrast_all_one ( n1 ) ] <EOL> else : <EOL> dd = np . r_ [ ee1 , - contrast_allpairs ( n1 ) ] <EOL> contrast_prod = np . kron ( dd [ <NUM_LIT:1> : ] , np . eye ( n2 ) ) <EOL> names_contrast_prod0 = contrast_labels ( contrast_prod , names_prod , reverse = True ) <EOL> names_contrast_prod = [ '<STR_LIT>' . join ( [ '<STR_LIT>' % ( signstr ( c , noplus = True ) , v ) <EOL> for c , v in zip ( row , names_prod ) [ : : - <NUM_LIT:1> ] if c != <NUM_LIT:0> ] ) <EOL> for row in contrast_prod ] <EOL> ee2 = np . zeros ( ( <NUM_LIT:1> , n2 ) ) <EOL> ee2 [ <NUM_LIT:0> , <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> if not pairs : <EOL> dd2 = np . r_ [ ee2 , - contrast_all_one ( n2 ) ] <EOL> else : <EOL> dd2 = np . r_ [ ee2 , - contrast_allpairs ( n2 ) ] <EOL> contrast_prod2 = np . kron ( np . eye ( n1 ) , dd2 [ <NUM_LIT:1> : ] ) <EOL> names_contrast_prod2 = [ '<STR_LIT>' . join ( [ '<STR_LIT>' % ( signstr ( c , noplus = True ) , v ) <EOL> for c , v in zip ( row , names_prod ) [ : : - <NUM_LIT:1> ] if c != <NUM_LIT:0> ] ) <EOL> for row in contrast_prod2 ] <EOL> if ( not intgroup1 is None ) and ( not intgroup1 is None ) : <EOL> d1 , _ = dummy_1d ( intgroup1 ) <EOL> d2 , _ = dummy_1d ( intgroup2 ) <EOL> dummy = dummy_product ( d1 , d2 ) <EOL> else : <EOL> dummy = None <EOL> return ( names_prod , contrast_prod , names_contrast_prod , <EOL> contrast_prod2 , names_contrast_prod2 , dummy ) <EOL> def dummy_1d ( x , varname = None ) : <EOL> '''<STR_LIT>''' <EOL> if varname is None : <EOL> labels = [ '<STR_LIT>' % i for i in range ( x . max ( ) + <NUM_LIT:1> ) ] <EOL> return ( x [ : , None ] == np . arange ( x . max ( ) + <NUM_LIT:1> ) ) . astype ( int ) , labels <EOL> else : <EOL> grouplabels = np . unique ( x ) <EOL> labels = [ varname + '<STR_LIT>' % str ( i ) for i in grouplabels ] <EOL> return ( x [ : , None ] == grouplabels ) . astype ( int ) , labels <EOL> def dummy_product ( d1 , d2 , method = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> if method == '<STR_LIT>' : <EOL> dd = ( d1 [ : , : , None ] * d2 [ : , None , : ] ) . reshape ( d1 . shape [ <NUM_LIT:0> ] , - <NUM_LIT:1> ) <EOL> elif method == '<STR_LIT>' : <EOL> d12rl = dummy_product ( d1 [ : , : - <NUM_LIT:1> ] , d2 [ : , : - <NUM_LIT:1> ] ) <EOL> dd = np . column_stack ( ( np . ones ( d1 . shape [ <NUM_LIT:0> ] , int ) , d1 [ : , : - <NUM_LIT:1> ] , d2 [ : , : - <NUM_LIT:1> ] , d12rl ) ) <EOL> elif method == '<STR_LIT>' : <EOL> d12r = dummy_product ( d1 [ : , <NUM_LIT:1> : ] , d2 [ : , <NUM_LIT:1> : ] ) <EOL> dd = np . column_stack ( ( np . ones ( d1 . shape [ <NUM_LIT:0> ] , int ) , d1 [ : , <NUM_LIT:1> : ] , d2 [ : , <NUM_LIT:1> : ] , d12r ) ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return dd <EOL> def dummy_limits ( d ) : <EOL> '''<STR_LIT>''' <EOL> nobs , nvars = d . shape <EOL> start1 , col1 = np . nonzero ( np . diff ( d , axis = <NUM_LIT:0> ) == <NUM_LIT:1> ) <EOL> end1 , col1_ = np . nonzero ( np . diff ( d , axis = <NUM_LIT:0> ) == - <NUM_LIT:1> ) <EOL> cc = np . arange ( nvars ) <EOL> if ( ( not ( np . r_ [ [ <NUM_LIT:0> ] , col1 ] == cc ) . all ( ) ) <EOL> or ( not ( np . r_ [ col1_ , [ nvars - <NUM_LIT:1> ] ] == cc ) . all ( ) ) ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> start = np . r_ [ [ <NUM_LIT:0> ] , start1 + <NUM_LIT:1> ] <EOL> end = np . r_ [ end1 + <NUM_LIT:1> , [ nobs ] ] <EOL> return start , end <EOL> def dummy_nested ( d1 , d2 , method = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> if method == '<STR_LIT>' : <EOL> return d2 <EOL> start1 , end1 = dummy_limits ( d1 ) <EOL> start2 , end2 = dummy_limits ( d2 ) <EOL> first = np . in1d ( start2 , start1 ) <EOL> last = np . in1d ( end2 , end1 ) <EOL> equal = ( first == last ) <EOL> col_dropf = ~ first * ~ equal <EOL> col_dropl = ~ last * ~ equal <EOL> if method == '<STR_LIT>' : <EOL> d12rl = dummy_product ( d1 [ : , : - <NUM_LIT:1> ] , d2 [ : , : - <NUM_LIT:1> ] ) <EOL> dd = np . column_stack ( ( np . ones ( d1 . shape [ <NUM_LIT:0> ] , int ) , d1 [ : , : - <NUM_LIT:1> ] , d2 [ : , col_dropl ] ) ) <EOL> elif method == '<STR_LIT>' : <EOL> d12r = dummy_product ( d1 [ : , <NUM_LIT:1> : ] , d2 [ : , <NUM_LIT:1> : ] ) <EOL> dd = np . column_stack ( ( np . ones ( d1 . shape [ <NUM_LIT:0> ] , int ) , d1 [ : , <NUM_LIT:1> : ] , d2 [ : , col_dropf ] ) ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return dd , col_dropf , col_dropl <EOL> class DummyTransform ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , d1 , d2 ) : <EOL> '''<STR_LIT>''' <EOL> self . transf_matrix = np . linalg . lstsq ( d1 , d2 ) [ <NUM_LIT:0> ] <EOL> self . invtransf_matrix = np . linalg . lstsq ( d2 , d1 ) [ <NUM_LIT:0> ] <EOL> def dot_left ( self , a ) : <EOL> '''<STR_LIT>''' <EOL> return np . dot ( self . transf_matrix , a ) <EOL> def dot_right ( self , x ) : <EOL> '''<STR_LIT>''' <EOL> return np . dot ( x , self . transf_matrix ) <EOL> def inv_dot_left ( self , b ) : <EOL> '''<STR_LIT>''' <EOL> return np . dot ( self . invtransf_matrix , b ) <EOL> def inv_dot_right ( self , z ) : <EOL> '''<STR_LIT>''' <EOL> return np . dot ( z , self . invtransf_matrix ) <EOL> def groupmean_d ( x , d ) : <EOL> '''<STR_LIT>''' <EOL> x = np . asarray ( x ) <EOL> nvars = x . ndim + <NUM_LIT:1> <EOL> sli = [ slice ( None ) ] + [ None ] * ( nvars - <NUM_LIT:2> ) + [ slice ( None ) ] <EOL> return ( x [ ... , None ] * d [ sli ] ) . sum ( <NUM_LIT:0> ) * <NUM_LIT:1.> / d . sum ( <NUM_LIT:0> ) <EOL> class TwoWay ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , endog , factor1 , factor2 , varnames = None ) : <EOL> self . nobs = factor1 . shape [ <NUM_LIT:0> ] <EOL> if varnames is None : <EOL> vname1 = '<STR_LIT:a>' <EOL> vname2 = '<STR_LIT:b>' <EOL> else : <EOL> vname1 , vname1 = varnames <EOL> self . d1 , self . d1_labels = d1 , d1_labels = dummy_1d ( factor1 , vname1 ) <EOL> self . d2 , self . d2_labels = d2 , d2_labels = dummy_1d ( factor2 , vname2 ) <EOL> self . nlevel1 = nlevel1 = d1 . shape [ <NUM_LIT:1> ] <EOL> self . nlevel2 = nlevel2 = d2 . shape [ <NUM_LIT:1> ] <EOL> res = contrast_product ( d1_labels , d2_labels ) <EOL> prodlab , C1 , C1lab , C2 , C2lab , _ = res <EOL> self . prod_label , self . C1 , self . C1_label , self . C2 , self . C2_label , _ = res <EOL> dp_full = dummy_product ( d1 , d2 , method = '<STR_LIT>' ) <EOL> dp_dropf = dummy_product ( d1 , d2 , method = '<STR_LIT>' ) <EOL> self . transform = DummyTransform ( dp_full , dp_dropf ) <EOL> self . nvars = dp_full . shape [ <NUM_LIT:1> ] <EOL> self . exog = dp_full <EOL> self . resols = sm . OLS ( endog , dp_full ) . fit ( ) <EOL> self . params = self . resols . params <EOL> self . params_dropf = self . transform . inv_dot_left ( self . params ) <EOL> self . start_interaction = <NUM_LIT:1> + ( nlevel1 - <NUM_LIT:1> ) + ( nlevel2 - <NUM_LIT:1> ) <EOL> self . n_interaction = self . nvars - self . start_interaction <EOL> def r_nointer ( self ) : <EOL> '''<STR_LIT>''' <EOL> nia = self . n_interaction <EOL> R_nointer = np . hstack ( ( np . zeros ( ( nia , self . nvars - nia ) ) , np . eye ( nia ) ) ) <EOL> R_nointer_transf = self . transform . inv_dot_right ( R_nointer ) <EOL> self . R_nointer_transf = R_nointer_transf <EOL> return R_nointer_transf <EOL> def ttest_interaction ( self ) : <EOL> '''<STR_LIT>''' <EOL> nia = self . n_interaction <EOL> R_nointer = np . hstack ( ( np . zeros ( ( nia , self . nvars - nia ) ) , np . eye ( nia ) ) ) <EOL> R_nointer_transf = self . transform . inv_dot_right ( R_nointer ) <EOL> self . R_nointer_transf = R_nointer_transf <EOL> t_res = self . resols . t_test ( R_nointer_transf ) <EOL> return t_res <EOL> def ftest_interaction ( self ) : <EOL> '''<STR_LIT>''' <EOL> R_nointer_transf = self . r_nointer ( ) <EOL> return self . resols . f_test ( R_nointer_transf ) <EOL> def ttest_conditional_effect ( self , factorind ) : <EOL> if factorind == <NUM_LIT:1> : <EOL> return self . resols . t_test ( self . C1 ) , self . C1_label <EOL> else : <EOL> return self . resols . t_test ( self . C2 ) , self . C2_label <EOL> def summary_coeff ( self ) : <EOL> from statsmodels . iolib import SimpleTable <EOL> params_arr = self . params . reshape ( self . nlevel1 , self . nlevel2 ) <EOL> stubs = self . d1_labels <EOL> headers = self . d2_labels <EOL> title = '<STR_LIT>' <EOL> table_fmt = dict ( <EOL> data_fmts = [ "<STR_LIT>" ] * self . nlevel2 ) <EOL> return SimpleTable ( params_arr , headers , stubs , title = title , <EOL> txt_fmt = table_fmt ) <EOL> from numpy . testing import assert_equal <EOL> class TestContrastTools ( object ) : <EOL> def __init__ ( self ) : <EOL> self . v1name = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . v2name = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . d1 = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ] ) <EOL> def test_dummy_1d ( self ) : <EOL> x = np . array ( [ '<STR_LIT:F>' , '<STR_LIT:F>' , '<STR_LIT:M>' , '<STR_LIT:M>' , '<STR_LIT:F>' , '<STR_LIT:F>' , '<STR_LIT:M>' , '<STR_LIT:M>' , '<STR_LIT:F>' , '<STR_LIT:F>' , '<STR_LIT:M>' , '<STR_LIT:M>' ] , <EOL> dtype = '<STR_LIT>' ) <EOL> d , labels = ( np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> ] ] ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> res_d , res_labels = dummy_1d ( x , varname = '<STR_LIT>' ) <EOL> assert_equal ( res_d , d ) <EOL> assert_equal ( res_labels , labels ) <EOL> def test_contrast_product ( self ) : <EOL> res_cp = contrast_product ( self . v1name , self . v2name ) <EOL> res_t = [ <NUM_LIT:0> ] * <NUM_LIT:6> <EOL> res_t [ <NUM_LIT:0> ] = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> res_t [ <NUM_LIT:1> ] = np . array ( [ [ - <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> , - <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , <EOL> [ - <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> , - <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] ] ) <EOL> res_t [ <NUM_LIT:2> ] = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> res_t [ <NUM_LIT:3> ] = np . array ( [ [ - <NUM_LIT:1.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> , <NUM_LIT:0.> , - <NUM_LIT:1.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , - <NUM_LIT:1.> , <NUM_LIT:1.> ] ] ) <EOL> res_t [ <NUM_LIT:4> ] = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for ii in range ( <NUM_LIT:5> ) : <EOL> np . testing . assert_equal ( res_cp [ ii ] , res_t [ ii ] , err_msg = str ( ii ) ) <EOL> def test_dummy_limits ( self ) : <EOL> b , e = dummy_limits ( self . d1 ) <EOL> assert_equal ( b , np . array ( [ <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:8> ] ) ) <EOL> assert_equal ( e , np . array ( [ <NUM_LIT:4> , <NUM_LIT:8> , <NUM_LIT:12> ] ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> tt = TestContrastTools ( ) <EOL> tt . test_contrast_product ( ) <EOL> tt . test_dummy_1d ( ) <EOL> tt . test_dummy_limits ( ) <EOL> import statsmodels . api as sm <EOL> examples = [ '<STR_LIT>' , '<STR_LIT>' , None ] [ <NUM_LIT:1> ] <EOL> v1name = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> v2name = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> res_cp = contrast_product ( v1name , v2name ) <EOL> print ( res_cp ) <EOL> y = np . arange ( <NUM_LIT:12> ) <EOL> x1 = np . arange ( <NUM_LIT:12> ) // <NUM_LIT:4> <EOL> x2 = np . arange ( <NUM_LIT:12> ) // <NUM_LIT:2> % <NUM_LIT:2> <EOL> if '<STR_LIT>' in examples : <EOL> d1 , d1_labels = dummy_1d ( x1 ) <EOL> d2 , d2_labels = dummy_1d ( x2 ) <EOL> if '<STR_LIT>' in examples : <EOL> x1 = np . repeat ( x1 , <NUM_LIT:5> , axis = <NUM_LIT:0> ) <EOL> x2 = np . repeat ( x2 , <NUM_LIT:5> , axis = <NUM_LIT:0> ) <EOL> nobs = x1 . shape [ <NUM_LIT:0> ] <EOL> d1 , d1_labels = dummy_1d ( x1 ) <EOL> d2 , d2_labels = dummy_1d ( x2 ) <EOL> dd_full = dummy_product ( d1 , d2 , method = '<STR_LIT>' ) <EOL> dd_dropl = dummy_product ( d1 , d2 , method = '<STR_LIT>' ) <EOL> dd_dropf = dummy_product ( d1 , d2 , method = '<STR_LIT>' ) <EOL> print ( ( np . dot ( dd_full . T , dd_full ) == np . diag ( dd_full . sum ( <NUM_LIT:0> ) ) ) . all ( ) ) <EOL> effect_size = [ <NUM_LIT:1.> , <NUM_LIT> ] [ <NUM_LIT:1> ] <EOL> noise_scale = [ <NUM_LIT> , <NUM_LIT:0.1> ] [ <NUM_LIT:0> ] <EOL> noise = noise_scale * np . random . randn ( nobs ) <EOL> beta = effect_size * np . arange ( <NUM_LIT:1> , <NUM_LIT:7> ) <EOL> ydata_full = ( dd_full * beta ) . sum ( <NUM_LIT:1> ) + noise <EOL> ydata_dropl = ( dd_dropl * beta ) . sum ( <NUM_LIT:1> ) + noise <EOL> ydata_dropf = ( dd_dropf * beta ) . sum ( <NUM_LIT:1> ) + noise <EOL> resols_full_full = sm . OLS ( ydata_full , dd_full ) . fit ( ) <EOL> resols_full_dropf = sm . OLS ( ydata_full , dd_dropf ) . fit ( ) <EOL> params_f_f = resols_full_full . params <EOL> params_f_df = resols_full_dropf . params <EOL> resols_dropf_full = sm . OLS ( ydata_dropf , dd_full ) . fit ( ) <EOL> resols_dropf_dropf = sm . OLS ( ydata_dropf , dd_dropf ) . fit ( ) <EOL> params_df_f = resols_dropf_full . params <EOL> params_df_df = resols_dropf_dropf . params <EOL> tr_of = np . linalg . lstsq ( dd_dropf , dd_full ) [ <NUM_LIT:0> ] <EOL> tr_fo = np . linalg . lstsq ( dd_full , dd_dropf ) [ <NUM_LIT:0> ] <EOL> print ( np . dot ( tr_fo , params_df_df ) - params_df_f ) <EOL> print ( np . dot ( tr_of , params_f_f ) - params_f_df ) <EOL> transf_f_df = DummyTransform ( dd_full , dd_dropf ) <EOL> print ( np . max ( np . abs ( ( dd_full - transf_f_df . inv_dot_right ( dd_dropf ) ) ) ) ) <EOL> print ( np . max ( np . abs ( ( dd_dropf - transf_f_df . dot_right ( dd_full ) ) ) ) ) <EOL> print ( np . max ( np . abs ( ( params_df_df <EOL> - transf_f_df . inv_dot_left ( params_df_f ) ) ) ) ) <EOL> np . max ( np . abs ( ( params_f_df <EOL> - transf_f_df . inv_dot_left ( params_f_f ) ) ) ) <EOL> prodlab , C1 , C1lab , C2 , C2lab , _ = contrast_product ( v1name , v2name ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( C1lab ) <EOL> print ( resols_dropf_full . t_test ( C1 ) . tvalue ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( C2lab ) <EOL> print ( resols_dropf_full . t_test ( C2 ) . tvalue ) <EOL> resols_dropf_full . cov_params ( C2 ) <EOL> R_noint = np . hstack ( ( np . zeros ( ( <NUM_LIT:2> , <NUM_LIT:4> ) ) , np . eye ( <NUM_LIT:2> ) ) ) <EOL> inter_direct = resols_full_dropf . tvalues [ - <NUM_LIT:2> : ] <EOL> inter_transf = resols_full_full . t_test ( transf_f_df . inv_dot_right ( R_noint ) ) . tvalue <EOL> print ( np . max ( np . abs ( ( inter_direct - inter_transf ) ) ) ) <EOL> tw = TwoWay ( ydata_dropf , x1 , x2 ) <EOL> print ( tw . ttest_interaction ( ) . tvalue ) <EOL> print ( tw . ttest_interaction ( ) . pvalue ) <EOL> print ( tw . ftest_interaction ( ) . fvalue ) <EOL> print ( tw . ftest_interaction ( ) . pvalue ) <EOL> print ( tw . ttest_conditional_effect ( <NUM_LIT:1> ) [ <NUM_LIT:0> ] . tvalue ) <EOL> print ( tw . ttest_conditional_effect ( <NUM_LIT:2> ) [ <NUM_LIT:0> ] . tvalue ) <EOL> print ( tw . summary_coeff ( ) ) <EOL> '''<STR_LIT>''' <EOL> '''<STR_LIT>''' </s>
