How to produce a multiple linear fittings for scatter plot?

조회 수: 3 (최근 30일)
Naveed Hossain
Naveed Hossain 2018년 8월 19일
댓글: Jeff Miller 2018년 8월 20일
I would like to know how to produce a graph that shows the impact on linear fitting, when removing some data from the original data set.
For example, if I initially had 30 coordinates and I removed 3, the linear fitting would change. The next iteration would then be choosing a different 3 coordinates to remove from initial 30 to show a different linear fitting.
I have attached an image to demonstrate what I mean. The blue is the original linear fitting. The red line (using MS Paint) are the different linear fittings when removing coordinates.
Ideally, I am trying to show all possible combinations of removing 3 coordinates out of 30.

답변 (1개)

Jeff Miller
Jeff Miller 2018년 8월 20일
편집: Jeff Miller 2018년 8월 20일
It's not entirely clear what you have so far or what part you are having trouble with, but it sounds like you may want something like this:
subsamples = nchoosek(1:30,27); % Generate all possible subsets of 27 out of 30 coordinates
nsubsamples = size(subsamples,1); % quite a lot!
for isample = 1:nsubsamples
subsamplex = fullsamplex(subsamples(isample,:));
subsampley = fullsampley(subsamples(isample,:));
% Fit the linear model to the two subsamples, eg with fitlm.
% Use the estimated parameters of the linear fit to compute
% two points on the line for this fit, say (fitx1, fity1) and (fitx2,fity2)
plot([fitx1 fitx2],[fity1 fity2]);
end
  댓글 수: 2
Naveed Hossain
Naveed Hossain 2018년 8월 20일
I would initially have 30 coordinates ie. 30 'x' values and 30 'y' values. So basically a table of 2 columns
Jeff Miller
Jeff Miller 2018년 8월 20일
OK, lets call that table 'tbl' with columns tbl.X and tbl.Y. Each row of subsamples indicates the 27 rows of tbl that you want for the current subsample. So something like this should work:
subsamplex = tbl.X(subsamples(isample,:));
etc

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by