Local Regression 2D

Local Regression for 2D Data with plot/figure

You are now following this Submission

This function will perform a local regression at the given points. Using the data at hand. You will need to input a spanwidth which will tell the function how many datapoints he will use in the local regression at each evaluation.

Example Code

X=-5:0.05:10;
X=X';
y=2*X-X.^2;
y=y+normrnd(0,2,size(y));
scatter(X,y)
X0=X;
robust=1;
spanwidth=0.4
X0=[-5:0.1:10]';

[eps]=MLR(X,y,spanwidth,X0,robust)

Assumption for use local Regression
The underlying function between y and X is continues and has a 1st derivative at any point.

Explanation
X= 1 column vector with data points
y= 1 column vector with data points
spanwidth= number between 0 and 1
X0= column vector specifying the points that you want to be evaluated
robust= either 0 or 1
( if you choose 1 then robust version is used )

Plot explanation
-The straight blue line is the local regression approximation at a certain point
- The green points are used for local regression
- The Red points are left out
- The blue dot in middle of blue line is the current point .

Please leave a comment with your opinion

Cite As

Arnout Tilgenkamp (2026). Local Regression 2D (https://www.mathworks.com/matlabcentral/fileexchange/28551-local-regression-2d), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.1.0.0

The output is now the estimated Y values instead of eps

1.0.0.0