0

I have a newbie question, sorry for that. I am doing the metric multidimensional scaling step-by-step in R. Therefore, I have to compute the following:

brs = ars - mean(ar) - mean(as) + mean(a)

I tried it with this code but of course it delivers correct results only for the diagonale:

i <- c(1:5)
j <- c(1:5)    
brs <- (A[i,j] - colMeans(A[i,]) - rowMeans(A[,j]) + mean(A))

FYI:

A <- matrix(c(0,-40.5,-8,-50,-24.5,-10.5,0,-4.5,-0.5,-2,-8,-4.5,0,-32,-18,-50,-0.5,-32,0,-12.5,-24.5,-2,-18,-12.5,0),nrow=5)

The result should be a matrix with the following values:

B <- matrix(c(33.8,-21.8,13.7,-21.8,-3.9,-21.8,3.6,2.1,12.6,3.5,13.7,2.1,9.6,-15.9,-9.5,-21.8,12.6,-15.9,22.6,2.5,-3.9,3.5,-9.5,2.5,7.4),nrow=5)
mrfarbe
  • 1
  • 1
  • You get the same values for `colMeans(A[i,])` and `colMeans(A[,j])`. I think you don't need i, j, etc – akrun Jan 18 '17 at 14:58
  • But not always?! When I want to have B[1,3] I need the mean of column 1 and the mean of row 3. This isn't the same value. Or do I understand wrongly?! – mrfarbe Jan 18 '17 at 15:05
  • I am not able to get the values in B. Could you show how you got 33.8 from A's values – akrun Jan 18 '17 at 15:06
  • I also don't get them but I want to get them (I know that B is the correct solution). With my R code I get the following values for B: 33.8 -36.9 1.6 -27.4 -17.1 -6.7 3.6 5.1 22.1 5.4 25.8 -0.9 9.6 -9.4 -10.6 -16.2 3.1 -22.4 22.6 -5.1 9.3 1.6 -8.4 10.1 7.4 (so, only the values in the diagonale are correct). – mrfarbe Jan 18 '17 at 15:13
  • 1
    I am not sure if the formula is correct. I double checked the values and it is not the same output – akrun Jan 18 '17 at 15:21
  • Hm, another question: How would you code the formula brs = ars - mean(ar) - mean(as) + mean(a) in R? – mrfarbe Jan 18 '17 at 15:27
  • I would use `A- rowMeans(A)[row(A)] - colMeans(A)[col(A)] + mean(A)` and I am getting 29 instead of 33.8 for the first value – akrun Jan 18 '17 at 15:31
  • Unfortunately, 33.8 has to be correct, It is an example of a textbook and when I do it by hand/my calculator manually, I also get 33.8... :( – mrfarbe Jan 18 '17 at 15:33
  • Are you sure that the formula is correct. If you calculate it for `A[1,1]` you get 29 `A[1,1] - rowMeans(A)[1] - colMeans(A)[1] + mean(A)` – Wolfgang Jan 18 '17 at 16:21

0 Answers0