Latent time-varying factors in longitudinal analysis: a linear mixed hidden Markov model for heart rates