# An error of unequal length when using Transpose[y]? [closed]

Why do I get this error? I just clicked shift+enter in the y and it appeared.

https://i.stack.imgur.com/IAKs8.png

This is the data

y = {{4.9176, 5.0208, 4.5429, 4.5573, 5.0597, 3.8910, 5.8980, 5.6039,
5.8282, 5.3003, 6.2712, 5.9592, 5.0500, 8.2464, 6.6969, 7.7841,
9.0384, 5.9894, 7.5422, 8.7951, 6.0831, 8.3607, 8.1400, 9.1416}};

x = {25.9, 29.5, 27.9, 25.9, 29.9, 29.9, 30.9, 28.9, 35.9, 31.5, 31,
30.9, 30, 36.9, 41.9, 40.5, 43.9, 37.5, 37.9, 44.5, 37.9, 38.9,
36.9, 45.8};
Id = IdentityMatrix[24];
x = MatrixForm[Thread[{1, x}]];
M = x*Inverse[Transpose[x]*x]*Transpose[x];

SSE = Transpose[y]*(Id - M)*y

SST = Transpose[y - Mean[y]]*(y - Mean[y])


I just wanted the transpose of y (first, in the end I want to know SSE).

How come unequal length error appeared?

(I apologize for many questions)

• Please post actual code rather than pictures of code. You'll likely get more help that way. – JimB Oct 31 '18 at 5:32
• @JimB Oh ok sorry, how do I do that? – g.a.l.l.e.t.a Oct 31 '18 at 5:33
• remove MatrixForm from the rhs of definition: use x = Thread[{1,x}]; – kglr Oct 31 '18 at 5:34
• @JimB I did it. – g.a.l.l.e.t.a Oct 31 '18 at 5:37
• You'll need to use . rather than * for matrix multiplication. – JimB Oct 31 '18 at 5:42

You need Dot:

ClearAll[x, y]
y = {{4.9176, 5.0208, 4.5429, 4.5573, 5.0597, 3.8910, 5.8980, 5.6039,
5.8282, 5.3003, 6.2712, 5.9592, 5.0500, 8.2464, 6.6969, 7.7841,
9.0384, 5.9894, 7.5422, 8.7951, 6.0831, 8.3607, 8.1400, 9.1416}};
x = {25.9, 29.5, 27.9, 25.9, 29.9, 29.9, 30.9, 28.9, 35.9, 31.5, 31,
30.9, 30, 36.9, 41.9, 40.5, 43.9, 37.5, 37.9, 44.5, 37.9, 38.9,
36.9, 45.8};

x = Thread[{1, x}];
y = y[[1]];
Id = IdentityMatrix[24];
M = x. Inverse[Transpose[x] . x] . Transpose[x];
SSE = y . (Id - M) . y


13.392961097651924

SST = (y - Mean[y]).(y - Mean[y])


57.56312745333333

• Thank you kglr, I have a question why do you add y = y[[1]]; ? – g.a.l.l.e.t.a Oct 31 '18 at 5:52
• Oh and you also removed the IdentityMatrix line, is y = y[[1]]; somehow equivalent to? – g.a.l.l.e.t.a Oct 31 '18 at 5:54
• @user459663, forgot to paste the line with Id =.... Re y[[1]], we need a T by 1 vector for the dependent variable. – kglr Oct 31 '18 at 5:57
• I don't understand. Is Transpose[y - Mean[y]].(y - Mean[y]) equivalent to (y - Mean[y]).(y - Mean[y]) + y = y[[1]];` ? – g.a.l.l.e.t.a Oct 31 '18 at 6:03
• @user459663, they are not . You need the latter to get the sse in mathematica. Btw, mathematica does not distinguish between column and row vectors. – kglr Oct 31 '18 at 6:07