fitlm works but polyfit does not work

5 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2020 年 12 月 6 日
コメント済み: Ameer Hamza 2020 年 12 月 6 日
I run polyfit and fitlm for the same data. fitlm provides an output. But polyfit and corrcoef return NaN. How can it be?
  1 件のコメント
Catalytic
Catalytic 2020 年 12 月 6 日
Who knows? You've provided no means for us to reproduce what you see.

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 6 日
編集済み: Ameer Hamza 2020 年 12 月 6 日
There is probably NaN somewhere in your dataset. fitlm() ignores those data values. For example
x = linspace(0, 1, 10);
y = 2*x + 3 + rand(size(x));
y(3) = nan;
p = polyfit(x, y, 1)
c = corrcoef(y)
ft = fitlm(x, y)
Result
>> p
p =
NaN NaN
>> c
c =
NaN
>> ft
ft =
Linear regression model:
y ~ 1 + x1
Estimated Coefficients:
Estimate SE tStat pValue
________ _______ ______ __________
(Intercept) 3.1773 0.13254 23.973 5.5901e-08
x1 2.3847 0.21348 11.17 1.0268e-05
Number of observations: 9, Error degrees of freedom: 7
Root Mean Squared Error: 0.206
R-squared: 0.947, Adjusted R-Squared: 0.939
F-statistic vs. constant model: 125, p-value = 1.03e-05
  2 件のコメント
alpedhuez
alpedhuez 2020 年 12 月 6 日
Thank you.
Ameer Hamza
Ameer Hamza 2020 年 12 月 6 日
I am glad to be of help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResampling Techniques についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by