How to find the points furthest from a linear regression line?

5 ビュー (過去 30 日間)
Moira Pryhoda
Moira Pryhoda 2017 年 5 月 8 日
編集済み: Roger Stafford 2017 年 5 月 8 日
I have fit a linear regression to a set of data that oscillates back and forth over the regression line. I'd like to find the points furthest from the regression line. How should I go about this?

回答 (2 件)

Roger Stafford
Roger Stafford 2017 年 5 月 8 日
編集済み: Roger Stafford 2017 年 5 月 8 日
If by “furthest” you mean furthest in a direction orthogonal, (rather than vertical,) to your regression line, then do the following. Suppose your line of regression has the equation y = m*x+b and X and Y are x and y coordinate vectors of your data set.
[d,ix] = max(abs(Y-m*X-b));
d = d/sqrt(1+m^2);
Then (X(ix),Y(ix)) is the data point having the greatest distance and that distance is d.

Walter Roberson
Walter Roberson 2017 年 5 月 8 日
polyval() the project the position of the line at the points. Then you can take the distance between the actual data and the projected data, and find the furthest points.
pointdist = abs(y - polyval(Coeffs, x));
[~, furthest_point_idx]] = max(pointdist);
far_points_idx = find(pointdist > some_cutoff);

カテゴリ

Help Center および File ExchangeRegression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by