XtX = sackmat_m.make_zero_matrix(k, k) for i in range(0, k): xi = xs[i] for j in range(i, k): xj = xs[j] xi_dot_xj = sackmat_m.vecdot(xi, xj) XtX[i][j] = xi_dot_xj if i != j: XtX[j][i] = xi_dot_xj # 3. commpute XxT.inv XtXi = XtX.inv() # xxx handle singular ... # 4. commpute XtX.inv Xt y Xt = sackmat_m.sackmat(xs) X = Xt.transpose() beta_hat = XtXi * Xt * y print 'beta_hat: ' print beta_hat print # 5. Estimate eps X_beta_hat = X * beta_hat eps_hat = sackmat_m.vecsub(y, X_beta_hat) #print 'eps_hat ' #print eps_hat #print # 6. Estimate V
def pqmat(p, q): return sackmat_m.sackmat([[p, 1-p],[1-q, q]])