Theory and algorithms for Linear mixed models