ZIPPCApn: ZIPPCApn

Description Usage Arguments Value Examples

View source: R/ZIPPCApn.R

Description

Microbiome data denoising framework (mbDenoise) with zero-inflated probabilistic PCA with Poisson (ZIPPCA-Poi) and negative-binomial model (ZIPPCA-NB), which can be used for downstream statistical analysis including ordination, compositional normalization, differential abundance analysis, etc. mbDenoise with ZIPPCA-NB model is recommended for empirical data analysis.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ZIPPCApn(
  X,
  V = NULL,
  family = "negative.binomial",
  n.factors = 2,
  rank = FALSE,
  trace = FALSE,
  maxit = 100,
  parallel = TRUE
)

Arguments

X

matrix of observations.

V

vector of the sample covariate.

family

distribution of models. Two options are "poisson" and "negative.binomial". Defaults to "negative.binomial".

n.factors

the rank or number of factors, after dimensional reduction. Defaults to 2.

rank

logical, if TRUE, the rank or number of factors, is chosen from 1 to 5 by HIC (hybrid information criterion). Defaults to FALSE.

trace

logical, defaults to FALSE. if TRUE each current iteration step information will be printed.

maxit

maximum number of iterations within optim and constrOptim function, defaults to 100.

parallel

logical, if TRUE, use parallel toolbox to accelerate.

Value

VLB

variational lower bound of log likelihood

lvs

list of latent variables

  • pi the probabilities of excess zeros

  • factor_scores coordinates or factor scores in low-dimensional subspace

  • factor_scores2 coordinates or factor scores in low-dimensional subspace with defalt rank 2, which is suitable for visualization.

params

list of model parameters

  • factor_coefs_j coefficients of latent variables fator scores or factor loadings

  • factor_coefs_0 taxon-specific intercepts

  • alpha sample-specifc coeffcient that adjusts for the sequencing depth

  • dispersion taxon-specific over-dispersion parameter for negative binomial distribution

  • gamma coeffcients of sample covariate

  • tuo taxon-specific parameter of zero-inflation probability

  • c sample-specific parameter of zero-inflation probability

Q

the underlying composition of microbiome data

muz

the denoised counts of microbiome data

hic

the number of the rank selection, chosen by HIC type information criterion

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
n.n = 60
n.w = 100
n.factors = 2
set.seed(1)
si <- diag(n.factors)
me <- c(0,0)
f <- matrix(0,nrow = n.n, ncol = n.factors)
for(i in 1:n.n){
 f[i,] <- rnorm(n.factors, mean = 0, sd = 1)
}
betaj <- matrix(0,nrow = n.w, ncol = n.factors)
for(j in 1:n.w){
  betaj[j,] <- runif(n.factors,-3,3)
}
alpha <- runif(n.n,-5,5)
beta0 <- rep(0,n.w)
g <- rep(0,n.w*0.5*0.5)
gamma <- c(g,-g,rep(0,(n.w-n.w*0.5)))
X_cov<- c(rep(1,n.n/2),rep(0,n.n/2))
ll <- f %*% t(betaj)  +matrix(alpha,n.n,n.w)+matrix(beta0,n.n,n.w,byrow=TRUE)
exp_mat <- exp(ll)
eta_mat <- matrix(0.25,n.n,n.w,byrow=TRUE)
z <- matrix(0,n.n,n.w,byrow = TRUE)
for(i in 1:n.n){
  z[i,] <- rbinom(n.w, size=1, prob=eta_mat[i,])
}
sum <- rowSums((1-z)*exp_mat)
Qn_z <- (1-z)*exp_mat/sum
sum <- rowSums(exp_mat)
Qn <- exp_mat/sum
X <- matrix(0,n.n,n.w,byrow = TRUE)
 for(i in 1:n.n){
  for(j in 1:n.w){
    X[i,j] <- rnbinom(n=1,size=10,mu=exp_mat[i,j])
 }
 }
X[z==1]=0
zerorow <- which(rowSums(X)==0)
if(length(zerorow) >0 ){
   X <- X[-zerorow,];X_cov<-X_cov[-zerorow];f <- f[-zerorow,];
   Qn <- Qn[-zerorow,];Qn_z <- Qn_z[-zerorow,];
}
zerocol <- which(colSums(X)==0)
if(length(zerocol) >0 ){
  X <- X[,-zerocol];betaj <- t(t(betaj)[,-zerocol]);
  Qn <- Qn[,-zerocol];Qn_z <- Qn_z[,-zerocol];
}
re_zinb_cov <- ZIPPCApn(X,X_cov)
re_zinb <- ZIPPCApn(X)

YanyZeng/mbDenoise documentation built on Dec. 18, 2021, 7:25 p.m.