Skip to content

Instantly share code, notes, and snippets.

@ramhiser
Created November 15, 2012 17:28
Show Gist options
  • Save ramhiser/4079946 to your computer and use it in GitHub Desktop.
Save ramhiser/4079946 to your computer and use it in GitHub Desktop.
flowClust Quantile
#' Computes the quantile from flowClust for a given vector of probabilties
#'
#' We estimate the quantile from a \code{flowClust} fit with a combination of
#' numerical integration and a root-finding method. We are effectively
#' estimating the cumulative distribution function (CDF) of the mixture density
#' estimated by \code{flowClust}.
#'
#' Because we are using numerical methods, we also need an \code{interval} of
#' values in which we will attempt to find the specified quantile.
#'
#' @param p vector of probabilities
#' @param object an object containing the \code{flowClust} fit
#' @return the quantile corresponding to the specified probabilities
quantile_flowClust <- function(p, object) {
t_quantiles <- sapply(seq_len(object@K), function(k) {
nu <- ifelse(length(object@nu) == 1, object@nu, object@nu[k])
qt(p, df = nu, ncp = object@mu[k])
})
weighted.mean(t_quantiles, w = object@w)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment