Linear Regression - more weight on specific Bins of data

3 views (last 30 days)
Hi, I am sort of new to Matlab and I need to analyze some data on Matlab. What I need to do is; I have a scatter plot (x, y) and I need to do a linear regression on this data in a way that I have more weight on a specific section (or bins)of my x axis.For example, my x axis is from 0 to 45, and i want to make a linear regression of the data so that I have more weight on data between 15 to 40, and less weight on data points above 40. For this I have to BIN my data points to 5 parts, (1 bin < x<15, 2 bins when x between 15 and 40 , and 1 bin when x is higher than 40). How can I do this easily in Matlab. I used polyfit for the linear regression, but how can I modify it to do such a thing. Thanks alot.

Answers (3)

Richard Willey
Richard Willey on 28 Nov 2011
MathWorks tech support has a solution documenting various options for weighted regression.
From my perspective, robustfit provides the most flexibility.

Daniel Shub
Daniel Shub on 28 Nov 2011
I am not sure you can do it easily with polyfit. The cftool and lscov both allow differential weighting.

Michael
Michael on 28 Nov 2011
lsqnonlin may be a good place to start, rather than giving it your model function and a starting point (eg. lsqcurvefit), you give it a function which returns a vector of the residuals of the fit. This way you have the freedom to multiply these residuals by factors based on their corresponding x coordinate- if a residual is multiplied by two, the minimisation scheme in lsqnonlin should work harder to ensure that this point is close to the final curve.

Categories

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!