Exemple #1
0
 def ols(self, axis):
     y = np.rollaxis(self.y, 0, axis+1) ## time index is axis
     X = self.X
     m = glm(y, X, axis=axis)
     m1 = glm(y, X, axis=axis, method='kalman')
     b = m.beta
     b1 = m1.beta
     tcon = m.contrast([1,0])
     tcon1 = m1.contrast([1,0])
     z = tcon.zscore()
     z1 = tcon1.zscore()
     assert_almost_equal(b, b1)            
Exemple #2
0
def ols(axis, y, X):
    y = np.rollaxis(y, 0, axis+1) ## time index is axis
    X = X
    m = glm(y, X, axis=axis)
    m1 = glm(y, X, axis=axis, method='kalman')
    b = m.beta
    b1 = m1.beta
    v = m.s2
    v1 = m1.s2
    print "Comparing standard OLS with Kalman OLS..."
    re = ( np.abs(b-b1) / (np.abs(b)+1e-20) ).mean()
    print "  Relative difference in Effect estimate: %s" % re
    re = ( np.abs(v-v1) / (np.abs(v)+1e-20) ).mean()
    print "  Relative difference in Variance: %s" % re
    tcon = m.contrast([1,0])
    tcon1 = m1.contrast([1,0])
    z = tcon.zscore()
    z1 = tcon1.zscore()
    re = ( abs(z-z1) / (abs(z)+1e-20) ).mean()
    print "  Relative difference in z score: %s" % re