Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find the best fitting line with respect to orthogonal distance
ResourceFunction["OrthogonalLineFit"][data] finds the best fitting orthogonal distance regression line to data. |
Parameters for a 2D line:
In[1]:= | ![]() |
Out[1]= | ![]() |
Generate some points near the line:
In[2]:= | ![]() |
Out[2]= | ![]() |
Find the orthogonal distance regression line:
In[3]:= | ![]() |
Out[3]= | ![]() |
Compare the regression line and the true line with the data:
In[4]:= | ![]() |
Out[4]= | ![]() |
Parameters for a 3D line:
In[5]:= | ![]() |
Out[5]= | ![]() |
Generate some points near the line:
In[6]:= | ![]() |
Out[6]= | ![]() |
Find the orthogonal distance regression line:
In[7]:= | ![]() |
Out[7]= | ![]() |
Compare the regression line and the true line with the data:
In[8]:= | ![]() |
Out[8]= | ![]() |
Here is a list of values:
In[9]:= | ![]() |
When coordinates are not given, OrthogonalLineFit assumes the values are to be paired up with 1,2,…:
In[10]:= | ![]() |
Out[10]= | ![]() |
In[11]:= | ![]() |
Out[11]= | ![]() |
Here is some data:
In[12]:= | ![]() |
This computes the parameters for the orthogonal distance regression line using the definition:
In[13]:= | ![]() |
Out[13]= | ![]() |
Use OrthogonalLineFit to get the best-fit line:
In[14]:= | ![]() |
Out[14]= | ![]() |
Use RegionMember to compare the equations for the best fit line generated by both methods:
In[15]:= | ![]() |
Out[15]= | ![]() |
Construct a function from the orthogonal fit:
In[16]:= | ![]() |
Out[16]= | ![]() |
Compare the orthogonal fit with the conventional least-squares fit:
In[17]:= | ![]() |
Out[17]= | ![]() |
In[18]:= | ![]() |
Out[18]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License