How to get linear fit standard deviation?

6 ビュー (過去 30 日間)
Adam Cervenka
Adam Cervenka 2018 年 8 月 11 日
コメント済み: David Goodmanson 2018 年 8 月 18 日
After linear fitting I need to get value of standard error. When I use this
A = [x(:),ones(length(x),1)];
[u,std_u] = lscov(A,y(:));
for x=[2550 2450 2352 2256 2162]
for y=[1,93 2,11 2,39 2,44 2,63]
I get right values.
But when I use the same code where
x = [5,13e-19 5,55e-19 5,9e-19 6,370e-19 6,77e-19]
y = [40,40 39,97 39,21 38,67 38,75]
std_u and u value are 0 but they shouldn't be.
Did I use the wrong function? How can I get these values?
  2 件のコメント
Star Strider
Star Strider 2018 年 8 月 11 日
The documentation section on Accuracy of Floating-Point Data (link) might be helpful.
Adam Cervenka
Adam Cervenka 2018 年 8 月 12 日
So what should I do now?

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

採用された回答

David Goodmanson
David Goodmanson 2018 年 8 月 13 日
Hi Adam,
Time to rescale.
S = 1e18; % scale factor to bring x into the same ballpark as the second column of A
x = S*[5.13e-19 5.55e-19 5.9e-19 6.370e-19 6.77e-19];
y = [40.40 39.97 39.21 38.67 38.75];
A = [x(:),ones(length(x),1)];
[u,std_u] = lscov(A,y(:))
u= (rescaled)
-11.1558
46.0310
std_u =
2.0929
1.2499
In terms of the rescaled x you get a good result.
The problem being solved is basically ux = y, or (u/S)(Sx) = y. So for the rescaled problem, u -> u/S.
To get back to the original problem you have to multiply the rescaled u by S. But since only the first column of A was rescaled, only the first element of u and std_u have to be changed. Then
u(1) = -1.1156e+19 (original)
u(2) = 46.0310
std_u(1) = 2.0929e+18
std_u(2) = 1.2499
Lots of scale factors that are within a few powers of 10 of S=1e19 are possible, and they don't change the 'original' results above (by any significant amount). But all in all, it makes at least as much sense to stay with the rescaled problam, because then the elements of u and std_u are of comparable size. I used a scale factor of 1e18 instead of 1e19 because for example if x were in meters, then the rescaled x is in the SI unit of attometers.
  4 件のコメント
Adam Cervenka
Adam Cervenka 2018 年 8 月 14 日
No, but I need values with more decimal places (about ten).
David Goodmanson
David Goodmanson 2018 年 8 月 18 日
You could use 'format long' and get more digits, which are there but not being displayed. However, your inputs x and y appear to only have four significant figures. Unless your x and y are good to many more sig figs than they appear to be (which I guess is possible), any more than four sig figs in the result is unjustified.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFit Postprocessing についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by