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.
0 个评论
回答(1 个)
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 个评论
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 Center 和 File 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!