我有一个新手问题,对不起。我在R中逐步执行度量multidimensional scaling。因此,我必须计算以下内容:
b rs = a rs - mean(a r ) - mean(a s )+ mean(a)
我用这段代码尝试了它,但当然它只为对角线提供了正确的结果:
i <- c(1:5)
j <- c(1:5)
brs <- (A[i,j] - colMeans(A[i,]) - rowMeans(A[,j]) + mean(A))
供参考:
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)
结果应该是具有以下值的矩阵:
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)