added a function for computing trends