Function Repository Resource:

# LineFit

Fit a line to data points in n-dimensional space

Contributed by: Sander Huisman
 ResourceFunction["LineFit"][pts] returns a Line that fits best through the points pts. ResourceFunction["LineFit"][pts,"Association"] returns an Association containing properties of the best fit line.

## Details

The returned function in the Association will correspond to a domain of 0 to 1.
The best fit is determined by minimizing the sum of squares of distances from the points to the best-fit line.

## Examples

### Basic Examples (2)

Fit a line in 2D:

 In[1]:=
 Out[1]=

Compare the points and the fit:

 In[2]:=
 Out[2]=

### Scope (2)

Do a fit with points in 3D:

 In[3]:=
 Out[3]=

Get a Dataset with all the fitting details:

 In[4]:=
 Out[4]=

### Properties and Relations (2)

Compare the result of LineFit with the result of computing the orthogonal fit through the definition:

 In[5]:=
 In[6]:=
 Out[6]=
 In[7]:=
 Out[7]=

The one-argument case of LineFit is equivalent to the resource function OrthogonalLineFit:

 In[8]:=
 In[9]:=
 Out[9]=
 In[10]:=
 Out[10]=

### Possible Issues (3)

All points have to be numeric:

 In[11]:=
 Out[11]=

All points have to be in the same dimension:

 In[12]:=
 Out[12]=

Real numbers have to be used:

 In[13]:=
 Out[13]=

### Neat Examples (1)

Do a fit in 10D:

 In[14]:=
 Out[14]=

SHuisman

## Version History

• 2.0.0 – 25 May 2021