-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include mkPriors/SimulateMixture from flowClust
- Loading branch information
mikejiang
committed
Aug 13, 2021
1 parent
4b28ad5
commit 6a75b8f
Showing
10 changed files
with
1,026 additions
and
4 deletions.
There are no files selected for viewing
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
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]> | ||
|
@@ -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 | ||
|
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
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
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 | ||
} |
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
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 | ||
|
||
} |
Oops, something went wrong.