Computes the chi2 distance between the rows of a rectangular matrix (with positive elements).
Computes the chi2 distance between the rows of a rectangular matrix (with positive elements).
Chi2Dist: Computes the I∗I matrix D which is the chi2 distance matrix between the rows of an I∗J rectangular matrix X
(with non-negative elements), and provides the I∗1 m
vector of mass (where the mass of a row is the sum of the entries of this row divided by the grand total of the matrix). When the distance matrix and the associated vector of masses are used as input to the function mmds
the results will give the factor scores of the correspondence analysis of the matrix X . The function is used by the function Chi2DistanceFromSort that computes the chi2
distance for the results of a sorting task.
Chi2Dist(X)
Arguments
X: A rectangle matrix with non-negative elements
Returns
Sends back a list: - **Distance∗∗:thesquaredchi2$
distance matrix computed the rows of matrix X .
masses: the vector of masses of the rows of of matrix X .
Examples
# Here is a data matrix from Abdi & Williams (2012)# page 449, Table 15. Punctuation of 6 French authorsPunctuation = matrix(c(7836,13112,6026,53655,102383,42413,115615,184541,59226,161926,340479,62754,38177,105101,12670,46371,58367,14299), ncol =3,byrow =TRUE)colnames(Punctuation)<-c('Period','Comma','Other')rownames(Punctuation)<-c('Rousseau','Chateaubriand','Hugo','Zola','Proust','Giroudoux')# 1. Get the Chi2 distance matrix# between the rows of Punctuation Dres <- Chi2Dist(Punctuation)# check that the mds of the Chi2 distance matrix# with CA-masses gives the CA factor scores for I # 2. Use function mmds from DistatisR #testmds <- mmds(Dres$Distance,masses=Dres$masses)# Print the MDS factor scores from mmdsprint('Factor Scores from mds')print(testmds$FactorScores)print('It matches CA on X (see Abdi & Williams, 2010. Table 16, p. 449)')# Et voila!
References
The procedure and references are detailled in (Paper available from https://personal.utdallas.edu/~herve/): Abdi, H. (2007). Distance. In N.J. Salkind (Ed.): Encyclopedia of Measurement and Statistics. Thousand Oaks (CA): Sage. pp. 304--308.
And in:
Abdi, H., & Valentin, D. (2006). Mathematiques pour les Sciences Cognitives (Mathematics for Cognitive Sciences).