How to produce a multiple linear fittings for scatter plot?

1 Ansicht (letzte 30 Tage)
Naveed Hossain
Naveed Hossain am 19 Aug. 2018
Kommentiert: Jeff Miller am 20 Aug. 2018
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.

Antworten (1)

Jeff Miller
Jeff Miller am 20 Aug. 2018
Bearbeitet: Jeff Miller am 20 Aug. 2018
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 Kommentare
Naveed Hossain
Naveed Hossain am 20 Aug. 2018
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 am 20 Aug. 2018
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by