Estimating covariance functions for longitudinal data using a random regression model