Have you maybe considered using the RCaller transformer? You could perhaps use the CoordinateExtractor to convert the points to X/Y values, group them with the Aggregator and then do the regression analysis in the RCaller, outputting the resulting line vertices as attributes. It's then fairly simple to build the corresponding line in FME again.
@hrinze we created several RCaller examples on FME Hub and also the tutorial on RCaller includes a couple of simple examples. It seems a little intimidating to get started with R, but with a few examples and so many online resources you should be able to get success
@hrinze we created several RCaller examples on FME Hub and also the tutorial on RCaller includes a couple of simple examples. It seems a little intimidating to get started with R, but with a few examples and so many online resources you should be able to get success
To add a bit of detail - the lm function from the stats package could work for this. There are a few specific points about using linear regression for spatial data. See this discussion on StackExchange for details. It has a python solution using arcpy that could work as well. The key points are:
- Using linear regression will bias your results towards x or y slightly; an average squared perpendicular distance method is technically more accurate. Linear regression should be good enough in most cases - though if planes are landing based on the results, you might need to be precise!
- The results of a linear regression model are not points, but values a (intercept) and b (slope), so of course your results are actually an infinite line. You can use the min and max values of x and y (BoundingBoxAccumulator in FME, min() and max() functions in R) to restrict the length of the line. You can then generate the values for the points using the linear regression formula y = ax + b. You can do that from the results of an lm model by accessing the coefficients (see e.g. here). Use the RCaller to generate the points of the line, then use a VertexCreator and LineBuilder in FME to build the line.
That just sketches out the basic solution. Good luck!
@hrinze we created several RCaller examples on FME Hub and also the tutorial on RCaller includes a couple of simple examples. It seems a little intimidating to get started with R, but with a few examples and so many online resources you should be able to get success
Didnt manage to get it work smooth with RCaller so ended up with a least square regression in python. But thanks for great input
Didnt manage to get it work smooth with RCaller so ended up with a least square regression in python. But thanks for great input
You are welcome. I'm glad you found a solution.
Didnt manage to get it work smooth with RCaller so ended up with a least square regression in python. But thanks for great input
hi @hrinze
did you use sklearn.linear_model? and if so did you have to redirect to your own version of python to install it? I have to do something similar and without web access so if there was a module that came with the installation that could do regression lines it would make my job much easier. thanks for your time.
Didnt manage to get it work smooth with RCaller so ended up with a least square regression in python. But thanks for great input
Have you tried the Generalizer transformer first?
@hrinze There are good examples of different stats tools on the FME HUB (hard to search for 'R'!), summarized in this blog: Statistical Analysis via FME Hub Transformers based on R-rrr!