LinearCorrectedVariance: Estimates variance of a transformation of latent Poisson...

Description Usage Arguments Details Value Author(s) Examples

View source: R/CorrectedVarianceEstimators.R

Description

Given a data matrix X[i,j] which follows a Poisson distribution with mean Lambda[i,j], this function estimates the covariance matrix of a transformation f of the latent Lambda.

Usage

1
2
3
4

Arguments

X

the data matrix

g

an estimator of the transformation function f(Lambda). That is, if X~Poisson(Lambda), g(X) should be an estimator of f(Lambda).

CVar

an estimator of the conditional variance of g(X) conditional on Lambda.

ECVar

an estimator of the conditional variance of g(X) conditional on Lambda.

Details

LinearCorrectedVariance merely estimates the covariance matrix of the latent Poisson means without transformation. LinearCorrectedVarianceSeqDepth deals with the common case in microbiome and other analysis, where the Poisson means are subject to large multiplicative noise not associated with the parameters of interest. In these cases, we would like to estimate the covariance of the compositional form of Lambda. That is, we want to scale the rows of Lambda to all have sum 1, and estimate the covariance matrix of the resultant matrix. This method uses the actual row sums of X as estimates of the scaling to be performed. TransformedVariance estimates the variance of a function of Lambda. It takes two additional parameters: g and CVar which are functions of X. g should be an estimator for the desired transformation f(Lambda) from an observation X. For example, if f(Lambda)=Lambda^2, then the unbiassed estimator is X*(X-1). CVar is an estimator for the conditional variance of g(X) given Lambda. For example, if f(Lambda)=Lambda^2, and we use the unbiassed g(X)=X*(X-1), then the variance of g(X) is 4*Lambda^3+3*Lambda^2, so an unbiassed estimator for this is CVar(X)=4*X*(X-1)*(X-2)+3*X*(X-1)=X*(X-1)*(4*X-5). The function polynomial_transformation will compute the unbiassed estimators for a given polynomial. The function makelogtransformation compute estimators for the log function. TransformedVarianceECV is the same as TransformedVariance, except that the third parameter estimates the average conditional variance from a sample of values of X, rather than a single value.

Value

An estimated covariance matrix for the transformed latent means.

Author(s)

Toby Kenney tkenney@mathstat.dal.ca and Tianshu Huang

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<-20  #20 observations
p<-5   #5 dimensions
r<-2   #rank 2

mean<-10*c(1,3,2,1,1)

Z<-rnorm(n*r)
dim(Z)<-c(n,r)
U<-rnorm(p*r)
dim(U)<-c(r,p)

Latent<-Z%*%U+rep(1,n)%*%t(mean)

X<-rpois(n*p,as.vector(Latent))
dim(X)<-c(n,p)

LinearCorrectedVariance(X)

seqdepth<-exp(rnorm(n)+2)
Xseqdep<-rpois(n*p,as.vector(diag(seqdepth)%*%Latent))
dim(Xseqdep)<-c(n,p)

LinearCorrectedVarianceSeqDepth(Xseqdep)


squaretransform<-polynomial_transformation(c(1,0))

Xsq<-rpois(n*p,as.vector(diag(seqdepth)%*%Latent)^2)

dim(Xsq)<-c(n,p)

TransformedVariance(Xsq,squaretransform$g,squaretransform$CVar)

Xexp<-rpois(n*p,as.vector(diag(seqdepth)%*%exp(Latent)))

logtrans<-makelogtransformation(3,4)

TransformedVarianceECV(X,logtrans$g,logtrans$ECVar)

PoissonPCA documentation built on Aug. 17, 2021, 5:09 p.m.