Negative R² when computing statistics in regress-function

1 view (last 30 days)
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

Accepted Answer

the cyclist
the cyclist on 20 Aug 2015
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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!