R-square and the F statistic... error

2 ビュー (過去 30 日間)
Asliddin Komilov
Asliddin Komilov 2022 年 5 月 3 日
コメント済み: Walter Roberson 2022 年 5 月 5 日
Hi everyone, I am getting this error for the each line (Warning: R-square and the F statistic are not well-defined unless X has a column of ones.).
I have looked up other similar questions but couldn't use the solutions for my case. Help if you can please. Thanks.
for r=1:size(Sun,1)
[~,~,~,~,STATNm(r,:)]=regress(Sun(r,:)',MHL(r,:)');
[~,~,~,~,STATNc(r,:)]=regress(Sun(r,:)',LComb(r,:)');
[~,~,~,~,STATSm(r,:)]=regress(Ssun(r,:)',Sm(r,:)');
[~,~,~,~,STATSc(r,:)]=regress(Ssun(r,:)',CLS2(r,:)');
[~,~,~,~,STATSml(r,:)]=regress(Nsun(r,:)',Nml(r,:)');
[~,~,~,~,STATSlc(r,:)]=regress(Nsun(r,:)',Nlc(r,:)');
end
Rsq=[STATNm(:,1) STATNc(:,1) STATSm(:,1) STATSc(:,1) STATSml(:,1) STATSlc(:,1)]';

採用された回答

Walter Roberson
Walter Roberson 2022 年 5 月 3 日
MHL(r, :) is a row. You transpose it to a column and pass it as the second parameter to regress(). That is a column vector, not a 2d matrix.
As it only has one column, we can be sure that there is no trailing column of 1's. But having a column of 1's is needed for regression to work properly, since it is needed to estimate the constant term.
  2 件のコメント
Asliddin Komilov
Asliddin Komilov 2022 年 5 月 4 日
OK, so shall I make MHL(r, :) into a 2d matrix with ones in the first column?
Walter Roberson
Walter Roberson 2022 年 5 月 4 日
Whether you put the ones as the first column or the second column does not matter, other than it will switch the order of the results, with the intercept going into whichever column has the ones.

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

その他の回答 (1 件)

Asliddin Komilov
Asliddin Komilov 2022 年 5 月 4 日
編集済み: Asliddin Komilov 2022 年 5 月 4 日
Thanks, it seems I got rid of the warning but have another one: "Warning: X is rank deficient to within machine precision. "
Any idea what I shall do now? Thanks.
Cones1=ones(size(Sun,2),1);
Cones2=ones(size(Ssun,2),1);
for r=1:size(Sun,1)
[~,~,~,~,STATNm(r,:)]=regress(Sun(r,:)',[Cones1 MHL(r,:)']);
[~,~,~,~,STATNc(r,:)]=regress(Sun(r,:)',[Cones1 LComb(r,:)']);
[~,~,~,~,STATSm(r,:)]=regress(Ssun(r,:)',[Cones2 Sm(r,:)']);
[~,~,~,~,STATSc(r,:)]=regress(Ssun(r,:)',[Cones2 CLS2(r,:)']);
[~,~,~,~,STATSml(r,:)]=regress(Nsun(r,:)',[Cones2 Nml(r,:)']);
[~,~,~,~,STATSlc(r,:)]=regress(Nsun(r,:)',[Cones2 Nlc(r,:)']);
end
Rsq=[STATNm(:,1) STATNc(:,1) STATSm(:,1) STATSc(:,1) STATSml(:,1) STATSlc(:,1)]';
  3 件のコメント
Asliddin Komilov
Asliddin Komilov 2022 年 5 月 5 日
I have zeros, shall I make them nans?
Walter Roberson
Walter Roberson 2022 年 5 月 5 日
I do not think 0 itself is a problem, but I think you could have a problem if you you had duplicate rows. If that can happen then I would suggest using unique() by rows, recording the second output as well, and using that second output to index the rows of the other array, using that along with the first output of unique()

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

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by