Negative R² when computing statistics in regress-function

I'm using the regress function to calculate the regression factor and would like to take a look at the R².
[b,bint,r,rint,stats] = regress(y,X)
Stats should provide the R² and other statistical values. In my case R² is negative, which makes no sense for me. The help tells me "When computing statistics, X should include a column of 1s so that the model contains a constant term."
I don't know how this should look like...my data are just 2 columns. Should I just add an extra column in X with only 1s?? Does someone know what this means and why I have to do that?!
Thanks for any help, Andreas

 採用された回答

the cyclist
the cyclist 2015 年 8 月 20 日

0 投票

I assume you are trying to fit a model of the form
y = a + b*X
If you think of this as fitting
y = a * 1 + b*X
then you will see how MATLAB is thinking about that columns of 1's. So, you want your input to be of the form
X = [ones(N,1) your_actual_X(N,1)]
to get sensible output from regress.

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by