# When is R squared negative?

My understanding is that R squared cannot be negative as it is the square of R. However I ran a simple linear regression in SPSS with a single independent variable and a dependent variable. My SPSS output give me a negative value for R-squared. If I was to calculate this by hand from R then R squared would be positive. What has SPSS done to calculate this as negative?

````R=-.395
R squared =-.156
B (un-standardized)=-1261.611
````

Code I've used:

````DATASET ACTIVATE DataSet1. 
REGRESSION /MISSING LISTWISE /STATISTICS COEFF OUTS R ANOVA 
           /CRITERIA=PIN(.05) POUT(.10) /NOORIGIN 
           /DEPENDENT valueP /METHOD=ENTER ageP
````

I get a negative value. Can anyone explain what this means?

Thanks.

-

3
– whuber♦ Jul 11 '11 at 17:14
Thanks Whuber. Not it doesn't because there seems to be disagreement on whether or not R squared can be negative and I can't how it has calculated R squared as negative. I've edited the above. Please let me know if I need to add more details. Many thanks! – Anne Jul 11 '11 at 17:52
OK. However, you may have been hasty in your reading. The reply to that question by @probabilityislogic begins by saying R squared "cannot be negative," but later on it admits that indeed it "can go negative." Thus there isn't any disagreement. A clear moral is that you need to let us know what procedure is being used to calculate R squared. – whuber♦ Jul 11 '11 at 17:52

2
@Anne Again, which SPSS procedure are you using? – whuber♦ Jul 11 '11 at 18:19

1
@Anne I suggest you disregard the time series reply, because your data are not time series and you're not using a time series procedure. Are you really sure the R squared is given as a negative value? Its magnitude is correct: $(-0.395)^2=0.156$. I have looked through SPSS help to see whether perhaps as a convention the R-squared value for negative R's is negated, but I don't see any evidence that this is the case. Perhaps you could post a screen shot of the output where you are reading the R-squared? – whuber♦ Jul 11 '11 at 20:26
show 10 more comments

## 3 Answers

R2 compares the fit of the chosen model with that of a horizontal straight line (the null hypothesis). If the chosen model fits worse than a horizontal line, then R2 is negative. Note that R2 is not always the square of anything, so it can have a negative value without violating any rules of math. R2 is negative only when the chosen model does not follow the trend of the data, so fits worse than a horizontal line.

Here is an example. We fit data to a linear regression model constrained so that the Y intercept must equal 1500.

The model makes no sense at all given these data. It is clearly the wrong model,perhaps chosen by accident.

The fit of the model (a straight line constrained to go through the point 0,1500) is worse than the fit of a horizontal line. Thus the sum-of-squares from the model (SSreg) is larger than the sum-of-squares from the horizontal line (SStot). R2 is computed as 1 - SSreg/SStot. When SSreg is greater than SStot, that equation computes a negative value for R2.

With linear regression with no constraints, R2 must be positive (or zero) and equals the square of the correlation coefficient, r. A negative R2 is only possible with linear regression when either the intercept or the slope are constrained so that the "best-fit" line (given the constraint) fits worse than a horizontal line. With nonlinear regression, the R2 can be negative whenever the best-fit model (given the chosen equation, and its constraints, if any) fits the data worse than a horizontal line.

Bottom line: A negative R2 is not a mathematical impossibility or the sign of a computer bug. It simply means that the chosen model (with its constraints) fits the data really poorly.

-
This is a nice illustration of the point made by @jefflovejapan. Where in the SPSS command is such a constraint specified? – whuber♦ Jul 13 '11 at 15:48
@whuber I think /NOORIGIN sets the intercept to 0. – JMS Jul 13 '11 at 18:00

2
– whuber♦ Jul 13 '11 at 18:13

3
@whuber Correct. @harvey-motulsky A negative R^2 value is a mathematical impossibility (and suggests a computer bug) for regular OLS regression (with an intercept). This is what the 'REGRESSION' command does and what the original poster is asking about. Also, for OLS regression, R^2 is the squared correlation between the predicted and the observed values. Hence, it must be non-negative. For simple OLS regression with one predictor, this is equivalent to the squared correlation between the predictor and the dependent variable -- again, this must be non-negative. – Wolfgang Jul 14 '11 at 7:17

1
@HarveyMotulsky, in this case the intercept or slope were not constrained. It seems that you are saying that Rsquared can only be negative if these are constrained. Can you elaborate on what might have occurred in this particular case? – Anne Jul 16 '11 at 21:56
show 4 more comments

Have you forgotten to include an intercept in your regression? I'm not familiar with SPSS code, but on page 21 of Hayashi's Econometrics:

If the regressors do not include a constant but (as some regression software packages do) you nevertheless calculate $R^2$ by the formula

$R^2=1-\frac{\sum_{i=1}^{n}e_i^2}{\sum_{i=1}^{n}(y_i-\bar{y})^2}$

then the $R^2$ can be negative. This is because, without the benefit of an intercept, the regression could do worse than the sample mean in terms of tracking the dependent variable (i.e., the numerator could be greater than the denominator).

I'd check and make sure that SPSS is including an intercept in your regression.

-

2
NOORIGIN subcommand in her code tells that intercept was included in the model – ttnphns Jul 12 '11 at 10:12

This can happen if you have a time series that is N.i.i.d. and you construct an inappropriate ARIMA model of the form(0,1,0) which is a first difference random walk model with no drift then the variance (sum of squares - SSE ) of the residuals will be larger than the variance (sum of squares SSO) of the original series. Thus the equation 1-SSE/SSO will yield a negative number as SSE execeedS SSO . We have seen this when users simply fit an assumed model or use inadequate procedures to identify/form an appropriate ARIMA structure. The larger message IS that a model can distort (much like a pair of bad glasses ) your vision. Without having access to your data I would otherwise have a problem in explaining your faulty results. Have you brought this to the attention of IBM ?

The idea of an assumed model being counter-productive has been echoed by Harvey Motulsky. Great post Harvey !

-

1
stat. Thanks. No I have not spoken to IBM. The data is not time series. It is from point in time data. – Anne Jul 11 '11 at 19:55

1
@Anne and others: Since your data are not time series and you're not using a time series procedure please disregard my answer. Others who have observed negative R Squares when involved with time series might find my post interesting and tangentially informative. Others unfortunately may not. – IrishStat Jul 11 '11 at 21:36
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 4, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9359946250915527, "perplexity_flag": "middle"}