0
$\begingroup$

Following is an example of the observed and predicted values for my variable y (in R).

> df <- data.frame(
        yobs = c(29.08,21.8371611111111,41.1785861111111,
                 60.5846,42.8531777777778,35.6931861111111,15.1174416666667,
                 10.9228777777778,17.6561777777778,29.2195694444444,
                 4.48469166666667,24.2387083333333,57.5354805555556,29.4075305555556,
                 26.7835888888889,28.9258111111111,37.1471972222222,
                 30.5934277777778,9.22973333333333,57.0615833333333,25.5308722222222,
                 40.429725,11.9677777777778,24.6323805555556,43.5893833333333,
                 25.0586194444444,21.5084305555556,28.5317944444444,
                 17.2729027777778,63.3144833333333,18.7004027777778,15.7129944444444,
                 15.6565138888889,27.4428777777778,55.2504027777778,
                 33.6584277777778,10.0764861111111,0.956327777777778,
                 30.4974416666667,40.2348166666667,12.0094138888889,16.0595388888889,
                 6.70388888888889,61.6930861111111,45.5002555555556,
                 34.9412638888889),
       ypred = c(37.9778265746194,20.4344267726767,
                 24.2583278821139,81.3820676947289,35.9664230956281,48.2550410428931,
                 13.1322244321762,11.2277223100893,17.3847974374533,
                 36.2654061390013,13.6891124226893,36.93587791295,42.4778772806932,
                 60.4805857896792,50.8097811774078,31.2983753184525,
                 39.4901787588643,36.0489111859141,5.16132056902304,67.6280256177873,
                 46.6873141264554,56.9305336644725,17.1904930898903,
                 17.8447406631152,81.8167881348895,21.6446504197869,17.2125579607197,
                 27.8854475743327,25.6223558489715,39.1097052984601,
                 14.3303635195841,8.3085889213573,14.7616830600331,29.6236752760362,
                 36.4710794579997,32.1294471109381,21.9208933069802,
                 8.17174771983545,30.3954470923862,25.2201086957305,13.7007923212405,
                 16.2708330581924,11.7006605896811,71.8768937208489,
                 77.2434241984382,30.0205384313346))
> SST <- sum((mean(df$yobs)-df$yobs)^2)
> SSE <- sum((df$yobs-df$ypred)^2)
> SSR <- sum((df$ypred-mean(df$yobs))^2)
> SST
[1] 11600.41
> SSR
[1] 18976.75
> SSE
[1] 8199.87

I know that SST=SSE+SSR. But something is wrong with my values. A scatter plot shows a reasonable agreement between ypred and yobs. Is there any reason why the relationship is not applicable in this case? The R² are understandably off. Am I making some mistake here?

$\endgroup$
2
  • 2
    $\begingroup$ Your formula for SSR is incorrect. This might become obvious if you were to check your formulas against a tiny dataset with simple values for which you can easily perform calculations by hand. $\endgroup$
    – whuber
    Oct 13 '21 at 15:35
  • $\begingroup$ Not in this example, but more generally $SST < SSR$ is related to "negative $R^2$" where the model is so poor that predicting a constant value equal to the mean of the observations would have performed better. This cannot happen with ordinary linear regression. See a couple of earlier questions: stats.stackexchange.com/questions/86305/… and stats.stackexchange.com/questions/12900/… $\endgroup$
    – Henry
    Oct 13 '21 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.