Skip to content

Commit

Permalink
include mkPriors/SimulateMixture from flowClust
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejiang committed Aug 13, 2021
1 parent 4b28ad5 commit 6a75b8f
Show file tree
Hide file tree
Showing 10 changed files with 1,026 additions and 4 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: flowStats
Type: Package
Title: Statistical methods for the analysis of flow cytometry data
Version: 4.5.2
Version: 4.5.3
Author: Florian Hahne, Nishant Gopalakrishnan, Alireza Hadj Khodabakhshi,
Chao-Jen Wong, Kyongryun Lee
Maintainer: Greg Finak <[email protected]>, Mike Jiang <[email protected]>, Jake Wagner <[email protected]>
Expand All @@ -17,7 +17,8 @@ Suggests:
Encoding: UTF-8
Depends: R (>= 3.0.2)
Imports: BiocGenerics, MASS, flowCore (>= 1.99.6), flowWorkspace, ncdfFlow(>= 2.19.5), flowViz, fda (>= 2.2.6),
Biobase, methods, grDevices, graphics, stats, cluster, utils, KernSmooth, lattice, ks, RColorBrewer, rrcov
Biobase, methods, grDevices, graphics, stats, cluster, utils, KernSmooth, lattice, ks, RColorBrewer, rrcov, corpcor,
mnormt
Enhances: RBGL,graph
License: Artistic-2.0
Lazyload: yes
Expand Down
40 changes: 38 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,38 @@ importMethodsFrom(Biobase, channel)
importMethodsFrom(BiocGenerics, cbind, colnames, lapply, mapply, order,
paste, pmax, pmin, rbind, rownames, sapply, setdiff,
table, unique)


importFrom(corpcor,cov.shrink)

importFrom(grDevices,cm.colors)
importFrom(grDevices,gray)
importFrom(grDevices,heat.colors)
importFrom(grDevices,rainbow)
importFrom(grDevices,terrain.colors)
importFrom(grDevices,topo.colors)
importFrom(graphics,abline)
importFrom(graphics,contour)
importFrom(graphics,curve)
importFrom(graphics,hist)
importFrom(graphics,image)
importFrom(graphics,lines)
importFrom(graphics,points)
importFrom(graphics,stripchart)
importFrom(graphics,title)
importFrom(mnormt,rmt)
importFrom(parallel,mclapply)
importFrom(stats,BIC)
importFrom(stats,cov)
importFrom(stats,dist)
importFrom(stats,kmeans)
importFrom(stats,mahalanobis)
importFrom(stats,na.omit)
importFrom(stats,optim)
importFrom(stats,optimize)
importFrom(stats,qchisq)
importFrom(stats,qf)
importFrom(stats,qnorm)
importFrom(stats,quantile)
importFrom(stats,var)
importFrom("grDevices", "colorRampPalette")
importFrom("grDevices", "devAskNewPage")
importFrom("utils", "read.csv")
Expand All @@ -27,6 +57,7 @@ importFrom("rrcov", "CovMcd")

importFrom(MASS, huber, hubers, rlm, cov.rob)


importFrom(ks, binning, hpi)

importFrom(fda, Data2fd, create.bspline.basis, eval.fd, fdPar,fd,int2Lfd,vec2Lfd,norder,
Expand Down Expand Up @@ -83,6 +114,11 @@ export("lymphGate",
"gate_tail",
"tailgate"
)
export(SimulateMixture)
export(flowClust2Prior)
export(mkPrior)
export(plotPrior)
exportMethods(mkPrior)

exportClasses("lymphFilter","rangeFilter","curv1Filter",
"curv2Filter", "norm2Filter")
Expand Down
73 changes: 73 additions & 0 deletions R/SimulateMixture.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#' Random Generation from a t Mixture Model with Box-Cox Transformation
#'
#' This function can be used to generate a sample from a multivariate \eqn{t}
#' mixture model with Box-Cox transformation.
#'
#'
#' @param N The number of observations.
#' @param w A vector of length \eqn{K}, containing the \eqn{K} cluster
#' proportions.
#' @param mu A matrix of size \eqn{K \times P}{K x P}, where \eqn{K} is the
#' number of clusters and \eqn{P} is the dimension, containing the \eqn{K} mean
#' vectors.
#' @param sigma An array of dimension \eqn{K \times P \times P}{K x P x P},
#' containing the \eqn{K} covariance matrices.
#' @param nu The degrees of freedom used for the \eqn{t} distribution.
#' @param lambda The Box-Cox transformation parameter. If missing, the
#' conventional \eqn{t} distribution without transformation will be used.
#' @return A matrix of size \eqn{N \times P}{N x P}.
#' @author Raphael Gottardo <\email{raph@@stat.ubc.ca}>, Kenneth Lo
#' <\email{c.lo@@stat.ubc.ca}>
#' @seealso \code{\link{flowClust}}
#' @keywords datagen
#' @examples
#' ### Number of components
#' K <- 5
#' ### Dimension
#' p <- 2
#' ### Number of observations
#' n <- 200
#' Mu <- matrix(runif(K*p, 0, 20), K, p)
#' Sigma <- array(0, c(K, p, p))
#'
#' for (k in 1:K)
#' {
#' Sigma[k,,][outer(1:p, 1:p, ">")] <- runif(p*(p-1)/2,-.1,.1)
#' diag(Sigma[k,,]) <- runif(p,0,1)
#' ### Make sigma positive definite
#' Sigma[k,,] <- Sigma[k,,] %*% t(Sigma[k,,])
#' }
#'
#' ### Generate the weights
#' w <- rgamma(K,10,1)
#' w <- w/sum(w)
#'
#' y <- SimulateMixture(n, w, Mu, Sigma, nu=4)
#' @export
#' @importFrom mnormt rmt
SimulateMixture <- function(N, w, mu, sigma, nu=4, lambda)
{
# Number of clusters
K <- length(w)
if (K==1) {
mu <- matrix(mu, 1)
sigma <- array(sigma, c(1, ncol(mu), ncol(mu)))
} else if (length(mu)==K) {
mu <- matrix(mu, K, 1)
sigma <- array(sigma, c(K, 1, 1))
}
# dimension
py <- ncol(mu)
y <- matrix(0, N, py)
nu <- rep(nu,K)
if (!missing(lambda))
lambda <- rep(lambda,K)

label <- sample(1:K, N, replace=T, prob=w)
count <- table(c(label,1:K))-1
for (k in 1:K) if (count[k]>0) {
y[label==k,] <- rmt(count[k], mu[k,], sigma[k,,], nu[k])
if (!missing(lambda)) y[label==k,] <- rbox(y[label==k,], lambda[k])
}
y
}
10 changes: 10 additions & 0 deletions R/ellipse.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#' convert ellipse from cov/mu to points
#' used to plot priors
ellipse <- function (cov, centre, level = 0.95)
{
colnames(cov) <- c("x", "y")
eg <- ellipsoidGate(.gate = cov, mean = centre, distance = sqrt(qchisq(level, 2)))
pg <- as(eg, "polygonGate")
pg@boundaries

}
Loading

0 comments on commit 6a75b8f

Please sign in to comment.