Title: | Analysis of zero-inflated count data |
---|---|
Description: | zitools allows for zero inflated count data analysis by either using down-weighting of excess zeros or by replacing an appropriate proportion of excess zeros with NA. Through overloading frequently used statistical functions (such as mean, median, standard deviation), plotting functions (such as boxplots or heatmap) or differential abundance tests, it allows a wide range of downstream analyses for zero-inflated data in a less biased manner. This becomes applicable in the context of microbiome analyses, where the data is often overdispersed and zero-inflated, therefore making data analysis extremly challenging. |
Authors: | Carlotta Meyring [aut, cre] |
Maintainer: | Carlotta Meyring <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 1.1.0 |
Built: | 2024-11-30 05:52:35 UTC |
Source: | https://github.com/bioc/zitools |
Arithmetic operators for a Zi-class object
## S4 method for signature 'Zi,ANY' e1 * e2
## S4 method for signature 'Zi,ANY' e1 * e2
e1 |
|
e2 |
|
a Zi
-class object after a specific arithmetic
operation is performed
data(mtx) Zi <- ziMain(mtx) Zi*Zi Zi*2
data(mtx) Zi <- ziMain(mtx) Zi*Zi Zi*2
Arithmetic operators for a Zi-class object
## S4 method for signature 'Zi,ANY' e1 / e2
## S4 method for signature 'Zi,ANY' e1 / e2
e1 |
|
e2 |
|
a Zi
-class object after a specific arithmetic
operation is performed
data(mtx) Zi <- ziMain(mtx) Zi/Zi Zi/2
data(mtx) Zi <- ziMain(mtx) Zi/Zi Zi/2
Arithmetic operators for a Zi-class object
Arithmetic operators for a Zi-class object
## S4 method for signature 'Zi,ANY' e1 + e2 ## S4 method for signature 'Zi,ANY' e1 - e2
## S4 method for signature 'Zi,ANY' e1 + e2 ## S4 method for signature 'Zi,ANY' e1 - e2
e1 |
|
e2 |
|
a Zi
-class object after a specific arithmetic
operation is performed
a Zi
-class object after a specific arithmetic
operation is performed
data(mtx) Zi <- ziMain(mtx) Zi+Zi Zi+2 data(mtx) Zi <- ziMain(mtx) Zi+Zi Zi+2
data(mtx) Zi <- ziMain(mtx) Zi+Zi Zi+2 data(mtx) Zi <- ziMain(mtx) Zi+Zi Zi+2
access assays of an
Zi
-class object if the inputdata is an object of the
class SummarizedExperiment
## S4 method for signature 'Zi' assays(x, withDimnames = TRUE, ...)
## S4 method for signature 'Zi' assays(x, withDimnames = TRUE, ...)
x |
|
withDimnames |
A |
... |
see |
list
data(mtx) colData <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) rowData <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) se <- SummarizedExperiment::SummarizedExperiment(assays = list(counts = mtx), colData = colData, rowData = rowData) Zi <- ziMain(se) assays(Zi)
data(mtx) colData <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) rowData <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) se <- SummarizedExperiment::SummarizedExperiment(assays = list(counts = mtx), colData = colData, rowData = rowData) Zi <- ziMain(se) assays(Zi)
Create boxplots of a 'Zi'-class object.
## S3 method for class 'Zi' boxplot(x, ...)
## S3 method for class 'Zi' boxplot(x, ...)
x |
'Zi'-class object |
... |
see boxplot.default |
A List with all information to create a boxplot see boxplot.default
data(mtx) Zi <- ziMain(mtx) boxplot(Zi) boxplot(log1p(Zi))
data(mtx) Zi <- ziMain(mtx) boxplot(Zi) boxplot(log1p(Zi))
access the colData of an
Zi
-class object if the inputdata is an object of the
class SummarizedExperiment
## S4 method for signature 'Zi' colData(x, ...)
## S4 method for signature 'Zi' colData(x, ...)
x |
|
... |
DFrame
data(mtx) colData <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) rowData <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) se <- SummarizedExperiment::SummarizedExperiment(assays = list(counts = mtx), colData = colData, rowData = rowData) Zi <- ziMain(se) colData(Zi)
data(mtx) colData <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) rowData <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) se <- SummarizedExperiment::SummarizedExperiment(assays = list(counts = mtx), colData = colData, rowData = rowData) Zi <- ziMain(se) colData(Zi)
Calculate row and column means of zero-inflated count data taking weights for structural zeros into account.
## S4 method for signature 'Zi' colMeans2(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE) ## S4 method for signature 'Zi' rowMeans2(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)
## S4 method for signature 'Zi' colMeans2(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE) ## S4 method for signature 'Zi' rowMeans2(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)
x |
A |
rows , cols
|
A |
na.rm |
|
useNames |
|
a numeric vector
of row/column length
data(mtx) Zi <- ziMain(mtx) colMeans2(Zi) rowMeans2(Zi)
data(mtx) Zi <- ziMain(mtx) colMeans2(Zi) rowMeans2(Zi)
Calculate the row or column median of zero-deinflated data of a
Zi
-class object. To calculate the median, the
deinflatedcounts matrix will be extracted.
## S4 method for signature 'Zi' colMedians(x, rows = NULL, cols = NULL, na.rm = TRUE, ..., useNames = TRUE) ## S4 method for signature 'Zi' rowMedians(x, rows = NULL, cols = NULL, na.rm = TRUE, ..., useNames = TRUE)
## S4 method for signature 'Zi' colMedians(x, rows = NULL, cols = NULL, na.rm = TRUE, ..., useNames = TRUE) ## S4 method for signature 'Zi' rowMedians(x, rows = NULL, cols = NULL, na.rm = TRUE, ..., useNames = TRUE)
x |
|
rows , cols
|
A |
na.rm |
|
... |
see |
useNames |
|
returns a numeric vector of row/column length
data(mtx) Zi <- ziMain(mtx) colMedians(Zi, useNames = TRUE) rowMedians(Zi, useNames = TRUE)
data(mtx) Zi <- ziMain(mtx) colMedians(Zi, useNames = TRUE) rowMedians(Zi, useNames = TRUE)
calculate the weighted pearson correlation coefficients of a count matrix of an Zi object taking weights for zero counts into account
## S4 method for signature 'Zi,ANY' cor(x, y = NULL, use = "everything", method = "pearson")
## S4 method for signature 'Zi,ANY' cor(x, y = NULL, use = "everything", method = "pearson")
x |
'Zi'-class object |
y |
'Zi'-class object |
use |
'everything' see cor |
method |
default = 'pearson', weighted correlation only implemented for person correlation |
correlation matrix
data(mtx) Zi <- ziMain(mtx) cor(Zi)
data(mtx) Zi <- ziMain(mtx) cor(Zi)
calculate the weighted covariance of the columns of the count matrix of an Zi object taking weights for possible structural zero counts into account
## S4 method for signature 'Zi,ANY' cov(x, y = NULL, use = "everything")
## S4 method for signature 'Zi,ANY' cov(x, y = NULL, use = "everything")
x |
'Zi'-class object |
y |
'Zi'-class object |
use |
'everything' |
covariance matrix
data(mtx) Zi <- ziMain(mtx) cov(Zi)
data(mtx) Zi <- ziMain(mtx) cov(Zi)
access the deinflatedcounts of an Zi
-class
object
deinflatedcounts(x) ## S4 method for signature 'Zi' deinflatedcounts(x) deinflatedcounts(x) <- value ## S4 replacement method for signature 'Zi' deinflatedcounts(x) <- value
deinflatedcounts(x) ## S4 method for signature 'Zi' deinflatedcounts(x) deinflatedcounts(x) <- value ## S4 replacement method for signature 'Zi' deinflatedcounts(x) <- value
x |
|
value |
deinflatedcounts object |
deinflatedcounts
data(mtx) Zi <- ziMain(mtx) deinflatedcounts(Zi)
data(mtx) Zi <- ziMain(mtx) deinflatedcounts(Zi)
draw a heatmap of a given 'Zi'-class object, heatmap.Zi uses the deinflatedcounts matrix (drawn structural zeros) to produce a heatmap. NA values are white
## S3 method for class 'Zi' heatmap(x, ...)
## S3 method for class 'Zi' heatmap(x, ...)
x |
'Zi'-class object |
... |
see heatmap |
heatmap
data(mtx) Zi <- ziMain(mtx) #heatmap(Zi) # Error, clustering not possible heatmap(Zi, Rowv=NA) # no clustering of rows heatmap(Zi, Rowv=NA, Colv=NA) # no clustering of rows and cols
data(mtx) Zi <- ziMain(mtx) #heatmap(Zi) # Error, clustering not possible heatmap(Zi, Rowv=NA) # no clustering of rows heatmap(Zi, Rowv=NA, Colv=NA) # no clustering of rows and cols
access the inputcounts of an Zi
-class object
inputcounts(x) ## S4 method for signature 'Zi' inputcounts(x) inputcounts(x) <- value ## S4 replacement method for signature 'Zi' inputcounts(x) <- value
inputcounts(x) ## S4 method for signature 'Zi' inputcounts(x) inputcounts(x) <- value ## S4 replacement method for signature 'Zi' inputcounts(x) <- value
x |
|
value |
inputcounts object |
inputcounts
data(mtx) Zi <- ziMain(mtx) inputcounts(Zi)
data(mtx) Zi <- ziMain(mtx) inputcounts(Zi)
access the inputdata of an Zi
-class object
inputdata(x) ## S4 method for signature 'Zi' inputdata(x) inputdata(x) <- value ## S4 replacement method for signature 'Zi' inputdata(x) <- value
inputdata(x) ## S4 method for signature 'Zi' inputdata(x) inputdata(x) <- value ## S4 replacement method for signature 'Zi' inputdata(x) <- value
x |
|
value |
inputdata object |
inputdata
data(mtx) Zi <- ziMain(mtx) inputdata(Zi)
data(mtx) Zi <- ziMain(mtx) inputdata(Zi)
Calculate log(1+x) of all 'matrix' objects of a 'Zi'-class object, log calculates by default natural logarithms
## S4 method for signature 'Zi' log1p(x)
## S4 method for signature 'Zi' log1p(x)
x |
|
a Zi
-class object where the log(1+x) values of
inputcounts, deinflatedcounts and weights
are calculated.
data(mtx) Zi <- ziMain(mtx) log1p(Zi)
data(mtx) Zi <- ziMain(mtx) log1p(Zi)
Calculate log2(x+1) of all 'matrix' objects of a 'Zi'-class object
log2p(x)
log2p(x)
x |
|
a Zi
-class object where the log2(1+x) values of
inputcounts, deinflatedcounts and weights
are calculated.
data(mtx) Zi <- ziMain(mtx) log2p(Zi)
data(mtx) Zi <- ziMain(mtx) log2p(Zi)
Calculate the arithmetic mean of zero inflated data taking weights for structural zeros into account
## S3 method for class 'Zi' mean(x, ...)
## S3 method for class 'Zi' mean(x, ...)
x |
A |
... |
mean value
weighted.mean, colMeans2, rowMeans2
data(mtx) Zi <- ziMain(mtx) mean(Zi)
data(mtx) Zi <- ziMain(mtx) mean(Zi)
Caluclate the median of zero-deinflated data of a 'Zi'-class object. To calculate the median, the deinflatedcounts matrix will be extracted
## S3 method for class 'Zi' median(x, na.rm = TRUE, ...)
## S3 method for class 'Zi' median(x, na.rm = TRUE, ...)
x |
|
na.rm |
|
... |
see median.default |
median value
median, colMedians, rowMedians
data(mtx) Zi <- ziMain(mtx) median(Zi)
data(mtx) Zi <- ziMain(mtx) median(Zi)
Missing Value Heatmap
MissingValueHeatmap(ZiObject, title = "", xlab = "", ylab = "")
MissingValueHeatmap(ZiObject, title = "", xlab = "", ylab = "")
ZiObject |
ZiObject, result of the ziMain function |
title |
Title of the plot . |
xlab |
Title of the x axis. |
ylab |
Title of the y axis. |
heatmap
data(mtx)
data(mtx)
access the model of an Zi
-class object
model(x) ## S4 method for signature 'Zi' model(x) model(x) <- value ## S4 replacement method for signature 'Zi' model(x) <- value
model(x) ## S4 method for signature 'Zi' model(x) model(x) <- value ## S4 replacement method for signature 'Zi' model(x) <- value
x |
|
value |
model object |
model
data(mtx) Zi <- ziMain(mtx) model(Zi)
data(mtx) Zi <- ziMain(mtx) model(Zi)
Zero-inflated matrix data
mtx
mtx
A matrix with 100 rows and 10 columns
a data matrix
access the otu_table of an
Zi
-class object if the inputdata slot is a phyloseq
object
## S4 method for signature 'Zi' otu_table(object)
## S4 method for signature 'Zi' otu_table(object)
object |
|
otu_table
data(mtx) OTU <- otu_table(mtx, taxa_are_rows = TRUE) sample_data <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) SAM <- sample_data(sample_data) tax_table <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) TAX <- tax_table(tax_table) ps <- phyloseq::phyloseq(OTU, TAX, SAM) Zi <- ziMain(ps) otu_table(Zi)
data(mtx) OTU <- otu_table(mtx, taxa_are_rows = TRUE) sample_data <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) SAM <- sample_data(sample_data) tax_table <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) TAX <- tax_table(tax_table) ps <- phyloseq::phyloseq(OTU, TAX, SAM) Zi <- ziMain(ps) otu_table(Zi)
plot
## S4 method for signature 'Zi,ANY' plot(x, y, ...)
## S4 method for signature 'Zi,ANY' plot(x, y, ...)
x |
|
y |
the y coordinates of points in the plot, optional if x is an appropriate structure |
... |
Arguments to be passed to plot |
returns plot object
data(mtx) Zi <- ziMain(mtx) plot(Zi)
data(mtx) Zi <- ziMain(mtx) plot(Zi)
Calculate the quantiles of zero-deinflated data of a
Zi
-class object. To calculate the quantiles, the
deinflatedcounts matrix will be extracted.
## S3 method for class 'Zi' quantile(x, probs = seq(0, 1, 0.25), na.rm = TRUE, ...)
## S3 method for class 'Zi' quantile(x, probs = seq(0, 1, 0.25), na.rm = TRUE, ...)
x |
A |
probs |
A numeric |
na.rm |
|
... |
quantile value
quantile, rowQuantiles, colQuantiles
data(mtx) Zi <- ziMain(mtx) quantile(Zi)
data(mtx) Zi <- ziMain(mtx) quantile(Zi)
Zi
-class objectResample the deinflatedcounts matrix of an
Zi
-class object. Resampling is done by drawing from a
binomial distribution with a given probability that a count value (zero and
non-zero) is a structural zero.
resample_deinflatedcounts(x)
resample_deinflatedcounts(x)
x |
|
a Zi
-class object where the
deinflatedcounts
are resampled
data(mtx) Zi <- ziMain(mtx) resample_deinflatedcounts(Zi)
data(mtx) Zi <- ziMain(mtx) resample_deinflatedcounts(Zi)
access the rowData of an
Zi
-class object if the inputdata is an object of the
class SummarizedExperiment
## S4 method for signature 'Zi' rowData(x, useNames = TRUE, ...)
## S4 method for signature 'Zi' rowData(x, useNames = TRUE, ...)
x |
|
useNames |
returns a rowData dataframe with rownames |
... |
DFrame
data(mtx) colData <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) rowData <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) se <- SummarizedExperiment::SummarizedExperiment(assays = list(counts = mtx), colData = colData, rowData = rowData) Zi <- ziMain(se) rowData(Zi)
data(mtx) colData <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) rowData <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) se <- SummarizedExperiment::SummarizedExperiment(assays = list(counts = mtx), colData = colData, rowData = rowData) Zi <- ziMain(se) rowData(Zi)
Calculate the row or column quantiles of zero-deinflated data
of a Zi
-class object. To calculate the quantiles, the
deinflatedcounts matrix will be extracted
## S4 method for signature 'Zi' rowQuantiles( x, rows = NULL, cols = NULL, probs = seq(from = 0, to = 1, by = 0.25), na.rm = TRUE, type = 7L, ..., useNames = TRUE, drop = TRUE ) ## S4 method for signature 'Zi' colQuantiles( x, rows = NULL, cols = NULL, probs = seq(from = 0, to = 1, by = 0.25), na.rm = TRUE, type = 7L, ..., useNames = TRUE, drop = TRUE )
## S4 method for signature 'Zi' rowQuantiles( x, rows = NULL, cols = NULL, probs = seq(from = 0, to = 1, by = 0.25), na.rm = TRUE, type = 7L, ..., useNames = TRUE, drop = TRUE ) ## S4 method for signature 'Zi' colQuantiles( x, rows = NULL, cols = NULL, probs = seq(from = 0, to = 1, by = 0.25), na.rm = TRUE, type = 7L, ..., useNames = TRUE, drop = TRUE )
x |
A |
rows , cols
|
A |
probs |
A numeric |
na.rm |
|
type |
An integer specifying the type of estimator |
... |
Additional arguments passed to specific methods rowQuantiles |
useNames |
|
drop |
a numeric vector
of row/column length
data(mtx) Zi <- ziMain(mtx) rowQuantiles(Zi, useNames = TRUE) colQuantiles(Zi, useNames = TRUE)
data(mtx) Zi <- ziMain(mtx) rowQuantiles(Zi, useNames = TRUE) colQuantiles(Zi, useNames = TRUE)
Calculate row and column standard deviations of zero inflated count data taking weights for structural zeros into account
## S4 method for signature 'Zi' rowSds(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE) ## S4 method for signature 'Zi' colSds(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)
## S4 method for signature 'Zi' rowSds(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE) ## S4 method for signature 'Zi' colSds(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)
x |
A |
rows , cols
|
A |
na.rm |
|
useNames |
|
a vector
of row/column length
data(mtx) Zi <- ziMain(mtx) rowSds(Zi) colSds(Zi)
data(mtx) Zi <- ziMain(mtx) rowSds(Zi) colSds(Zi)
Calculate row and column variances of zero inflated count data taking weights for structural zeros into account.
## S4 method for signature 'Zi' rowVars(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE) ## S4 method for signature 'Zi' colVars(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)
## S4 method for signature 'Zi' rowVars(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE) ## S4 method for signature 'Zi' colVars(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)
x |
A |
rows , cols
|
A |
na.rm |
|
useNames |
|
a vector of row/col length
data(mtx) Zi <- ziMain(mtx) rowVars(Zi) colVars(Zi)
data(mtx) Zi <- ziMain(mtx) rowVars(Zi) colVars(Zi)
Calculate row and column weighted means of zero inflated count data, additionally taking weights for structural zeros into account.
## S4 method for signature 'Zi' rowWeightedMeans( x, w, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE ) ## S4 method for signature 'Zi' colWeightedMeans( x, w, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE )
## S4 method for signature 'Zi' rowWeightedMeans( x, w, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE ) ## S4 method for signature 'Zi' colWeightedMeans( x, w, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE )
x |
A |
w |
a numerical vector of weights either of length = rows or length = cols giving the weights to use for elements of x |
rows , cols
|
A |
na.rm |
|
useNames |
|
a numeric vector of length N(K)
data(mtx) Zi <- ziMain(mtx) rowWeightedMeans(Zi, w = runif(ncol(inputcounts(Zi)), 0.1,1)) colWeightedMeans(Zi, w = runif(nrow(inputcounts(Zi)), 0.1,1))
data(mtx) Zi <- ziMain(mtx) rowWeightedMeans(Zi, w = runif(ncol(inputcounts(Zi)), 0.1,1)) colWeightedMeans(Zi, w = runif(nrow(inputcounts(Zi)), 0.1,1))
Calculate row and column standard deviations or variances of zero inflated count data, additionally taking weights for structural zeros into account.
## S4 method for signature 'Zi' rowWeightedSds(x, w, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE) ## S4 method for signature 'Zi' colWeightedSds(x, w, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE) ## S4 method for signature 'Zi' rowWeightedVars(x, w, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE) ## S4 method for signature 'Zi' colWeightedVars(x, w, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)
## S4 method for signature 'Zi' rowWeightedSds(x, w, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE) ## S4 method for signature 'Zi' colWeightedSds(x, w, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE) ## S4 method for signature 'Zi' rowWeightedVars(x, w, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE) ## S4 method for signature 'Zi' colWeightedVars(x, w, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)
x |
A |
w |
a numerical vector of weights either of length = rows or length = cols giving the weights to use for elements of x |
rows , cols
|
A |
na.rm |
|
useNames |
|
a numeric vector of length N(K)
data(mtx) Zi <- ziMain(mtx) rowWeightedSds(Zi, w = runif(ncol(inputcounts(Zi)), 0.1,1)) colWeightedSds(Zi, w = runif(nrow(inputcounts(Zi)), 0.1,1)) rowWeightedVars(Zi, w = runif(ncol(inputcounts(Zi)), 0.1,1)) colWeightedVars(Zi, w = runif(nrow(inputcounts(Zi)), 0.1,1))
data(mtx) Zi <- ziMain(mtx) rowWeightedSds(Zi, w = runif(ncol(inputcounts(Zi)), 0.1,1)) colWeightedSds(Zi, w = runif(nrow(inputcounts(Zi)), 0.1,1)) rowWeightedVars(Zi, w = runif(ncol(inputcounts(Zi)), 0.1,1)) colWeightedVars(Zi, w = runif(nrow(inputcounts(Zi)), 0.1,1))
access the sample_data of an
Zi
-class object if the inputdata slot is a phyloseq
object
## S4 method for signature 'Zi' sample_data(object)
## S4 method for signature 'Zi' sample_data(object)
object |
|
sample_data
data(mtx) OTU <- otu_table(mtx, taxa_are_rows = TRUE) sample_data <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) SAM <- sample_data(sample_data) tax_table <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) TAX <- tax_table(tax_table) ps <- phyloseq::phyloseq(OTU, TAX, SAM) Zi <- ziMain(ps) sample_data(Zi)
data(mtx) OTU <- otu_table(mtx, taxa_are_rows = TRUE) sample_data <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) SAM <- sample_data(sample_data) tax_table <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) TAX <- tax_table(tax_table) ps <- phyloseq::phyloseq(OTU, TAX, SAM) Zi <- ziMain(ps) sample_data(Zi)
Calculate the standard deviation of zero inflated count data taking weights for structural zeros into account.
## S4 method for signature 'Zi' sd(x, na.rm = FALSE)
## S4 method for signature 'Zi' sd(x, na.rm = FALSE)
x |
A |
na.rm |
|
standard deviation value
data(mtx) Zi <- ziMain(mtx) sd(Zi)
data(mtx) Zi <- ziMain(mtx) sd(Zi)
Message printed at command line
## S4 method for signature 'Zi' show(object)
## S4 method for signature 'Zi' show(object)
object |
|
returns a numeric vector of row/column length
data(mtx) Zi <- ziMain(mtx) Zi show(Zi)
data(mtx) Zi <- ziMain(mtx) Zi show(Zi)
Zi
-class object based on feature dataSubset a Zi
-class object based on tax_table
of a phyloseq
object or on rowData of a SummarizedExperiment object
subset_feature(Zi, ...)
subset_feature(Zi, ...)
Zi |
|
... |
The subsetting expression that should be applied, see subset for more details |
a Zi
-class object after subsetting is done
data(mtx) OTU <- otu_table(mtx, taxa_are_rows = TRUE) sample_data <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) SAM <- sample_data(sample_data) tax_table <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) TAX <- tax_table(tax_table) ps <- phyloseq::phyloseq(OTU, TAX, SAM) Zi <- ziMain(ps) subset_Zi_phylo <- subset_feature(Zi, ta2 == 'Bacteroidetes')
data(mtx) OTU <- otu_table(mtx, taxa_are_rows = TRUE) sample_data <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) SAM <- sample_data(sample_data) tax_table <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) TAX <- tax_table(tax_table) ps <- phyloseq::phyloseq(OTU, TAX, SAM) Zi <- ziMain(ps) subset_Zi_phylo <- subset_feature(Zi, ta2 == 'Bacteroidetes')
Zi
-class object based on sample dataSubset a Zi
-class object based on
sample_data of an phyloseq object or on colData based on a
SummarizedExperiment object
subset_sample(Zi, ...)
subset_sample(Zi, ...)
Zi |
|
... |
The subsetting expression that should be applied, see subset for more details |
a Zi
-class object after subsetting is done
data(mtx) OTU <- otu_table(mtx, taxa_are_rows = TRUE) sample_data <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) SAM <- sample_data(sample_data) tax_table <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) TAX <- tax_table(tax_table) ps <- phyloseq::phyloseq(OTU, TAX, SAM) Zi <- ziMain(ps) subset_Zi <- subset_sample(Zi, SampleID %in% c('Sample1','Sample2'))
data(mtx) OTU <- otu_table(mtx, taxa_are_rows = TRUE) sample_data <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) SAM <- sample_data(sample_data) tax_table <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) TAX <- tax_table(tax_table) ps <- phyloseq::phyloseq(OTU, TAX, SAM) Zi <- ziMain(ps) subset_Zi <- subset_sample(Zi, SampleID %in% c('Sample1','Sample2'))
Zi
-class objecttranspose all matrizes of a Zi
-class object
## S4 method for signature 'Zi' t(x)
## S4 method for signature 'Zi' t(x)
x |
|
Zi
-class object
data(mtx) Zi <- ziMain(mtx) t(Zi)
data(mtx) Zi <- ziMain(mtx) t(Zi)
access the taxonomy table (tax_table) of an
Zi
-class object if the inputdata slot is a phyloseq
object
## S4 method for signature 'Zi' tax_table(object)
## S4 method for signature 'Zi' tax_table(object)
object |
|
tax_table
data(mtx) OTU <- otu_table(mtx, taxa_are_rows = TRUE) sample_data <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) SAM <- sample_data(sample_data) tax_table <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) TAX <- tax_table(tax_table) ps <- phyloseq::phyloseq(OTU, TAX, SAM) Zi <- ziMain(ps) tax_table(Zi)
data(mtx) OTU <- otu_table(mtx, taxa_are_rows = TRUE) sample_data <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) SAM <- sample_data(sample_data) tax_table <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) TAX <- tax_table(tax_table) ps <- phyloseq::phyloseq(OTU, TAX, SAM) Zi <- ziMain(ps) tax_table(Zi)
Calculate the variance of zero inflated count data taking weights for structural zeros into account.
## S4 method for signature 'Zi,ANY' var(x, na.rm = FALSE)
## S4 method for signature 'Zi,ANY' var(x, na.rm = FALSE)
x |
A |
na.rm |
|
variance value
data(mtx) Zi <- ziMain(mtx) var(Zi)
data(mtx) Zi <- ziMain(mtx) var(Zi)
Calculate a weighted mean of zero inflated count data, additionally taking weights for structural zeros into account
## S4 method for signature 'Zi' weighted.mean(x, w, ...)
## S4 method for signature 'Zi' weighted.mean(x, w, ...)
x |
A |
w |
a numerical |
... |
weighted mean value
weighted.mean, rowWeightedMeans, colWeightedMeans
data(mtx) Zi <- ziMain(mtx) weight <- runif(length(inputcounts(Zi)), 0.1, 1) weighted.mean(Zi, w= weight)
data(mtx) Zi <- ziMain(mtx) weight <- runif(length(inputcounts(Zi)), 0.1, 1) weighted.mean(Zi, w= weight)
Calculate a weighted variance and standard deviation of zero inflated count data, additionally taking weights for structural zeros into account
weightedSd(x, w = NULL, idxs = NULL, na.rm = FALSE, center = NULL, ...) weightedVar(x, w = NULL, idxs = NULL, na.rm = FALSE, center = NULL, ...)
weightedSd(x, w = NULL, idxs = NULL, na.rm = FALSE, center = NULL, ...) weightedVar(x, w = NULL, idxs = NULL, na.rm = FALSE, center = NULL, ...)
x |
A |
w |
a numerical |
idxs |
A |
na.rm |
|
center |
|
... |
a numeric
scalar
weightedVar, rowWeightedVars, colWeightedVars
data(mtx) Zi <- ziMain(mtx) weight <- runif(length(inputcounts(Zi)), 0.1, 1) weightedVar(Zi, w= weight) weightedSd(Zi, w = weight)
data(mtx) Zi <- ziMain(mtx) weight <- runif(length(inputcounts(Zi)), 0.1, 1) weightedVar(Zi, w= weight) weightedSd(Zi, w = weight)
access the weights of an Zi
-class object
weights(x) ## S4 method for signature 'Zi' weights(x) weights(x) <- value ## S4 replacement method for signature 'Zi' weights(x) <- value
weights(x) ## S4 method for signature 'Zi' weights(x) weights(x) <- value ## S4 replacement method for signature 'Zi' weights(x) <- value
x |
|
value |
weights object |
weights
data(mtx) Zi <- ziMain(mtx) weights(Zi)
data(mtx) Zi <- ziMain(mtx) weights(Zi)
Objects of this class store all the results of the ZiMain function to continue zero inflated data analysis
Zi
-class object
inputdata
a matrix, phyloseq or SummarizedExperiment object.
inputcounts
matrix. The count matrix, features as rows, samples as columns
model
list. The result of fitting a zero inflated model using zeroinfl
deinflatedcounts
matrix. The matrix where predicted structural zeros are omitted and stored as NA values
weights
matrix. A matrix containing weights for zero counts
Zi
-class object to a DESeq2 dds objectA Zi
-class object is converted to a
DESeqDataSet object, which can be used for DESeq2 analysis. Both, weight and
count matrices will be stored in assays of the DESeqDataSet.
zi2deseq2(ZiObject, design, colData, ...)
zi2deseq2(ZiObject, design, colData, ...)
ZiObject |
|
design |
A formula which specifies the design of the experiment, taking the form formula(~ x + y + z). That is, a formula with right-hand side only. By default, the functions in this package and DESeq2 will use the last variable in the formula (e.g. z) for presenting results (fold changes, etc.) and plotting. When considering your specification of experimental design, you will want to re-order the levels so that the NULL set is first. |
colData |
if the inputdata of the |
... |
phyloseq::phyloseq_to_deseq2 if the inputdata of the 'Zi'-object is a phyloseq object DESeq2::DESeqDataSet if the inputdata the ' Zi'-object is a SummarizedExperiment object |
a dds
class object
data(mtx) Zi <- ziMain(mtx) colData <- data.frame(group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) zi2deseq2(Zi, ~group, colData)
data(mtx) Zi <- ziMain(mtx) colData <- data.frame(group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) zi2deseq2(Zi, ~group, colData)
Replace the OTU table of a phyloseq object with the OTU table of zero de-inflated count data
zi2phyloseq(ZiObject)
zi2phyloseq(ZiObject)
ZiObject |
|
a 'phyloseq'-class object
data(mtx) OTU <- otu_table(mtx, taxa_are_rows = TRUE) sample_data <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) SAM <- sample_data(sample_data) tax_table <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) TAX <- tax_table(tax_table) ps <- phyloseq::phyloseq(OTU, TAX, SAM) Zi <- ziMain(ps) new_ps <- zi2phyloseq(Zi) new_ps
data(mtx) OTU <- otu_table(mtx, taxa_are_rows = TRUE) sample_data <- data.frame(SampleID = c('Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6', 'Sample7', 'Sample8', 'Sample9', 'Sample10'), Group = factor(x = c(1,1,1,1,1,2,2,2,2,2))) SAM <- sample_data(sample_data) tax_table <- data.frame(Kingdom = c(rep('Bacteria', times = 100)), Phylum = c(rep('Bacteroidetes', times = 50), rep('Firmicutes', times = 50))) TAX <- tax_table(tax_table) ps <- phyloseq::phyloseq(OTU, TAX, SAM) Zi <- ziMain(ps) new_ps <- zi2phyloseq(Zi) new_ps
This function fits a zero-inflated mixture model (either Poisson or negative binomial distribution) to count data and calculates weights for all zeros indicating whether a zero is a real count (weight close to 1) or whether it is a structural zero (weight close to 0). The default model is a zero inflated negative binomial model.
The input inputdata of the ziMain function is either a phyloseq object, SummarizedExperiment object or count matrix.
In order to reduce calculation times, the count matrix is divided into blocks of around 5000 count values. Then, a zero inflation model (either Poisson or negative binomial distribution) is fitted to the data. The response variable count is estimated using the predictor variables sample(columns) and feature(rows). Using the fitted zero inflated model, probabilities given that a zero in the count matrix is a structural zero are predicted. Those probabilities are used in two ways: 1) A zero-deinflated count matrix is generated where a appropriate proportion of zeros are randomly replaced by NA. This count matrix can be used for analysis methods which cannot deal with weights. 2) Weights
(see Van den Berge, K., Perraudeau, F., Soneson, C. et al.) are calculated in order to down-weight structrual zeros in analyses which can account for weighting of individual data points.
all zero counts are calculated given the following formula:
The result of the ziMain function can be used to analyze zero inflated count data.
ziMain( inputdata, feature = "feature", formula = count ~ sample + feature, dist = "negbin", link = "logit", zeroRows.rm = FALSE, ... )
ziMain( inputdata, feature = "feature", formula = count ~ sample + feature, dist = "negbin", link = "logit", zeroRows.rm = FALSE, ... )
inputdata |
phyloseq object, SummarizedExperiment object, or matrix (rows =features, columns=samples) |
feature |
'feature', 'gene', 'OTU', 'phylum', etc. By default, rownames are labelled as feature1, feature2, ... |
formula |
formula to fit the zero inflated model y ~ x1 + x2 + ..., default = count ~ sample + feature. A different set of regressors can be specified using y ~ x1 +x2 + ...|z1 + z2
|
dist |
= distribution, either poisson ('poisson'), negative binomial ('negbin') |
link |
= link function, either 'logit', 'probit', 'cloglog', 'cauchit' |
zeroRows.rm |
= logical, indicating whether rows that only contain zeros
should be removed ( |
... |
additional parameters to describe the model, see
|
Zi
-class object
inputdata
a matrix, phyloseq or SummarizedExperiment object.
inputcounts
matrix. The count matrix, features as rows, samples as columns
model
list. The result of fitting a zero inflated model using
zeroinfl
deinflatedcounts
matrix. A matrix where zero counts are randomly replaced according to the estimated probability of being a structural zero
weights
matrix. A matrix containing weights for zero counts
Van den Berge, K., Perraudeau, F., Soneson, C. et al. Observation weights unlock bulk RNA-seq tools for zero inflation and single-cell applications. Genome Biol 19, 24 (2018). https://doi.org/10.1186/s13059-018-1406-4
# zero-inflated count matrix data(mtx) # calling ziMain function: Zi <- ziMain(mtx) #Example Data Sets from other R packages #data(enterotype) #data(GlobalPatterns) #data(esophagus) #ziMain(esophagus) #data(soilrep)
# zero-inflated count matrix data(mtx) # calling ziMain function: Zi <- ziMain(mtx) #Example Data Sets from other R packages #data(enterotype) #data(GlobalPatterns) #data(esophagus) #ziMain(esophagus) #data(soilrep)