Skip to contents

This function removes zeros from a simplex (a matrix or vector where each row sums to one and all elements are between 0 and 1) using a specified method.

Usage

remove_zeros(simplex, method = "rescaling", padding = 0.01)

Arguments

simplex

A numeric matrix, data frame, or vector representing the simplex. Each row should sum to one and all elements should be between 0 and 1.

method

A character string specifying the method to remove zeros. Currently, only "rescaling" is supported. Default is "rescaling".

padding

A numeric value to add to each element of the simplex when using the "rescaling" method. Default is 0.01.

Value

A numeric matrix with the same dimensions as the input simplex, with zeros removed according to the specified method.

Details

The rescaling methods adds a small value (padding) to each element of the simplex and then rescales the rows so that they still sum to one:

Examples

# Example usage:
simplex <- matrix(c(0.2, 0.3, 0.5, 0, 0.5, 0.5), nrow = 2, byrow = TRUE)
remove_zeros(simplex)
#>             [,1]      [,2]      [,3]
#> [1,] 0.203883495 0.3009709 0.4951456
#> [2,] 0.009708738 0.4951456 0.4951456