How to produce a multiple linear fittings for scatter plot?

1 次查看(过去 30 天)
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