Linear Regression - more weight on specific Bins of data
Show older comments
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
on 28 Nov 2011
2 votes
MathWorks tech support has a solution documenting various options for weighted regression.
From my perspective, robustfit provides the most flexibility.
1 Comment
Daniel Shub
on 28 Nov 2011
+1 nice use of the documentation
Daniel Shub
on 28 Nov 2011
0 votes
I am not sure you can do it easily with polyfit. The cftool and lscov both allow differential weighting.
Michael
on 28 Nov 2011
0 votes
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 Multiple Linear 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!