I think that this function should re-use or improve nipy.algorithms.statistics.mixed_effects instead of duplicating it.