<s> '''<STR_LIT>''' <EOL> from statsmodels . compat . python import iterkeys , zip <EOL> import string <EOL> import numpy as np <EOL> from statsmodels . sandbox import formula <EOL> from statsmodels . sandbox import contrast_old as contrast <EOL> X = np . random . standard_normal ( ( <NUM_LIT> , <NUM_LIT:10> ) ) <EOL> namespace = { } <EOL> terms = [ ] <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> name = '<STR_LIT:%s>' % string . uppercase [ i ] <EOL> namespace [ name ] = X [ : , i ] <EOL> terms . append ( formula . Term ( name ) ) <EOL> form = terms [ <NUM_LIT:0> ] <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:10> ) : <EOL> form += terms [ i ] <EOL> form . namespace = namespace <EOL> form . design ( ) . shape <EOL> ( <NUM_LIT> , <NUM_LIT:10> ) <EOL> '''<STR_LIT>''' <EOL> print ( form . hasterm ( '<STR_LIT:C>' ) ) <EOL> print ( form . termcolumns ( formula . Term ( '<STR_LIT:C>' ) ) ) <EOL> f2 = ( form [ '<STR_LIT:A>' ] + form [ '<STR_LIT:B>' ] ) <EOL> print ( f2 ) <EOL> print ( repr ( f2 ) ) <EOL> list ( iterkeys ( f2 . namespace ) ) <EOL> f2 . namespace = namespace <EOL> iterkeys ( f2 . namespace ) <EOL> f2 . design ( ) . shape <EOL> contrast . Contrast ( formula . Term ( '<STR_LIT:A>' ) , f2 ) . matrix <EOL> '''<STR_LIT>''' <EOL> f3 = ( form [ '<STR_LIT:A>' ] * form [ '<STR_LIT:B>' ] ) <EOL> f3 . namespace <EOL> f3 . namespace = namespace <EOL> f3 . design ( ) . shape <EOL> np . min ( np . abs ( f3 . design ( ) - f2 . design ( ) . prod ( <NUM_LIT:1> ) ) ) <EOL> '''<STR_LIT>''' <EOL> f4 = formula . interactions ( [ form [ '<STR_LIT:A>' ] , form [ '<STR_LIT:B>' ] ] ) <EOL> f4 . namespace <EOL> f4 . namespace = namespace <EOL> print ( f4 ) <EOL> f4 . names ( ) <EOL> f4 . design ( ) . shape <EOL> contrast . Contrast ( formula . Term ( '<STR_LIT:A>' ) , f4 ) . matrix <EOL> '''<STR_LIT>''' <EOL> '''<STR_LIT>''' <EOL> f = [ '<STR_LIT:a>' ] * <NUM_LIT:3> + [ '<STR_LIT:b>' ] * <NUM_LIT:3> + [ '<STR_LIT:c>' ] * <NUM_LIT:2> <EOL> fac = formula . Factor ( '<STR_LIT>' , f ) <EOL> fac . namespace = { '<STR_LIT>' : f } <EOL> f5 = formula . Term ( '<STR_LIT:A>' ) + fac <EOL> namespace [ '<STR_LIT:A>' ] = form . namespace [ '<STR_LIT:A>' ] <EOL> formula . Formula ( fac ) . design ( ) <EOL> '''<STR_LIT>''' <EOL> f7 = formula . Formula ( fac ) <EOL> f7 . namespace . update ( dict ( zip ( fac . names ( ) , fac ( ) ) ) ) <EOL> contrast . Contrast ( formula . Term ( '<STR_LIT>' ) + formula . Term ( '<STR_LIT>' ) , f7 ) . matrix <EOL> contrast . Contrast ( f7 , f7 ) . matrix <EOL> contrast . Contrast ( formula . Term ( '<STR_LIT>' ) + formula . Term ( '<STR_LIT>' ) , f7 ) . matrix - contrast . Contrast ( formula . Term ( '<STR_LIT>' ) , f7 ) . matrix <EOL> cont = [ ] <EOL> for i , j in zip ( * np . triu_indices ( len ( f7 . names ( ) ) , <NUM_LIT:1> ) ) : <EOL> ci = contrast . Contrast ( formula . Term ( f7 . names ( ) [ i ] ) , f7 ) . matrix <EOL> ci -= contrast . Contrast ( formula . Term ( f7 . names ( ) [ j ] ) , f7 ) . matrix <EOL> cont . append ( ci ) <EOL> cont = np . array ( cont ) <EOL> cont </s>
