Created
November 15, 2012 17:28
-
-
Save ramhiser/4079946 to your computer and use it in GitHub Desktop.
flowClust Quantile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' 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