Interpretations of gamma-ray burst spectroscopy. I. Analytical and numerical study of spectral lags