Posted by Ryan Roper
Recently, a customer contacted me to ask how to estimate parameters of a best-fit trend line for data stored in a Time Series element. The solution had to be sufficiently generic for multiple data sets and the fitting had to occur at the beginning of a simulation so that the parameters could be used for forecasting. The first solution I proposed used a SubModel with the optimization capability enabled. This worked well for a few data sets, but the solution needed to be scaled up to work efficiently for dozens of data sets on a single run. By the time I had implemented the approach for 10 data sets, I could see that the run time was going to be too long.
Since we had a known equation to fit to the data, I decided to implement a solution using the Gauss-Newton algorithm, an iterative nonlinear least-squares method for fitting trend lines to data (see Gauss-Newton Algorithm). This solution dramatically reduced the computation time and still gave great results. Since I think this solution could be of interest to many users in a variety of application areas, I put together a nice example model and posted it to our model library: Gauss-Newton Trend Line Fitting. In this blog post, I describe the implementation and show some results.