Partitioning a 2D space for piecewise regression.
Piecewise regression is a common technique dealing with non-stationary (varying coefficient) linear model of dependent-independent variables. There have been many methods dealing with input space segmentation for building piecewise regression models, e.g., treed model, dynamic programming for the fixed design segmented regression. However, there is a lack of methods specifically dealing with 2D-spatial partition-wise regression. This post adopts a greedy merging algorithm that efficiently and automatically detects the change-points (boundaries) of the spatially piecewise relationship. The algorithm borrows ideas from a paper ‘Fast Algorithms for Segmented Regression’ and a GitHub repository DataDog/piecewise.
Input: 2D spatially distributed independent variables at spatial locations , and corresponding dependent variable .
Output: a 2D space is partitioned into regions: , which have different regression models.
Make an initial segmentation of the 2D space, e.g., partition the space into multiple uniform rectangle grids. Fit a linear model within each region, and calculate the summation of the fitting errors of all regions, e.g., the sum of squared errors, ;
Iterate the following two steps until or the number of regions reduced to one:
Note that is the number of iterations. is a predetermined threshold, e.g., . is the sum of squared errors and can be replaced with other metrics, such as the sum of absolute errors.
The Matlab code of the algorithm and an example can be found in GitHub@jay15summer.
To demonstrate the effectiveness of the above algorithm, a simulation case study was made.
spatial_partition_reg
and its descriptions can be found in GitHub@jay15summer):In many situations, the change of the relationship of independent-dependent variables has no clear spatial boundaries. Under such conditions, the piecewise assumption is violated, and the algorithm may not result in good partitioning. To deal with such problem, local models can be applied instead, such as geographically weighted regression (GWR) model (refer to http://gwr.maynoothuniversity.ie/ or GWR-in-ArcGIS).