Computationally efficient methods for fitting mixed models to electronic health records data