Esempio n. 1
0
    def test_termcolumns(self):
        t1 = formula.Term("A")
        t2 = formula.Term("B")
        f = t1 + t2 + t1 * t2

        def other(val):
            return np.array([3.2 * val, 4.342 * val**2, 5.234 * val**3])

        q = formula.Quantitative(['other%d' % i for i in range(1, 4)],
                                 termname='other',
                                 func=t1,
                                 transform=other)
        f += q
        q.namespace = f.namespace = self.formula.namespace
        assert_almost_equal(q(), f()[f.termcolumns(q)])
Esempio n. 2
0
if __name__ == '__main__':
    import numpy.random as R
    n = 100
    X = np.array([0]*n + [1]*n)
    b = 0.4
    lin = 1 + b*X
    Y = R.standard_exponential((2*n,)) / lin
    delta = R.binomial(1, 0.9, size=(2*n,))

    subjects = [Observation(Y[i], delta[i]) for i in range(2*n)]
    for i in range(2*n):
        subjects[i].X = X[i]

    import statsmodels.sandbox.formula as F
    x = F.Quantitative('X')
    f = F.Formula(x)

    c = CoxPH(subjects, f)

#    c.cache()
    # temp file cleanup doesn't work on windows
    c = CoxPH(subjects, f, time_dependent=True)
    c.cache() #this creates  tempfile cache,
    # no tempfile cache is created in normal use of CoxPH


    #res = c.newton([0.4])  #doesn't work anymore
    res=c.fit([0.4],method="bfgs")
    print res.params
    print dir(c)
Esempio n. 3
0
 def test_quantitative(self):
     t = self.terms[2]
     sint = formula.Quantitative('t', func=t, transform=np.sin)
     t.namespace = sint.namespace = self.formula.namespace
     assert_almost_equal(np.sin(t()), sint())