July 2007
Preparing Experimental Data for Mathcad Analysis: Useful Techniques for Time Series
by Frank Smietana

This article is the fourth in a series that examines specific aspects of real world data set preparation and illustrates the functionality provided in Mathcad to optimally expose the information content of a data set. This article introduces moving averages and detrending, two very effective techniques used to prepare time series data for statistical modeling and forecasting applications.


What Is a Time Series?


A time series associates each data element with a specific point in time. Daily temperature readings, hourly chemical reaction yields, and yearly factory production output are all examples of time series. Engineers and data analysts often concern themselves with predicting (or forecasting) the next data point (or points) in a time series, given some amount of previously collected time/date pairs that can be modeled. The time points are typically, but not necessarily, equidistant. For example the following daily factory output values do not contain data for holidays and weekends:



To make plotting easier, run the data through the following conversion routine:



 

Plotting the data reveals a largely upward trending time series with a fair amount of day-to-day fluctuation:



The upward trend and the fluctuations illustrate two problems you need to address in order to minimize problems when trying to forecast future values of this time series.


Using Moving Averages to Decrease Data Variability


Averaging is a computationally simple way to smooth out data fluctuations in a time series. By removing noise you can expose the true underlying signal. Depending on the span chosen, either high or low periodicity is revealed by the smoothed series. This is extremely helpful when dealing with seasonal data for example.

The following function generates a simple moving average. Specify either "mean" or "med" in the type parameter depending on which statistical moment you decide to use to generate the smoothed series. Note that the first "span-1" elements in the resulting smoothed vector are set to zero, since the moving average requires exactly "span" elements to create one smoothed point.



Now generate two smoothed series, each over a span of 5 days:





Plot the two smoothed series against the original raw data and notice the decrease in day-to-day variability of the smoothed series:




A slightly more complex moving average involves a user-defined weighting scheme to increase the importance of more recent observations relative to older data. Numerous weighting schemes can be defined. As an example, the following method weights the oldest data point fractionally less than the most recent point in the series:

 







Detrending a Time Series


Forecasting algorithms tend to be sensitive to linear trends in your data. At worst, this can lead to blatantly biased forecasts, at best it lowers the accuracy of your forecasts. Differencing your time series data is a simple but very effective tool for removing trend from your data. Like most data-processing tools, detrending must be used judiciously. Practitioners of time series analysis recommend that at most two detrending iterations are employed. Overuse of this powerful technique can easily render your data meaningless. The following function creates a matrix containing the results of successive differencing iterations:




Compare this with the plot of the raw data at the beginning of this article. Notice that the differenced series bear little resemblance to the original time series and that the strong upward trend in the data has been removed.



This article introduced some mathematically simple yet very effective techniques for removing noise and trends from your time series data using Mathcad. In the September article you will learn about additional transformations that can be deployed within Mathcad for optimally exposing time series' information content to modeling and forecasting algorithms.


Right-click, choose Save Target As, and change the extension to XMCD and File Type to All to download Mathcad file (version Mathcad 14).

Was this article interesting? Let us know.





[PRINTER FRIENDLY VERSION]
HOME

Managing Product Development Processes with Windchill 9.0
PTC Updates
Tips of the Month
Knowledge Base Exclusive
Mathcad Methods
Webcasts & Events
Virtual Reality – a Different Approach to Product Development
The Mathcad Calculation Server

Contact PTC | Privacy Policy | PTC Express Archive | Subscribe | Unsubscribe | Change Preferences | Edit Profile

This e-mail was sent to:   PTC, 140 Kendrick Street, Needham, MA 02494 USA
If you are unable to read this page correctly, please click here