ZIPPCApn: ZIPPCA

Description Usage Arguments Value Examples

View source: R/ZIPPCA.R

Description

Zero-Inflated Probabilistic PCA (ZIPPCA), for dimension reduction and data ordination of multivariate abundance data, and propose an efficient variational approximation method for estimation, inference, and prediction.

Usage

1
2
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

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 intercepts that adjusts for the sequencing depth

  • gamma coeffcients of sample covariate

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

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
 n.n = 100
 n.m = 50
 n.factors = 2
 set.seed(37)
 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.m, ncol = n.factors)
 for(j in 1:n.m){
   betaj[j,] <- rnorm(n.factors, mean =0, sd = 1)
 }
 beta0 <- rep(1,n.m)
 alpha <- rep(0,n.n)
 l <- matrix(alpha,n.n,n.m) +matrix(beta0,n.n,n.m,byrow=TRUE) + f %*% t(betaj)
 lambda <- exp(l)
 eta_j <- runif(n.m, 0,1)
 z <- matrix(0,n.n,n.m)
 for(i in 1:n.n){
   z[i,] <- rbinom(n.m, size=1, prob=eta_j)
 }
 X <- matrix(0,n.n,n.m,byrow = TRUE)
 for(i in 1:n.n){
   for(j in 1:n.m){
     X[i,j] <- rnbinom(n=1,size=10,mu=lambda[i,j])
   }
 }
 X[z==1]=0
 zerorow <- which(rowSums(X)==0)
 if(length(zerorow) >0 ){
   X <- X[-zerorow,];f <- f[-zerorow,]
 }
 zerocol <- which(colSums(X)==0)
 if(length(zerocol) >0 ){
   X <- X[,-zerocol];betaj <- t(t(betaj)[,-zerocol])
 }
 result <- ZIPPCA::ZIPPCApn(X)
 f_coordinates <- result$lvs$factor_scores

YanyZeng/ZIPPCA documentation built on March 17, 2021, 4:57 p.m.