Correspondence Analysis on Generalised Aggregated Lexical Tables (CA-GALT) in the FactoMineR Package

Correspondence analysis on generalised aggregated lexical tables (CA-GALT) is a method that generalizes classical CA-ALT to the case of several quantitative, categorical and mixed variables. It aims to establish a typology of the external variables and a typology of the events from their mutual relationships. In order to do so, the influence of external variables on the lexical choices is untangled cancelling the associations among them, and to avoid the instability issued from multicollinearity, they are substituted by their principal components. The CaGalt function, implemented in the FactoMineR package, provides numerous numerical and graphical outputs. Confidence ellipses are also provided to validate and improve the representation of words and variables. Although this methodology was developed mainly to give an answer to the problem of analyzing open-ended questions, it can be applied to any kind of frequency/contingency table with external variables. Introduction Frequency tables are a common data structure in very different domains such as ecology (specie abundance table), textual analysis (documents × words table) and public information systems (administrative register such as mortality data). This type of table counts the occurrences of a series of events (species, words, death causes) observed on different units (ecological sites, documents, administrative areas). Correspondence analysis (CA) is a reference method to analyse this type of tables offering the visualization of the similarities between events, the similarities between units and the associations between events and units (Benzécri, 1973; Lebart et al., 1998; Murtagh, 2005; Greenacre, 2007; Beh and Lombardo, 2014). However, this method presents two main drawbacks, when the frequency table is very sparse: 1. The first axes frequently show the relationships between small sets of units and small sets of events and do not reveal global trends. 2. The interpretation of the similarities/oppositions among units cannot be understood without taking into account the unit characteristics (such as, for example, climatic conditions, socioeconomic description of the respondents or economic characteristics of the area). In order to solve these drawbacks, contextual variables are also observed on the units and introduced in the analysis. A first step consists of grouping the units depending on one categorical variable and building an aggregated frequency table (AFT) crossing the categories (rows) and the events (columns). In this AFT, the former row-units corresponding to the same category are now collapsed into a single row while the event-columns remain unchanged. Then, CA is applied on this AFT, often called, in textual analysis, aggregated lexical table (ALT; Lebart et al., 1998). CA on the aggregated lexical table (CA-ALT) usually leads to robust and interpretable results. CAALT visualizes the similarities among categories, the similarities among words and the associations between categories and words. The same approach can be applied in other domains. The main drawback of CA-ALT is its restrictiveness. Only one categorical variable can be considered while often several categorical and quantitative contextual variables are available and associated to the events. Recently, correspondence analysis on generalised aggregated lexical tables (CA-GALT; BécueBertaut and Pagès, 2015; Bécue-Bertaut et al., 2014) has been proposed to generalize CA-ALT to the case of several quantitative, categorical and mixed variables. CA-GALT brings out the relationships between the vocabulary and the several selected contextual variables. This article presents an R function implementing CA-GALT in the FactoMineR package (Lê et al., 2008; Husson et al., 2010) and has the following outline: We first describe the example used to illustrate the method and introduce the notation. Then we recall the principles of the CA-GALT methodology and proceed to detail the function and the algorithm. Subsequently, the results obtained on the example are provided. Finally, we conclude with some remarks. The R Journal Vol. 7/1, June 2015 ISSN 2073-4859 CONTRIBUTED RESEARCH ARTICLES 110 Example The example is extracted from a survey intended to better know the definitions of health that the nonexperts give. An open-ended question “What does health mean to you?” was asked to 392 respondents who answered through free-text comments. The documents × words table is built keeping only the words used at least 10 times among all respondents. This minimum threshold is used to obtain statistically interpretable results (Lebart et al., 1998; Murtagh, 2005). Thus, 115 different words and 7751 occurrences are kept. The respondents’ characteristics are also collected. In this example, we use age in groups (under 21, 21–35, 36–50 and over 50), gender (man and woman) and health condition (poor, fair, good and very good health) as they possibly condition the respondents’ viewpoint. CA-GALT is able to determine the main dispersion dimensions as much as they are related to the respondents’ characteristics. Notation The data is coded into two matrices (see Figure 1). The (I × J) matrix Y, with generic term yij, contains the frequency of the J words in the I respondents’ answers. The (I × K) matrix X, with generic term xik, stores the K respondents’ characteristics, codified as dummy variables from the L categorical variables.


Introduction
Frequency tables are a common data structure in very different domains such as ecology (specie abundance table), textual analysis (documents × words table) and public information systems (administrative register such as mortality data). This type of table counts the occurrences of a series of events (species, words, death causes) observed on different units (ecological sites, documents, administrative areas). Correspondence analysis (CA) is a reference method to analyse this type of tables offering the visualization of the similarities between events, the similarities between units and the associations between events and units (Benzécri, 1973;Lebart et al., 1998;Murtagh, 2005;Greenacre, 2007;Beh and Lombardo, 2014). However, this method presents two main drawbacks, when the frequency table is very sparse: 1. The first axes frequently show the relationships between small sets of units and small sets of events and do not reveal global trends.
2. The interpretation of the similarities/oppositions among units cannot be understood without taking into account the unit characteristics (such as, for example, climatic conditions, socioeconomic description of the respondents or economic characteristics of the area).
In order to solve these drawbacks, contextual variables are also observed on the units and introduced in the analysis. A first step consists of grouping the units depending on one categorical variable and building an aggregated frequency table (AFT) crossing the categories (rows) and the events (columns). In this AFT, the former row-units corresponding to the same category are now collapsed into a single row while the event-columns remain unchanged. Then, CA is applied on this AFT, often called, in textual analysis, aggregated lexical table (ALT; Lebart et al., 1998).
CA on the aggregated lexical table (CA-ALT) usually leads to robust and interpretable results. CA-ALT visualizes the similarities among categories, the similarities among words and the associations between categories and words. The same approach can be applied in other domains. The main drawback of CA-ALT is its restrictiveness. Only one categorical variable can be considered while often several categorical and quantitative contextual variables are available and associated to the events.

Example
The example is extracted from a survey intended to better know the definitions of health that the nonexperts give. An open-ended question "What does health mean to you?" was asked to 392 respondents who answered through free-text comments. The documents × words table is built keeping only the words used at least 10 times among all respondents. This minimum threshold is used to obtain statistically interpretable results (Lebart et al., 1998;Murtagh, 2005). Thus, 115 different words and 7751 occurrences are kept.
The respondents' characteristics are also collected. In this example, we use age in groups (under 21, 21-35, 36-50 and over 50), gender (man and woman) and health condition (poor, fair, good and very good health) as they possibly condition the respondents' viewpoint.
CA-GALT is able to determine the main dispersion dimensions as much as they are related to the respondents' characteristics.

Notation
The data is coded into two matrices (see Figure 1). The (I × J) matrix Y, with generic term y ij , contains the frequency of the J words in the I respondents' answers. The (I × K) matrix X, with generic term x ik , stores the K respondents' characteristics, codified as dummy variables from the L categorical variables.  The proportion matrix P is computed as P = Y/N with generic term p ij = y ij /N. The row margin (respectively, column margin) with generic term . This matrix, or equivalently, its doubly centred form, the (I × J) matrixQ with generic termq ij = (p ij − p i• p •j )/(p i• p •j ) is the matrix analysed by CA.Q evidences that CA analyses the weighted deviation between P and the (I The principal component analysis (PCA) applied to a data matrix Z with metric M/D and weighting system D/M in the row/column space is noted PCA(Z, M, D).

Methodology
The CA-GALT method is detailed in Bécue-Bertaut and Pagès (2015) for quantitative contextual variables and Bécue-Bertaut et al. (2014) for categorical variables. We recall here the principles of this method. To ease the presentation, we recall first that classical CA is a double projected analysis. Then, we show that CA-GALT maintains a similar approach when several quantitative or categorical variables are taken into account.

Classical CA as a particular PCA
It is established that classical CA(Y) is equivalent to PCA(Q, D J , D I ) or to PCA(Q, D J , D I ) (Escofier and Pagès, 1988;Böckenholt and Takane, 1994;Bécue-Bertaut and Pagès, 2004). This point of view presents the advantage of placing CA rationale in the general scheme for the principal components methods.

CA of an aggregated lexical table
In this section, the columns of X are dummy variables corresponding to the categories of a single categorical variable. First, the (J × K) aggregated lexical table is built crossing the words and the categories of the categorical variable. Then the (J × K) proportion matrix is computed as The store, respectively, the row and colum margins of P A . D J (respectively, D K ) corresponds to weighting the system on the rows (respectively, on the columns). As a single categorical variable is considered is the double standardized form of P A .

Correspondence analysis on generalised aggregated lexical tables (CA-GALT)
In this section, X includes the centred dummy columns corresponding to several categorical variables. The aggregated lexical tables built from each categorical variable are juxtaposed row-wise into the generalised aggregated lexical table (GALT) Y A of dimensions J × K (see Figure 2).
In the following, we use the same notation that this used in the former section to highlight that the same rationale is followed regardless the differences existing between the X structure in both cases. As in the former section To maintain a double projected analysis, D K is substituted by the (K × K) covariance matrix C = (X T D I X). As C is not invertible, the Moore-Penrose pseudoinverse C − is used and the former Eq. (6) becomes As in any PCA, the eigenvalues are stored into the (S × S) diagonal matrix Λ, and the eigenvectors into the (K × S) matrix U. The coordinates of the row-words are computed as and the column-categories as The respondents can be reintroduced in the analysis by positioning the columns of Q as supplementary The interpretation rules of the results of this specific CA are the usual CA interpretation rules (Greenacre, 1984;Escofier and Pagès, 1988;Lebart et al., 1998).

Quantitative contextual variables
The case of the quantitative variables is detailed in Bécue-Bertaut and Pagès (2015). The same rationale is followed, but defining: • The GALT Y A is built as Y A = Y T X and transformed into the matrix P A = P T X whose generic term p Ajk = ∑ i p ij x ik is equal to the weighted sum of the values assumed for variable k by the respondents who used word j.
• The matrix D −1 K no longer exists because the column-margins of P A do not correspond to a weighting system on the columns.

Other aspects
• CA-GALT on principal components: To obtain less time consuming computation, the original variables are substituted by their principal components, computed either by PCA if X stores quantitative variables or multiple correspondence analysis if X stores categorical variables. The components associated to the low eigenvalues can be discarded to solve the instability problem issued from multicolinearity.
• Confidence ellipses: To validate and to better interpret the representation of the words and variables, confidence ellipses based on the bootstrap principles (Efron, 1979) are performed.

Using the CaGalt function in R
The R function CaGalt is currently part of the FactoMineR package. The default input for the CaGalt function in R is CaGalt(Y, X, type = "s", conf.ellip = FALSE, nb.ellip = 100, level.ventil = 0, sx = NULL, graph = TRUE, axes = c(1, 2)) with the following arguments: • Y: a data frame with n rows (individuals) and p columns (frequencies) • X: a data frame with n rows (individuals) and k columns (quantitative or categorical variables) • type: the type of variables: "c" or "s" for quantitative variables and "n" for categorical variables. The difference is that for "s" variables are scaled to unit variance (by default, variables are scaled to unit variance) • conf.ellip: boolean (FALSE by default), if TRUE, draw confidence ellipses around the frequencies and the variables when graph is TRUE • nb.ellip: number of bootstrap samples to compute the confidence ellipses (by default 100) • level.ventil: proportion corresponding to the level under which the category is ventilated; by default, 0 and no ventilation is done. Available only when type is equal to "n" • sx: number of principal components kept from the principal axes analysis of the contextual variables (by default is NULL and all principal components are kept) • graph: boolean, if TRUE a graph is displayed • axes: a length 2 vector specifying the components to plot The returned value of CaGalt is a list containing: • eig: a matrix containing all the eigenvalues, the percentage of variance and the cumulative percentage of variance • ind: a list of matrices containing all the results for the individuals (coordinates, square cosine) • freq: a list of matrices containing all the results for the frequencies (coordinates, square cosine, contributions) • quanti.var: a list of matrices containing all the results for the quantitative variables (coordinates, correlation between variables and axes, square cosine) • quali.var: a list of matrices containing all the results for the categorical variables (coordinates of each categories of each variables, square cosine) • ellip: a list of matrices containing the coordinates of the frequencies and variables for replicated samples from which the confidence ellipses are constructed To facilitate the analysis of the output of the results and the graphs, corresponding print, plot and summary methods were also implemented in FactoMineR.

Application of the CaGalt function
To illustrate the outputs and graphs of CaGalt, we use the data set presented in the previous section. The first 115 columns correspond to the frequencies of the words in respondents' answers and the last three columns correspond to the categorical variables corresponding to respondents' characteristics (whose type is defined as "n"). The code to perform the CaGalt is > data(health) > res.cagalt <-CaGalt(Y = health[, 1:115], X = health[, 116:118], type = "n")

Numerical outputs
The results are given in a list for the individuals, the frequencies, the variables and the confidence ellipses.
> res.cagalt **Results for the Correspondence Analysis on Generalised Aggregated Lexical Tables (CaGalt)** *The results are available in the following entries: name description 1 "$eig" "eigenvalues" 2 "$ind" "results for the individuals" 3 "$ind$coord" "coordinates for the individuals" 4 "$ind$cos2" "cos2 for the individuals" 5 "$freq" "results for the frequencies" 6 "$freq$coord" "coordinates for the frequencies" 7 "$freq$cos2" "cos2 for the frequencies" 8 "$freq$contrib" "contributions of the frequencies" 9 "$quali.var" "results for the categorical variables" 10 "$quali.var$coord" "coordinates for the categories" 11 "$quali.var$cos2" "cos2 for the categories" 12 "$ellip" "coordinates to construct confidence ellipses" 13 "$ellip$freq" "coordinates of the ellipses for the frequencies" 14 "$ellip$var" "coordinates of the ellipses for the variables" The interpretation of the numerical outputs can be facilitated using the summary method for the objects of class 'CaGalt' returned by function CaGalt which prints summaries of the CaGalt entries.  Regarding the interpretation of these results, the percentage of variance explained by each dimension is given: 30.21% for the first axis and 19.02% for the second one. The third and fourth dimensions also explain an important part of the total variability (13.78% and 12.95%, respectively) and it may be interesting to plot the graph for these two dimensions. The numerical outputs corresponding to the individuals, frequencies and variables are useful especially as a help to interpret the graphical outputs.
The arguments of the summary method for 'CaGalt' objects, nbelements (number of written elements), nb.dec (number of printed decimals) and ncp (number of printed dimensions), can also be modified to obtain more detailed numerical outputs. For more information please check the help file of this function.

Graphical outputs
By default, the CaGalt function gives three graphs: one for the individuals, one for the variables and one for the frequencies. The variables graph shows the map of the categories (see Figure 3). The trajectory of age group categories notably follows the first axis. The second axis opposes the Man category and the Woman category. The categories of health condition are close to the centroid on the first dimension indicating a low association with the words on this dimension. The categories poor and good of health condition are opposed on the second axis; they lie close to Man and Woman respectively. Regarding the word graph (see Figure 4), best, main and child are the words with the highest coordinates at the right of the first axis. From the transition relationships between words and categories, we can say that both words are very frequently used by the oldest categories and avoided by the youngest. These words contrast with something and sport, at the left of the first axis, these latter words being used by the youngest categories and avoided by the oldest. Comparing vocabulary choices depending on the gender (second axis), we see that men more frequently consider health from a physical point of view (sport, to maintain, and so on) and women from a psychological point of view (psychologically, mind, and so on).
The high number of elements drawn on the graphs (points and labels) makes the reading and the interpretation difficult. The plot method for 'CaGalt' objects can improve them through replacing the labels, modifying their size, changing the colours, adding confidence ellipses or only selecting a part of the elements. For example, for the categorical variables we will use the code > plot(res.cagalt, choix = "quali.var", conf.ellip = TRUE, axes = c(1, 4)) The parameter choix = "quali.var" indicates that we plot the graph of the categorical variables, the parameter axes = c(1,4) indicates that the graph is done for the dimensions 1 and 4, and the parameter conf.ellip = TRUE indicates that confidence ellipses are drawn around the categorical variables. Analyzing the graph which was drawn with this code (see Figure 5), it shows that the fourth axis turns out to be of interest because of ranking health condition categories in their natural order. These categories are well separated, except for the two better health categories whose confidence ellipses overlap.

Conclusion
The main features of the R function CaGalt have been detailed and illustrated using an example based on survey data collected by a questionnaire which included an open-ended question. This application to a real data set demonstrates how both open-ended and closed questions combine to provide relevant information. Although this methodology was developed mainly to give an answer to the problem of analyzing open-ended questions with several quantitative, categorical and mixed contextual variables, it can be applied to any kind of frequency/contingency table with external variables. The function CaGalt can also be used to perform a CA-ALT because there is no other function in R for the same purpose.