Laird’s contribution was to make longitudinal dependence a modeling target rather than a nuisance. Repeated observations on the same unit are correlated because they share latent subject-level effects. A simple random-intercept version is
Define \(V(\sigma_u,\sigma_\varepsilon)\) and estimate the two variance components by profiling out \(\beta\).
def nll(theta): su, se = np.exp(theta) V = su**2* (Z @ Z.T) + se**2* np.eye(len(y)) c, low = linalg.cho_factor(V) Vinv =lambda a: linalg.cho_solve((c, low), a) beta = linalg.solve(X.T @ Vinv(X), X.T @ Vinv(y)) r = y - X @ betareturn0.5* (2* np.log(np.diag(c)).sum() + r @ Vinv(r))su, se = np.exp(optimize.minimize(nll, np.log([0.6, 0.4])).x)su, se