AddOutlier: Add outlier to matrix

Description Usage Arguments Value Note Examples

View source: R/simulation.R

Description

AddOutlier returns a matrix with outliers randomly added to a matrix given certain proportion of contamination

Usage

1
AddOutlier(X, proportion, value, seed = NULL, method = "element")

Arguments

X

matrix, to which outliers are added

proportion

numeric, proportion of elements, rows or columns to be contaminated. Must be between 0 and 1.

value

numeric, the outlying value to be used for contamination

seed

numeric, a seed to reproduce the randomization behaviour

method

character, must be one of the following:

  • "element" - For contaminating at random positions of the matrix

  • "row" - For contaminating an entire row of the matrix

  • "col" - For contaminating an entire column of the matrix

Value

A matrix with elements / rows / columns contaminated.

Note

Due to randomization, it is possible that the none of the entries of the matrix become contaminated. In that case, it is recommended to use different seed value.

Examples

1
2
X = matrix(1:20, nrow = 4, ncol = 5)
AddOutlier(X, 0.5, 10, seed = 1234)

rsvddpd documentation built on Oct. 27, 2021, 5:07 p.m.