Learn R Programming

popkin (version 1.2.2)

validate_kinship: Validate a kinship matrix

Description

Tests that the input is a valid kinship matrix (a numeric square R matrix). Throws errors if the input is not as above.

Usage

validate_kinship(kinship)

Arguments

kinship

The kinship matrix to validate.

Value

Nothing

Details

True kinship matrices have values strictly between 0 and 1, and diagonal values strictly between 0.5 and 1. However, estimated matrices may contain values slightly out of range. For greater flexibility, this function does not check for out-of-range values.

Examples

Run this code
# NOT RUN {
# this is a valid (positive) example
kinship <- matrix(c(0.5, 0, 0, 0.6), nrow=2)
# this will run without errors or warnings
validate_kinship(kinship)

# negative examples

# dies if input is missing
try( validate_kinship() )

# and if input is not a matrix
try( validate_kinship( 1:5 ) )

# and for non-numeric matrices
char_mat <- matrix(c('a', 'b', 'c', 'd'), nrow=2)
try( validate_kinship( char_mat ) )

# and non-square matrices
non_kinship <- matrix(1:2, nrow=2)
try( validate_kinship( non_kinship ) )

# }

Run the code above in your browser using DataLab