Message Boards Message Boards

My RSS (residuals) equation isn't summing up

Posted 10 years ago

The function " Define rss" Is not summing up the equation correctly. It was working before I changed the scale of the Plot3D margins, but I really can't see why its not working. Any help would be amazing.

t = Import[
   "http://www.doc.gold.ac.uk//~ma302jh//RegressionExample.xls"];
tp = t[[1]];
t1 = Table[tp[[i]], {i, 2, Length[tp]}];
xcol = Table[t1[[i]][[1]], {i, 1, Length[t1]}];
ycol = Table[t1[[i]][[2]], {i, 1, Length[t1]}];
zcol = Table[t1[[i]][[3]], {i, 1, Length[t1]}];

Clear[DefineRSS];
DefineRSS[a_?NumericQ, b_?NumericQ, 
  c_?NumericQ] := (rss = Total[(zcol - a*xcol + b*ycol + c)^2];
  (a*x) + (b*y) + c)

Manipulate[
 With[{plane = DefineRSS[a, b, c]}, 
  Show[Plot3D[plane, {x, -10, 1000}, {y, -10, 100}, 
    AxesLabel -> {X, Y, Z}, PlotLabel -> rss, 
    PlotStyle -> 
     Directive[Yellow, Specularity[White, 20], Opacity[0.5]]], 
   Graphics3D[{Red, PointSize[Medium], 
     Point[Transpose[{xcol, ycol, zcol}]], 
     Line[Transpose[{{xcol, ycol, zcol}, {xcol, ycol, 
         plane /. Thread[{x, y} -> {xcol, ycol}]}}, {2, 3, 1}]]}], 
   PlotRange -> {{0, 1000}, {0, 60}, {-100, 500}}]], {a, 0, 
  1}, {b, -1, 5}, {c, -60, 300}]
POSTED BY: jethro holcroft
3 Replies
Posted 10 years ago
POSTED BY: Jim Baldwin
Posted 10 years ago

Yes that works, im getting quite high numbers not sure if Im squaring it in the right place but it does what its supposed to do, thank you very mutch :)

POSTED BY: jethro holcroft
Posted 10 years ago

The residual in the formula for the residual sum of squares (rss) needs to be of the form "observed minus predicted". You have

zcol - a*xcol + b*ycol + c

and I suspect you dropped the parentheses around

a*xcol + b*ycol + c

So you need to have

zcol - (a*xcol + b*ycol + c)
POSTED BY: Jim Baldwin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract