Confidence band around linear least-squares line

27 ビュー (過去 30 日間)
z8080
z8080 2018 年 4 月 4 日
コメント済み: z8080 2018 年 4 月 5 日
I am using lsline in Matlab 2016b to add a linear least-squares line to a scatter plot. I would like to add a 95% confidence band around that fit line, such that it looks like this (plot is made with the python function seaborn):
However, lsline returns no fit parameters from which to construct the 95% confidence band, and the only Matlab function I could find that does return these, is nlpredci, but that function is used for something else (nonlinear regression prediction)

採用された回答

Star Strider
Star Strider 2018 年 4 月 4 日
One option is the Statistics and Machine Learning Toolbox fitlm (link) function. Then use the predict function (linked at the end of that page).
Another option is to sue polyfit and polyval with the File Exchange polypredci function, or the Statistics and Machine Learning Toolbox polyconf (link) function.
  7 件のコメント
Star Strider
Star Strider 2018 年 4 月 5 日
As always my pleasure.
The width isn’t constant. It may look that way if you use only the original ‘x’ values. However if you use my code (with the ‘xv’ vector) you can easily see that it is not constant, and diverges appropriately from the mean values to the extremes.
It’s not your inexperience. When I plot a nonlinear regression, confidence intervals, or anything else that needs nigher-than normal resolution to depict correctly, I use something like ‘xv’ instead of only using the original *‘x’*values, unless they are sufficiently high resolution. The image you posted appears to have used the same sort of approach.
z8080
z8080 2018 年 4 月 5 日
Makes perfect sense now.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet 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