Beispiel #1
0
    def __init__(self, units, response, fixed=I, random=I):
        self.units = units
        self.m = len(self.units)
        
        self.fixed = formula(fixed)
        self.random = formula(random)
        self.response = formula(response)

        self.N = 0
        for unit in self.units:
            unit.Y = N.squeeze(unit.design(self.response))
            unit.X = unit.design(self.fixed)
            unit.Z = unit.design(self.random)
            self.N += unit.X.shape[0]

        # Determine size of fixed effects

        d = self.units[0].design(self.fixed)
        self.p = d.shape[1]  # d.shape = p 
        self.a = N.zeros(self.p, N.float64)

        # Determine size of D, and sensible initial estimates
        # of sigma and D        
        d = self.units[0].design(self.random)
        self.q = d.shape[1]  # d.shape = q 

        self.D = N.zeros((self.q,)*2, N.float64)
        self.sigma = 1.

        self.dev = N.inf
Beispiel #2
0
    def test_mul(self):
        t1 = formula.term("t1")
        t2 = formula.term("t2")
        f = t1 * t2
        self.assert_(isinstance(f, formula.formula))

        intercept = formula.term("intercept")
        f = t1 * intercept
        self.assertEqual(str(f), str(formula.formula(t1)))

        f = intercept * t1
        self.assertEqual(str(f), str(formula.formula(t1)))
Beispiel #3
0
 def __call__(self, formula, **extra):
     """
     Return the corresponding design matrix from formula,
     perform a check whether formula just has an intercept in it, in
     which case the number of rows must be computed.
     """
     if hasattr(self, 'n') and not extra.has_key('nrow'):
         extra['nrow'] = self.n
     return formula(namespace=self.dict, **extra)