outlier.matrix: identify outlier sample indexes in a matrix

View source: R/outlier.matrix.R

outlier.matrixR Documentation

identify outlier sample indexes in a matrix

Description

Given a matrix of data this function returns a matrix of 0|1, of the same structure with 1 values indicating outliers. It is an expansion of the function id.outliers(), applied to columns of a matrix.

Usage

outlier.matrix(data, nsd = 5, meansd = FALSE)

Arguments

data

a matrix of numerical values, samples in row, features in columns

nsd

the unit distance in SD or IQR from the mean or median estimate, respectively outliers are identified at. Default value is 5.

meansd

set to TRUE if you would like to estimate outliers using a mean and SD method; set to FALSE if you would like to estimate medians and inter quartile ranges. The default is FALSE.

Value

a matrix of 0 (not a sample outlier) and 1 (outlier)

Examples

ex_data = sapply(1:25, function(x){ rnorm(250, 40, 5) })
## define the data set
rownames(ex_data) = paste0("ind", 1:nrow(ex_data))
colnames(ex_data) = paste0("var", 1:ncol(ex_data))
## add in some technical error to two samples
m = apply(ex_data, 2, function(x){ mean(x, na.rm = TRUE) })
ex_data[c(1,50), ] = ex_data[1, ] + (m*4) 
Omat = outlier.matrix(ex_data)
## how many outliers identified
sum(Omat)


MRCIEU/metaboprep documentation built on Jan. 28, 2023, 7:29 p.m.