increase_na_percentage {topolow}R Documentation

Increase Missing Values in a Matrix

Description

Strategically introduces NA values into a distance matrix while maintaining symmetry. New NA values are added preferentially farther from the diagonal to simulate real-world measurement patterns where distant pairs are more likely to be unmeasured.

Usage

increase_na_percentage(mat, target_na_percentage)

Arguments

mat

Matrix to modify

target_na_percentage

Numeric between 0 and 1 specifying desired proportion of NAs

Details

The function:

  1. Calculates needed additional NAs to reach target percentage

  2. Creates probability matrix favoring off-diagonal elements

  3. Randomly selects positions weighted by distance from diagonal

  4. Maintains matrix symmetry by mirroring NAs

Value

A matrix with an increased number of NA values, maintaining symmetry.

Examples

# Create sample distance matrix
dist_mat <- matrix(runif(100), 10, 10)
dist_mat[lower.tri(dist_mat)] <- t(dist_mat)[lower.tri(dist_mat)]
diag(dist_mat) <- 0

# Increase NAs to 70%
sparse_mat <- increase_na_percentage(dist_mat, 0.7)

[Package topolow version 1.0.0 Index]