def repanel_cov(groups, sigmas):
 if (groups.ndim == 1):
  groups = groups[:, None]
 (nobs, nre) = groups.shape
 omega = (sigmas[(-1)] * np.eye(nobs))
 for igr in range(nre):
  group = groups[:, igr:(igr + 1)]
  groupuniq = np.unique(group)
  dummygr = (sigmas[igr] * (group == groupuniq).astype(float))
  omega += np.dot(dummygr, dummygr.T)
 (ev, evec) = np.linalg.eigh(omega)
 omegainv = np.dot(evec, ((1 / ev) * evec).T)
 omegainvhalf = (evec / np.sqrt(ev))
 return (omega, omegainv, omegainvhalf)

def repanel_cov ( groups , sigmas ) : if ( groups . ndim == 1 ) : groups = groups [ : , None ] ( nobs , nre ) = groups . shape omega = ( sigmas [ ( - 1 ) ] * np . eye ( nobs ) ) for igr in range ( nre ) : group = groups [ : , igr : ( igr + 1 ) ] groupuniq = np . unique ( group ) dummygr = ( sigmas [ igr ] * ( group == groupuniq ) . astype ( float ) ) omega += np . dot ( dummygr , dummygr . T ) ( ev , evec ) = np . linalg . eigh ( omega ) omegainv = np . dot ( evec , ( ( 1 / ev ) * evec ) . T ) omegainvhalf = ( evec / np . sqrt ( ev ) ) return ( omega , omegainv , omegainvhalf )
calculate error covariance matrix for random effects model parameters groups : array .