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!