# I want to run a same result of biplot in R

There is a software called Brandmap$^1$ which can return a biplot from a matrix. I am trying to run the same result in R but the coordinates are not the same.

First I input a simple matrix into the software.

  x1 x2 x3
a  6  3  7
b  8  6  7
c  9  4  2


There were several options of data centering and I chose to center the data by subtracting every number in the matrix from its (row mean*column mean/grand mean).

         x1    x2         x3
a -1.076923 -1.00  2.0769231
b -1.288462  0.75  0.5384615
c  2.365385  0.25 -2.6153846


Then I chose column factorization to create a biplot. I guess it means a covariance biplot which the singular values are totally assigned to the right singular vectors.

It showed the coordinates:

     dim1    dim2
x1  -2.81   -0.73
x2  -0.55    1.15
x3   3.36   -0.42

a    1.58   -1.78
b    0.75    2.26
c   -2.33   -0.48


I tried to calculate the same results in R.

> P = matrix(c(6,8,9,3,6,4,7,7,2),nrow=3)
> row.names(P)=c("a","b","c")
> colnames(P)=c("x1","x2","x3")
> P
x1 x2 x3
a  6  3  7
b  8  6  7
c  9  4  2
> r1 = matrix(rep(1,3))     #row sum
> c1 = matrix(rep(1,3))     #column sum
> r = P%*%r1
> c = t(P)%*%c1
> L = P - r%*%t(c)/sum(P)   #subtract row mean*column mean/grand mean
> L
x1    x2         x3
a -1.076923 -1.00  2.0769231
b -1.288462  0.75  0.5384615
c  2.365385  0.25 -2.6153846
> S = svd(L)
> S$v%*%diag(S$d)
[,1]       [,2]         [,3]
[1,]  2.8077724  0.7289408 -8.10596e-17
[2,]  0.5487104 -1.1506159 -8.10596e-17
[3,] -3.3564829  0.4216750 -8.10596e-17
> S$u [,1] [,2] [,3] [1,] -0.5420705 0.6105950 0.5773503 [2,] -0.2577555 -0.7747443 0.5773503 [3,] 0.7998260 0.1641494 0.5773503  I found that the values in the right vector are the same but with negative sign and all the values in the left vector are multiplied by -2.918. I am not sure if there is any weighting in the calculation of that software. What kind of adjustment I can try so that I can run the same results in R?$^1\$ Note from @ttnphns: I suppose this software does correspondence analysis, not just arbitrary biplot. CA is very often used in brand research.

• I've done (not weighted) biplot with your 2nd (centered) table. I used formulas described here - they are in aggreement with Greenacre "Biplots in practice" well known paper and other sources. I gave all the inertia to the columns, like you. Your table has rank 2, so only 2 principal dimensions exist, with eigenvalues 2.16118 .22590 The coordinates (for shortness, I display here only Dimension1 coordinates): For rows: -.93889 -.44645 .38534, For columns: 1.62107 .31680 -1.93787. – ttnphns Sep 28 '16 at 9:14
• When you look in the thread with formulas I link to, pay attention that biplot is not simply svd(X), it is svd(Z) where Z is a normalized version of X taking number of rows and columns in consideration. After svd, a "back rescaling" of eigenvectors is performed, which gives the standardized coordinates. – ttnphns Sep 28 '16 at 9:19
• @ttnphns Thank you for your answer! I tried to normalize the matrix by dividing by (r*c)^0.5 which is Z = X/(3*3^0.5) but I got the eigenvalues 1.470096 .475287 and couldn't get the desired results. I need to generate the exact same results of coordinates from that software in R. – bbbbbliu Sep 28 '16 at 14:47
• You got correct singular values. Eigenvalues are just their squares. You should be able to reproduce my results. As for the results of Brandmap software - I absolutly can't comment it since I don't know its algorithms. It might use other normalizations or even other approaches. Or even have a bug. Consult with the documentation or the developers. – ttnphns Sep 28 '16 at 15:48
• Hey, possibly I cracked it. I performed, on your initial table1 correspondence analysis (euclidaen model, see my link) with preprocessing = two-way centering + normalizing by the mean mass. I gave full inertia to columns, as you did. I got coordinates which have the cosine similarity with your coordinates from Brandmap equal 1. I.e. results are fully proportional. I tentatively conclude that Brandmap actually does correspondence analysis, only it does normalization which is not same but is equivalent in results with correspondence analysis I described in the link. – ttnphns Sep 28 '16 at 17:13