merged in regress_motion.py from statsmodels branch