Learn R Programming

topolow (version 1.0.0)

increase_na_percentage: 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)

Value

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

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

Examples

Run this code
# 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)

Run the code above in your browser using DataLab