def test_interactions(self): f = formula.interactions([formula.Term(l) for l in ['a', 'b', 'c']]) assert_equal(set(f.termnames()), set(['a', 'b', 'c', 'a*b', 'a*c', 'b*c'])) f = formula.interactions( [formula.Term(l) for l in ['a', 'b', 'c', 'd']], order=3) assert_equal( set(f.termnames()), set([ 'a', 'b', 'c', 'd', 'a*b', 'a*c', 'a*d', 'b*c', 'b*d', 'c*d', 'a*b*c', 'a*c*d', 'a*b*d', 'b*c*d' ])) f = formula.interactions( [formula.Term(l) for l in ['a', 'b', 'c', 'd']], order=[1, 2, 3]) assert_equal( set(f.termnames()), set([ 'a', 'b', 'c', 'd', 'a*b', 'a*c', 'a*d', 'b*c', 'b*d', 'c*d', 'a*b*c', 'a*c*d', 'a*b*d', 'b*c*d' ])) f = formula.interactions( [formula.Term(l) for l in ['a', 'b', 'c', 'd']], order=[3]) assert_equal(set(f.termnames()), set(['a*b*c', 'a*c*d', 'a*b*d', 'b*c*d']))
def test_interactions(self): f = formula.interactions([formula.Term(l) for l in ['a', 'b', 'c']]) assert_equal(set(f.termnames()), set(['a', 'b', 'c', 'a*b', 'a*c', 'b*c'])) f = formula.interactions([formula.Term(l) for l in ['a', 'b', 'c', 'd']], order=3) assert_equal(set(f.termnames()), set(['a', 'b', 'c', 'd', 'a*b', 'a*c', 'a*d', 'b*c', 'b*d', 'c*d', 'a*b*c', 'a*c*d', 'a*b*d', 'b*c*d'])) f = formula.interactions([formula.Term(l) for l in ['a', 'b', 'c', 'd']], order=[1,2,3]) assert_equal(set(f.termnames()), set(['a', 'b', 'c', 'd', 'a*b', 'a*c', 'a*d', 'b*c', 'b*d', 'c*d', 'a*b*c', 'a*c*d', 'a*b*d', 'b*c*d'])) f = formula.interactions([formula.Term(l) for l in ['a', 'b', 'c', 'd']], order=[3]) assert_equal(set(f.termnames()), set(['a*b*c', 'a*c*d', 'a*b*d', 'b*c*d']))
def test_subtract(self): f = formula.interactions([formula.Term(l) for l in ['a', 'b', 'c']]) ff = f - f['a*b'] assert_equal(set(ff.termnames()), set(['a', 'b', 'c', 'a*c', 'b*c'])) ff = f - f['a*b'] - f['a*c'] assert_equal(set(ff.termnames()), set(['a', 'b', 'c', 'b*c'])) ff = f - (f['a*b'] + f['a*c']) assert_equal(set(ff.termnames()), set(['a', 'b', 'c', 'b*c']))
>>> f3 = (form['A']*form['B']) >>> f3.namespace {} >>> f3.namespace = namespace >>> f3.design().shape (40,) >>> np.min(np.abs(f3.design() - f2.design().prod(1))) 0.0 ''' #Example: Interactions of two terms #---------------------------------- #I don't get contrast of product term f4 = formula.interactions([form['A'], form['B']]) f4.namespace f4.namespace = namespace print(f4) f4.names() f4.design().shape contrast.Contrast(formula.Term('A'), f4).matrix #contrast.Contrast(formula.Term('A*B'), f4).matrix ''' >>> formula.interactions([form['A'],form['B']]) <statsmodels.sandbox.formula.Formula object at 0x033E8EB0> >>> f4 = formula.interactions([form['A'],form['B']]) >>> f4.namespace {} >>> f4.namespace = namespace
>>> f3 = (form['A']*form['B']) >>> f3.namespace {} >>> f3.namespace = namespace >>> f3.design().shape (40,) >>> np.min(np.abs(f3.design() - f2.design().prod(1))) 0.0 ''' #Example: Interactions of two terms #---------------------------------- #I don't get contrast of product term f4 = formula.interactions([form['A'],form['B']]) f4.namespace f4.namespace = namespace print f4 f4.names() f4.design().shape contrast.Contrast(formula.Term('A'), f4).matrix #contrast.Contrast(formula.Term('A*B'), f4).matrix ''' >>> formula.interactions([form['A'],form['B']]) <statsmodels.sandbox.formula.Formula object at 0x033E8EB0> >>> f4 = formula.interactions([form['A'],form['B']]) >>> f4.namespace {}