Dynamic empirical Bayes models and their applications to longitudinal data