title: R error | Vectors calculations returns the wrong matrix size | Non-conformable arrays
body: <p>I am trying to calculate Within And Total Sum of Squares and Cross-Product Matrices (W) in one-way MANOVA. 
  I have a treatment matrix <strong>tm</strong>:</p>
  
  <pre><code> n x1 x2
   1  6 7
   1  5 9
   1  8 6
   ...
   2  3 3
   2  1 6
   2  2 3
   ...
   3  2 3
   3  2 3
   3  5 1
   ...
  </code></pre>
  
  <p>I also have each individual observations in their own variables, for example: </p>
  
  <pre><code> x111 = x[1,1]
   x112 = x[2,1]
   ...
  </code></pre>
  
  <p>that are also in the variables that create vectors: </p>
  
  <pre><code># creating vectors
  
  t11 = c(x111, x111_2) # 6,7
  t12 = c(x112, x112_2) # 5,9 
  t13 = c(x113, x113_2) # 8,6
  t14 = c(x114, x114_2) # 4,9
  t15 = c(x115, x115_2) # 7,9
  t21 = c(x211, x211_2) # 3,3
  t22 = c(x212, x212_2) # 1,6
  t23 = c(x213, x213_2) # 2,3
  t31 = c(x311, x311_2) # 2,3
  t32 = c(x312, x312_2) # 5,1
  t33 = c(x313, x313_2) # 3,1
  t34 = c(x314, x314_2) # 2,3
  
  &gt;dput(t11)
  c(6,7)
  </code></pre>
  
  <p>I am trying to calculate W (Within And Total Sum of Squares and Cross-Product Matrices). </p>
  
  <p>The means are </p>
  
  <pre><code>&gt; x1 # treatment 1
  [1] 6 8
  
  &gt; x2  # treatment 2
  [1] 2 4
  
  &gt; x3  # treatment 3
  
  [1] 3 2
  
  &gt; x # overall mean
  
       X1 X2
  [1,]  4  5
  </code></pre>
  
  <p>The code I have is: </p>
  
  <pre><code>W = (t(t11)-t(x1))*(t11-x1)
  +(t(t12)-t(x1))%*%(t12-x1)
  +(t(t13)-t(x1))%*%(t13-x1)
  +(t(t14)-t(x1))%*%(t14-x1)
  +(t(t15)-t(x1))%*%(t15-x1)
  +(t(t21)-t(x2))%*%(t21-x2)
  +(t(t22)-t(x2))%*%(t22-x2)
  +(t(t23)-t(x2))%*%(t23-x2)
  +(t(t31)-t(x3))%*%(t31-x3)
  +(t(t32)-t(x3))%*%(t32-x3)
  +(t(t33)-t(x3))%*%(t33-x3)
  +(t(t34)-t(x3))%*%(t34-x3)
  </code></pre>
  
  <p>The result I get is:</p>
  
  <pre><code>Error in (t(t11) - t(x1)) * (t11 - x1) + (t(t12) - t(x1)) %*%  : 
  non-conformable arrays
  </code></pre>
  
  <p>When I isolated each statements, I got this: </p>
  
  <pre><code>&gt; (t(t11)-t(x1))%*%(t11-x1)
        [,1]
   [1,]   1
  &gt; (t(t12)-t(x1))%*%(t12-x1)
       [,1]
  [1,]    2
  </code></pre>
  
  <p>Why do these statements evaluate to 1x1 matrices? When I calculate 2x1 and 1x2 operations (subtraction and multiplication) manually, I get 2x2 for both. <a href="http://www.calcul.com/show/calculator/matrix-multiplication_;2;1;1;2?matrix1=[[%220%22],[%221%22]]&amp;matrix2=[[%220%22,%221%22]]&amp;operator=*" rel="nofollow noreferrer">Here</a> is an online calculator </p>