flowClust-class | R Documentation |
This function performs automated clustering for identifying cell populations in flow cytometry data. The approach is based on the tmixture model with the Box-Cox transformation, which provides a unified framework to handle outlier identification and data transformation simultaneously.
flowClust(
x,
expName = "Flow Experiment",
varNames = NULL,
K,
nu = 4,
lambda = 1,
trans = 1,
min.count = 10,
max.count = 10,
min = NULL,
max = NULL,
randomStart = 0,
prior = NULL,
usePrior = "no",
criterion = "BIC",
...
)
x |
A numeric vector, matrix, data frame of observations, or object of
class |
expName |
A character string giving the name of the experiment. |
varNames |
A character vector specifying the variables (columns) to be included in clustering. When it is left unspecified, all the variables will be used. |
K |
An integer vector indicating the numbers of clusters. |
nu |
The degrees of freedom used for the |
lambda |
The initial transformation to be applied to the data. |
trans |
A numeric indicating whether the Box-Cox transformation parameter is estimated from the data. May take 0 (no estimation), 1 (estimation, default) or 2 (cluster-specific estimation). |
min.count |
An integer specifying the threshold count for filtering
data points from below. The default is 10, meaning that if 10 or more data
points are smaller than or equal to |
max.count |
An integer specifying the threshold count for filtering
data points from above. Interpretation is similar to that of
|
min |
The lower boundary set for data filtering. Note that it is a vector of length equal to the number of variables (columns), implying that a different value can be set as per each variable. |
max |
The upper boundary set for data filtering. Interpretation is
similar to that of |
randomStart |
A numeric value indicating how many times a random parition of the data is generated for initialization. The default is 0, meaning that a deterministic partition based on kmeans clustering is used. A value of 10 means random partitions of the data will be generated, each of which is followed by a short EM run. The partition leading to the highest likelihood value will be adopted to be the initial partition for the eventual long EM run. |
prior |
The specification of the prior. Used if usePrior="yes" |
usePrior |
Argument specifying whether or not the prior will be used. Can be "yes","no","vague". A vague prior will be automatically specified if usePrior="vague" |
criterion |
A character string stating the criterion used to choose the
best model. May take either |
... |
other arguments: B: The maximum number of EM iterations.Default is 500. tol: The tolerance used to assess the convergence of the EM. default is 1e-5. nu.est: A numeric indicating whether level: A numeric value between 0 and 1 specifying the threshold quantile level used to call a point an outlier. The default is 0.9, meaning that any point outside the 90% quantile region will be called an outlier. u.cutoff: Another criterion used to identify outliers. If this is
z.cutoff: A numeric value between 0 and 1 underlying a criterion which may
be used together with B.init: The maximum number of EM iterations following each random partition in random initialization. Default is the same as B. tol.init: The tolerance used as the stopping criterion for the short EM runs in random initialization. Default is 1e-2. seed: An integer giving the seed number used when
control: An argument reserved for internal use. |
Estimation of the unknown parameters (including the Box-Cox parameter) is done via an Expectation-Maximization (EM) algorithm. At each EM iteration, Brent's algorithm is used to find the optimal value of the Box-Cox transformation parameter. Conditional on the transformation parameter, all other estimates can be obtained in closed form. Please refer to Lo et al. (2008) for more details.
The flowClust package makes extensive use of the GSL as well as BLAS. If an optimized BLAS library is provided when compiling the package, the flowClust package will be able to run multi-threaded processes.
Various operations have been defined for the object returned from
flowClust
.
In addition, to facilitate the integration with the flowCore package
for processing flow cytometry data, the flowClust
operation can be
done through a method pair (tmixFilter
and
filter
) such that various methods defined in
flowCore can be applied on the object created from the filtering
operation.
If K
is of length 1, the function returns an object of class
flowClust
containing the following slots, where K
is the number
of clusters, N
is the number of observations and P
is the number
of variables:
expName |
Content of the |
varNames |
Content of the |
K |
An integer showing the number of clusters. |
w |
A vector of length |
mu |
A matrix of size |
sigma |
An array of dimension |
lambda |
The Box-Cox transformation parameter estimate. |
nu |
The
degrees of freedom for the |
z |
A matrix of size
|
u |
A
matrix of size |
label |
A
vector of size |
uncertainty |
A vector of size |
ruleOutliers |
A numeric vector of size 3, storing the
rule used to call outliers. The first element is 0 if the criterion is set
by the |
flagOutliers |
A
logical vector of size |
rm.min |
Number of points filtered from below. |
rm.max |
Number of points filtered from above. |
logLike |
The log-likelihood of the fitted mixture model. |
BIC |
The Bayesian Information Criterion for the fitted mixture model. |
ICL |
The Integrated Completed Likelihood for the fitted mixture model. |
If K
has a length >1, the function returns an object of class
flowClustList
. Its data part is a list with the same length as
K
, each element of which is a flowClust
object corresponding
to a specific number of clusters. In addition, the resultant
flowClustList
object contains the following slots:
index
An integer giving the index of the list element corresponding
to the best model as selected by criterion
.
criterion
The
criterion used to choose the best model – either "BIC"
or
"ICL"
.
Note that when a flowClustList
object is used in place of a
flowClust
object, in most cases the list element corresponding to the
best model will be extracted and passed to the method/function call.
Raphael Gottardo <raph@stat.ubc.ca>, Kenneth Lo <c.lo@stat.ubc.ca>
Lo, K., Brinkman, R. R. and Gottardo, R. (2008) Automated Gating of Flow Cytometry Data via Robust Model-based Clustering. Cytometry A 73, 321-332.
summary
,
plot
,
density
,
hist
, Subset
,
split
, ruleOutliers
, Map
,
SimulateMixture
library(flowCore)
data(rituximab)
### cluster the data using FSC.H and SSC.H
res1 <- flowClust(rituximab, varNames=c("FSC.H", "SSC.H"), K=1)
### remove outliers before proceeding to the second stage
# %in% operator returns a logical vector indicating whether each
# of the observations lies within the cluster boundary or not
rituximab2 <- rituximab[rituximab %in% res1,]
# a shorthand for the above line
rituximab2 <- rituximab[res1,]
# this can also be done using the Subset method
rituximab2 <- Subset(rituximab, res1)
### cluster the data using FL1.H and FL3.H (with 3 clusters)
res2 <- flowClust(rituximab2, varNames=c("FL1.H", "FL3.H"), K=3)
show(res2)
summary(res2)
# to demonstrate the use of the split method
split(rituximab2, res2)
split(rituximab2, res2, population=list(sc1=c(1,2), sc2=3))
# to show the cluster assignment of observations
table(Map(res2))
# to show the cluster centres (i.e., the mean parameter estimates
# transformed back to the original scale)
getEstimates(res2)$locations
### demonstrate the use of various plotting methods
# a scatterplot
plot(res2, data=rituximab2, level=0.8)
plot(res2, data=rituximab2, level=0.8, include=c(1,2), grayscale=TRUE,
pch.outliers=2)
# a contour / image plot
res2.den <- density(res2, data=rituximab2)
plot(res2.den)
plot(res2.den, scale="sqrt", drawlabels=FALSE)
plot(res2.den, type="image", nlevels=100)
plot(density(res2, include=c(1,2), from=c(0,0), to=c(400,600)))
# a histogram (1-D density) plot
hist(res2, data=rituximab2, subset="FL1.H")
### to demonstrate the use of the ruleOutliers method
summary(res2)
# change the rule to call outliers
ruleOutliers(res2) <- list(level=0.95)
# augmented cluster boundaries lead to fewer outliers
summary(res2)
# the following line illustrates how to select a subset of data
# to perform cluster analysis through the min and max arguments;
# also note the use of level to specify a rule to call outliers
# other than the default
flowClust(rituximab2, varNames=c("FL1.H", "FL3.H"), K=3, B=100,
min=c(0,0), max=c(400,800), level=0.95, z.cutoff=0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.