ICGE: an R package for detecting relevant clusters and atypical units in gene expression

Background Gene expression technologies have opened up new ways to diagnose and treat cancer and other diseases. Clustering algorithms are a useful approach with which to analyze genome expression data. They attempt to partition the genes into groups exhibiting similar patterns of variation in expression level. An important problem associated with gene classification is to discern whether the clustering process can find a relevant partition as well as the identification of new genes classes. There are two key aspects to classification: the estimation of the number of clusters, and the decision as to whether a new unit (gene, tumor sample...) belongs to one of these previously identified clusters or to a new group. Results ICGE is a user-friendly R package which provides many functions related to this problem: identify the number of clusters using mixed variables, usually found by applied biomedical researchers; detect whether the data have a cluster structure; identify whether a new unit belongs to one of the pre-identified clusters or to a novel group, and classify new units into the corresponding cluster. The functions in the ICGE package are accompanied by help files and easy examples to facilitate its use. Conclusions We demonstrate the utility of ICGE by analyzing simulated and real data sets. The results show that ICGE could be very useful to a broad research community.


Background
There is considerable interest among researches in using cluster methods. For example, a common approach in many biomedical applications is to seek a reliable and precise classification of genes into a number of clusters, which is essential for understanding the bases of complex diseases. For instance, an accurate classification of tumors is essential to successful diagnosis and treatment of cancer. Clustering algorithms attempt to partition the units into groups that have similar properties and it is necessary to identify the value of k at which the final partition appears to be the best. There is considerable interest among researches in using cluster methods, which can be generally found in R packages on the Comprehensive R Archive Network (CRAN, http://CRAN.R-project. org). An important problem associated with the classification of units is to assess whether the clustering process finds a relevant partition, and to identify new classes of units. For example, if genes are classified into groups exhibiting similar patterns of gene expression variation, it is necessary to pay attention to two things. First the correct classification in k clusters of the genes by an unsupervised method. Usually, when a clustering algorithm is applied to a set of units, although the data do not present a cluster structure, the algorithm returns a partition. It is thus necessary that the index used to establish the "real" number of clusters should also be able to detect the absence of cluster structure. A variety of measures for determining the "real" number of cluster can be found in the literature, see for example [1][2][3][4][5][6][7][8] or [9], which gives an excellent overview. Most of these procedures are useful only for continuous data. Only one, the silhouette method [5], is appropriate for any kind of data (continuous, binary or qualitative). Data of this kind are common in biomedical applications, but the silhouette index cannot detect the absence of a cluster structure. An index that can be applied to any kind of attribute type, the INCA index, can be found in [10]. This index can use continuous data without any assumption about their distribution and it also permits detection of data that have no cluster structure. Second, given a new gene, the procedure should establish whether it is sufficiently similar to any of the existing clusters. If not, a new type of expression pattern must be considered. Note that some techniques of classification, similar to discriminant analysis, classify a new unit as necessarily belonging to one of the specified clusters. However, this new unit may not belong to any of the pre-identified clusters, but may rather be a member of an entirely different and unknown cluster. There are few approaches in the literature dealing with the typicality problem [11][12][13][14][15]. All these methods have some restrictions on the type of data (only continuous data following normal distribution) or on the number of groups (only two groups for any kind of data). Recently, Irigoien et al. [10] developed an effective test for determining atypical objects in different types of clustering applications. This test provides an alternative to the other models that impose constraints on the type of data or the number of groups. This test can be used with any kind of data, and has no limitation on the number of groups.
The literature on statistical clustering is large, but it does not appear to contain any computational tool capable of solving all the key aspects of classification: identifying the number of clusters using mixed variables, usually found in applied biomedical research; detecting whether the data have a cluster structure; identifying whether a new unit belongs to one of the pre-identified clusters, and classifying this unit. The ICGE package uses the methodology introduced in [10] and deals with all the aspects commented above.

Implementation
In this section, the structure of the package and the functions implemented are explained. Examples illustrating the usage of the functions are also included.
The ICGE package was developed for the free statistical R environment (http://www.r-project.org) and runs under the major operating systems. We do not delve here into details of the underlying statistical methodology. However, a review of this methodology can be found in the Methods subsection. Table 1 summarizes the main functions available in the package. A detailed description of these functions is provided below.

Main functions
The main function INCAindex helps to estimate the number of clusters in a dataset.

• Arguments
To call the main function INCAindex(d, pert_clus), two arguments must be specified.
As usual, d is a distance matrix or a dist object containing the distances between the n units, and pert clus is an n-vector that indicates which group each unit belongs to. The default value indicates the presence of only one group in the data. Note that the expected values of pert_clus are greater than or equal to 1 (for instance 1,2,3,4...).

• Value
This function returns an object of class incaix, which is a list containing the following components: well_class, a vector indicating the number of units that are well classified; Ni_cluster, a vector indicating each cluster size and Total, percentage of units well classified in the partition defined by pert_clus, i.e., the INCA index. • Remarks It admits the associated methods summary and plot. The first simply returns the percentage of well-classified units and the second offers a barchart with the percentages of well classified units for each group in the given partition.
• Example 1 Consider the following simulated data. Using the data simulation functions included in the WGCNA package (see [16]), we generated 100 samples and three groups containing 480, 360 and 360 genes, respectively. We used the Euclidean distance and calculated the percentage of well classified genes.  Furthermore, in order to obtain an estimation of the "real" number of clusters from the data, we compute the INCA index for several partitions, with different number k of clusters in each partition, where k = 2,..., K. This is the aim of INCAnumclu function.

• Arguments
The function INCAnumclu(d, K, method="pam", pert, noise="NULL", L) has 6 arguments but they are not involved simultaneously. A distance matrix d or a dist object with distance information between the n units is required. Argument K indicates the maximum number of clusters to be considered. For each value k, k = 2, ..., K a partition in k clusters is considered. The method argument is a character string defining the clustering method to be applied in order to obtain the corresponding partitions. The clustering method is performed via the function pam and agnes in cluster package. The available clustering methods are pam (default method, Partitioning Around Medoids clustering method, PAM, [17]), average (UPGMA), single (single linkage), complete (complete linkage), ward (Ward's method), weighted (weighted average linkage). Nevertheless, the user can introduce particular partitions indicating method="partition" and using the pert argument. This argument is a matrix with n rows, and each column contains a particular partition. This means that each column is an n vector that indicates the group to which each unit belongs. Note that the expected values of each column of pert are consecutive integers that are greater than or equal to 1 (for instance 1,2,3,4..., k). The argument noise is a logical vector indicating units considered as "noise" units by the user, and argument L must be set as L="custom". When argument L = "NULL" no "noise" units are considered. If parameter L is greater than or equal to 1, the units classified in all clusters C, containing a number of units ≤ L, are considered "noise" units. If L="custom", the "noise" units are selected by the user and they must be indicated in the noise argument. The average clustering algorithm was applied to the same data. Using INCAnumclu we determined the number of clusters. Consequently we calculated the INCA index associated with partitions having k = 2, ..., 10 clusters. out <-INCAnumclu (dst,10,"average") plot(out) The procedure gives good results and identifies the three clusters, see Figure 1.
Now consider the following example. Using the data simulation functions included in [16], we generated 100 samples and three groups containing 360, 360 and 360 simulated genes, respectively. A fourth group with 120 "noise" genes was also generated. The INCAnumclu function shows (taken K = 15) that the "noise" genes have hidden the underlying cluster structure. Using the parameter noise with L = 2, the procedure identifies, in the initial partitions 13 "noise" genes. library("WGCNA") library("ICGE") nSamples = 100 set.seed ( Finally, INCAtest function performs the typicality INCA test. Therein, the null hypothesis that a new unit g 0 is a typical unit with respect to a previously fixed partition is tested versus the alternative hypothesis that the unit is atypical.

• Arguments
By calling the function, INCAtest(d, pert, d_test, np = 1000, alpha = 0.05, P = 1), 6 arguments are specified. As before, d is a distance matrix or a dist object with distance information between the n units, and pert is an n-vector that indicates the group to which each unit belongs. The default value indicates the presence of only one group in the data. Note that the expected values of pert are greater than or equal to 1 (for instance 1,2,3,4...). The argument d_test is a vector of length n that contains the distances from the new unit g 0 to the rest of the n units. Note that sampling distributions of the INCA statistics W(g 0 ) and the related statistics U j (g 0 ) (j = 1, ..., k) (see subsection Methods for the definition) can be difficult to find for mixed data, but they may nevertheless be obtained by re-sampling methods, in particular by drawing bootstrap samples as follows. Draw N units g with replacement from the union of C 1 , ..., C k and calculate the corresponding W(g) and U j (g) (j = 1, ..., k) values. This process is repeated 10P times. In this way, the bootstrap distributions under H 0 are obtained. Then, the np and alpha arguments indicate the sample size for the bootstrap procedure, and the level for the test, respectively. Finally, the argument P indicates that the bootstrap procedure is repeated 10P times.  Consider the above simulated gene-expression data that include 120 "noise" genes, 100 samples and three groups containing 360, 360 and 360 simulated genes, respectively. Now, consider only the three groups without "noise" genes. Select one "noise" gene at random and insert the distances from it to the "nonnoise" genes in vector dd. We also considered 100 genes selected at random: 87 "non-noise" genes (27 from group 1, 30 from group 2 and 30 from group 3) and 13 "noise" genes. We computed the INCAtestfunction. The results show that the function correctly predicts the cluster membership of the 87 "non-noise" genes. For the "noise" genes, 8 are considered as atypical and the other 5 are confounded as genes of the initial groups.

Auxiliary functions
These main functions are, of course, based on the auxiliary functions that calculate the geometric variability, the distance between two groups, the proximity function and the INCA statistic itself, which are described at the beginning of the Method Section. Table 2 shows the corresponding functions available from the package, and more detailed comments are presented below.
The vgeo function calculates the geometrical variabil-ityV δ (C j ) (see subsection Methods for the definition) for each group in the data.
• Usage vgeo(d, pert = "onegroup") • Arguments To call vgeo(d, pert = "onegroup") two arguments must be specified. The d argument is a distance matrix or a dist object with distance information between the n units and pert is an n-vector that indicates the group to which each unit belongs. The default value indicates that there is only one group in the data. Note that the expected values of pert are numbers greater than or equal to 1 (for instance 1,2,3,4...).

• Value
The function returns a matrix containing the geometric variability for each group.
The deltas function calculates the distanceˆ 2 ij between each pair of groups C i and C j in the data (see subsection Methods for the definition).

• Value
The function returns a matrix containing the distances between each pair of groups. proxi function calculates the proximity functionφ 2 (g 0 , C j ) (see subsection Methods for the definition) from a specific unit g 0 to the other groups C j in the data. • Usage proxi(d, dx0, pert = "onegroup") • Arguments To call proxi(d, dx0, pert = "onegroup") three arguments must be specified. The d argument is a distance matrix or an object dist for the n units; dx0 is an n-vector containing the distances from g0 to the rest of the units and pert is an n-vector that indicates the unit to which group belongs. The default value indicates that there is only one group in the data. Note that the expected values of pert are numbers greater than or equal to 1 (for instance 1,2,3,4...).

• Value
The function returns a vector containing the proximity function from g 0 to each group.

• Arguments
This needs the same arguments as proxi.

• Value
The function returns an object of incaest class, which is a list containing the following components: Wvalue, is the INCA statistic W(g 0 ); Uvalue, is a vector containing the statistics U j (g 0 ), j = 1,..., k. The associated summary method returns only the INCA statistic value.

Distance functions
Note that all these functions require the previous calculation of a distance between units. Biomedical and genetic studies incorporate any type of data, not only continuous variables, and correlation or other types of dissimilarities are frequently used for clustering. For this reason, ICGE can calculate different distance matrices ( Table 3).
The correlation distance and the Mahalanobis distance [18] are well known, but perhaps the Bhattacharyya and the Gower distances are less. A function named mahalanobis() that calculates the Mahalanobis distance already exists in the stats package, but it is not suitable in our context. While this function calculates the Mahalanobis distance with respect to a given center, our function is designed to calculate the Mahalanobis distance between each pair of units given a data matrix.
The Bhattacharyya distance [19] between two units with frequencies i = (p i1 , ..., p im ) and j = (p j1 , ...,p jm ) is defined by: The Gower distance [20], used for mixed variables, is defined by d 2 ij = 2(1 − s ij ) . As each unit is characterized by m 1 continuous, m 2 binary and m 3 qualitative variables, the similarity coefficient s ij between unit i and j is calculated as follows: where R l is the range of the lth continuous variable (l = 1,..., m 1 ); for the m 2 binary variables, a and d represent the number of matches presence-presence and absence-absence, respectively and a is the number of matches between states for the m 3 qualitative variables. Note that there is also the daisy() function in cluster package, which can calculate the Gower distance for mixed variables. The difference between this function and dgower() in ICGE is that in daisy() the distance is calculated as d ij = 1 -s ij and in dgower() as d 2 ij = 2 * (1 − s ij ). Moreover, dgower() allows us to include missing values (such as NA) and therefore calculates distances based on Gower's weighted similarity coefficients.
The procrustes distance was defined in [21], and it was introduced to find an appropiate distance between genes using their expression profile. It was defined as the procrustes statistics between the procrustes weighted mean associated with two genes, see definition 2, Step C in [21] for more details.

Methods
Briefly, we describe some of the concepts used in the ICGE package. A more detailed description of the procedure and applications can be found in [10]. Consider a dataset with n units and a partition into k groups C 1 , ..., C k . Let δ(g,g') be a distance between units g and g'. Let samples g 1 1 , . . . , g 1 n 1 , . . . , g k 1 , . . . , g k n k , of sizes n 1 , ..., n k be taken from the C 1 , ..., C k groups respectively.
The geometric variability for each group is defined by: Given two groups C i , C j the distance between them is given by: Given the distances from one specific unit g 0 to the rest of the units organized in the k groups, the proximity function of unit g 0 to C j is defined by: For more details on these concepts see [22]. From these previous concepts we define the INCA statistic. Consider a fixed unit g 0 , which may be an element of some C j , j = 1,..., k or may belong to some unknown cluster, i.e., it may be an atypical unit. This statistic trades off between minimizing the weighted sum of proximities of g 0 to clusters (which takes into consideration the within-cluster variabilities) and maximizing the weighted sum of the squared distances between clusters (between-cluster variability) -a common feature of a clustering criterion. Moreover, this statistic can be interpreted (see Figure 2) as the (squared) orthogonal distance or height h of g 0 on the hyperplane generated by the centers of C i (i = 1,..., k), denoted in Figure 2 by a i , i = 1,..., k. Then, points which lie significantly far from this hyperplane are held to be atypical. This intuitive idea is used both to determine the number of clusters, and to detect atypical units among existing clusters. The definition of the INCA statistic is: where,

Estimating the number of clusters
We define the INCA index, INCA k , associated with the partition C 1 ,..., C k , as the probability of finding well classified units. Consider that n units are divided into k clusters C 1 ,...,C k of sizes n 1 ,..., n k , respectively. Fix cluster C j and for each unit g belonging to the data set, consider the value of INCA statistic, W C j (g) , with respect to clusters C i with i ≠ j. Consider the maximum, W C j , of these (squared) orthogonal distances for all the units that do not belong to C j . Then consider the following criterion: Unit g of C j is well classified in C j if W C j (g) > W C j . Unit g of C j is poorly classified in C j if W C j (g) ≤ W C j , in fact, it is closer to another cluster. Let N j be the total number of units in C j which are well classified. Thus we define the INCA index, INCA k , associated with the partition C 1 ,..., C k as the frequency of well classified, i.e.,

Procedure for detecting an atypical observation
Suppose now that a cluster analysis is performed and the optimal number of clusters is found. Let g 0 be a new unit and consider the INCA test to decide whether g 0 belongs to one of the fixed clusters C j , j = 1,..., k or, on the contrary, whether it is an atypical observation, belonging to some different and unknown cluster. Compute W(g 0 ): if this value is significant it means that g 0 comes from a different and unknown cluster. Otherwise, we allocate g 0 to C i using the rule: where U j (g 0 ) = φ 2 j (g 0 ) − W(g 0 ), j = 1, ..., k. For a geometric interpretation, see Figure 2, where for simplicity the (squared) projection U j (g 0 ) is denoted by r j , j = 1,..., k. So, the above criterion follows the next geometric and intuitive allocation rule: A more detailed explanation of these procedures, properties and examples can be found in [10].

Remarks and limitations of the package
For ICGE package the computing times are reasonable. Table 4 shows runtime for functions INCAindex and INCAtest based on synthetic data sets of different sample sizes (n = 50,100, 500 or 1000), and different number of groups k = 2, 3, 5, 10, 15, 20, 30 or 40. Observe that for a large number of clusters, the time increases exponentially.
Furthermore, note that in the main functions INCAindex, INCAnumclu and INCAtest the argument d is a distance matrix or a dist object. Therefore, any kind of dissimilarity can be used, not only those included in ICGE, and in this sense the package is flexible.
Another aspect is also relevant. Let p be the dimensionality of the Euclidean space in which the original metric space (S, δ) can be embedded (see [10], section 2). If the number of clusters k is equal to or greater than the dimensionality p, the hyperplane generated by the cluster centers will simply be the whole space, and the INCA statistic will always be zero. This special situation should be taken into account when using these functions, and it may be a limitation of the method (and of the package).

Application to real and simulated data
Functions and methods are illustrated and tested on both real and simulated data.

Chowdary's data set
Chowdary et al., compared in [23] pairs of snap-frozen and RNAlater preservative-suspended tissue from lymph node-negative breast tumors (B) and Dukes' B colon tumors (C). ICGE package proved to be effective at automatically discovering the both groups (see Figure 3). The procedure chooses k as the value of k prior to the first biggest slope decrease. Using the correlation distance, the clustering procedure PAM was used to partition the 94 samples successively into 2, 3, ..., 10 clusters. The plot indicates that there are two clusters as it was already reported. This data set is included in the package.

Golub's data set
Golub et al., studied in [24] gene expression in two types of acute leukemia: acute lymphoblastic leukemia (ALL) and acute myeloid leukemia (AML). They worked with 27 ALL and 11 AML samples. There were no missing values and we standardized the data as described in [25]. We evaluated the performance of the typicality test using the correlation distance. We considered 5 and 3 units at random from ALL and AML group, respectively. Using ICGE we decided whether these unknown units are typical units with respect to ALL and AML groups or whether on the contrary, they are units from another group. We repeated this procedure ten times for each group. Good results at the 5% level were obtained. In each case, the units were identified as units from one of the two groups and were well classified. Data can be found in the multtest library.

Synthetic time course data
We generated time course data with 8 groups, 15 genes in each group and six time points, following 8 different profiles (see Figure 4): G 1 , constant profile; G 2 , monotone increasing but with small difference between the expression value at the first and the last time points; G 3 , constant profile at 1, 2 and 3, and later monotone increasing; G 4 up-down profile with maxima at 2; G 5 , up-down with maxima at 5; G 6 , down-up profile with minima at 3; G 7 , cyclic with maxima at 2 and minima at 5; G 8 , down-up constant profile with minima at 2 and constant at 3,4,5 and 6. The procrustes distance was used [21]. When genes in G 1 are considered as new genes to be classified in G 2 , G 3 , G 4 , G 5 , G 6 , G 7 or G 8 the procedure identifies the 15 as belonging to a new group. When genes in G 2 are considered as new genes to be classified in G 1 , G 3 , G 4 , G 5 , G 6 , G 7 or G 8 the procedure identifies 3 as belonging to a new group (as we know) and 12 as belonging to G 1 . When genes in G i , i = 3,4,5,6,7,8 are considered as new genes to be classified in G j , j ≠ i, the procedure identifies the 15 genes as belonging to a new group (as we know). ICGE package proved to be effective at automatically discovering atypical genes. This data set is included in the package.

Lymphatic cancer data
The data from [26] demonstrates that ICGE can correctly identify situations in which the data do not present a clear cluster structure (see Figure 5). The Lymphatic data set consists of 148 instances of the diagnosis of four lymphatic cancer classes (normal found, metastases, malign lymph and fibrosis), with 2, 81, 61 and 4 samples, respectively. Note that it is very difficult for any method to find four clusters given the small sizes of two of the groups. 18 mixed variables were measured: 1 quantitative; 9 binaries and 8 multi-state. ICGE can correctly identify situations in which the data do not present cluster structure. Notice that this is an advantage over other procedures. The PAM clustering procedure was used to partition the 148 samples successively into 2, 3, ..., 10 clusters. Gower's distance was used. As expected, the low values of the index indicate no cluster structure. This data set is included in the package. For additional details read [10].

Conclusions
ICGE offers a friendly implementation for R users that is capable of solving important questions in genetic analysis and in general studies, where an unsupervised classification is necessary. One aspect of the package is the estimation of the number of clusters. The ICGE procedures provide functionalities that are not offered by other tools; in particular, they can deal with mixtures of categorical and continuous data, a situation usually found by applied researchers. Furthermore, it can detect the absence of cluster structure. Only the silhouette method is appropriate for any kind of data, but this index cannot detect the absence of cluster structure. Thus, our method is able to deal with data of a more general kind. In contrast to other classification techniques, given a new unit to be classified, it does not automatically classify it in previously specified clusters. The procedure decides whether a new unit belongs to a new group. For this reason, the ICGE package is able to solve the typicality problem. Other methods present restrictions in the kind of data or number of groups, but the ICGE package can work with any kind of data and has no limitation on the number of groups. For all these reasons ICGE could be very useful to a large number of researchers.

Availability and requirements
The ICGE package has been developed for the free statistical R environment (http://www.r-project.org) and will run under the major operating systems.   Synthetic time course data. Synthetic time course data following 8 different profiles: G 1 , constant profile; G 2 , monotone increasing but with small difference between the expression value at the first and the last time points; G 3 , constant profile at 1, 2 and 3, and later monotone increasing; G 4 up-down profile with maxima at 2; G 5 , up-down with maxima at 5; G 6 , down-up profile with minima at 3; G 7 , cyclic with maxima at 2 and minima at 5; G 8 , down-up constant profile with minima at 2 and constant at 3,4,5 and 6.