Time series analysis function created