clustering-methods: Method to perform clustering on the samples of an ExposomeSet

Description Usage Arguments Value Note See Also Examples

Description

This method allows to create an ExposomeClust object from an ExposomeSet object by clustering samples through the exposure levels. The method is flexible to accept any clustering method (method) that allows to obtain a classification (cmethod) of the samples. The function assigned to argument method must have an argument called data, waiting for the matrix of exposures (samples as rows, exposures as columns). If the result object of the method has no accessor $classification, then a cmethod is required and will be applied on the result of method to obtain a labelled vector with the samples' classification.

Usage

1
clustering(object, method, cmethod, ..., warnings = TRUE)

Arguments

object

ExposomeSet containing the exposures used for the clustering process

method

Function applied to the exposures of object. This function must has an argument named as data that will receive the matrix of exposures.

cmethod

(optional) Function to obtain the classification from the object generated with method.

...

Passed to content of method.

warnings

(default TRUE) If set to FALSE warnings will not be displayed.

Value

ExposomeClust with the original exposures and the classification of each exposure.

Note

The function assigned to cmethod will be directy applied to the result of the method as: cmethod(model); being model the result of method.

See Also

classification to see how to obtain the classification of the samples from an ExposomeClust, plotClassification to plot the groups

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
data("exposome")

# EXAMPLE 1: Clustering with mclust
library(mclust)
c <- clustering(expo[12:32, ], method = Mclust, G = 2)
table(classification(c))  # This works since the result of Mclust has an accessor
                   # $classification

# EXAMPLE 2: Cluseting with flexmix
library(flexmix)
# First we carete a function to apply flexmix to the ExposomeSet
flexmix_clust <- function(data, ...) {
  data <- as.matrix(data)
  flexmix(formula = data~1, ...)
}

# Then if we apply the method to the ExposomeSet it will crash:
# c <- clustering(expo[12:32, ], method = flexmix_clust, k = 2, model = FLXMCmvnorm())
# Because the method does not know how to obtain the classification for the result
# since flexmix has not an accessor called $classiciation

# We create a function to get the classification
flexmix_clas <- function(model, ...) {
  return(clusters(model))
}

# We put it to the ExposomeClust
c <- clustering(expo[12:32, ], method = flexmix_clust, cmethod = flexmix_clas,
    k = 2, model = FLXMCmvnorm())
classification(c) # This works because the ExposomeClust has a way to get
                  # the classification

rexposome documentation built on March 13, 2021, 2:01 a.m.