cofVar: Calculating the coefficient of variation for expression...

View source: R/cofVar.R

cofVarR Documentation

Calculating the coefficient of variation for expression matrix.


This function calculates the mean and the coefficient of variation to each row (genes or probesets) in an expression matrix in two ways: i) in the whole matrix ii) for the specific phenotype (case or control).


cofVar(expData, complete = TRUE, treatment = NULL, type = NULL)



The whole normalized expression matrix, rows: genes or probeset, columns: samples, it may be stored in a SummarizedExperiment object.


Boolean to define if the function uses the whole expression matrix, by default TRUE.


A numeric vector with 0s and 1s for each sample in the expression matrix, the 0 expresses the control samples and 1 expresses the case samples, by default is NULL.


It can be "case" to calculate the mean and the coefficient of variation for the case samples or, otherwise, "control" to obtain these two values for the control samples.


The expression matrix with two new columns, the first one with the averages and the other one with the coefficient of variation values.


Juan David Henao <>


## Creating the expression matrix

# The matrix have 200 genes and 20 samples

n <- 200
m <- 20

# The vector with treatment and control samples

treat <- c(rep(0,10),rep(1,10))

# Calculating the expression values normalized

mat <- as.matrix(rexp(n, rate = 1))
norm <- t(apply(mat, 1, function(nm) rnorm(m, mean=nm, sd=1)))

## Calculating the mean and the coefficient of variation

# For the whole expression matrix

complete <- cofVar(norm)

# For the case samples

case <- cofVar(expData = norm,complete = FALSE,treatment = treat,type = "case")

jdhenaos/coexnet documentation built on April 22, 2022, 12:43 a.m.