is_matrix verifies that mx is a valid 2x2 matrix (i.e., a numeric contingency table).

is_matrix(mx)

Arguments

mx

An object to verify (required).

Value

A Boolean value: TRUE if mx

is a numeric matrix and 2x2 contingency table; otherwise FALSE.

Details

is_matrix is more restrictive than is.matrix, as it also requires that mx is.numeric, is.table, nrows(mx) == 2, and ncols(mx) == 2.

References

Neth, H., Gradwohl, N., Streeb, D., Keim, D.A., & Gaissmaier, W. (2021). Perspectives on the 2×2 matrix: Solving semantically distinct problems based on a shared structure of binary contingencies. Frontiers in Psychology, 11, 567817. doi: doi: 10.3389/fpsyg.2020.567817

Examples

is_matrix(1:4)
#> is_matrix: mx is no matrix.
#> [1] FALSE
is_matrix(matrix("A"))
#> is_matrix: mx is no contingency table.
#> [1] FALSE
is_matrix(matrix(1:4))
#> is_matrix: mx is no contingency table.
#> [1] FALSE
is_matrix(as.table(matrix(1:4, nrow = 1, ncol = 4)))
#> is_matrix: mx does not have 2 rows.
#> [1] FALSE
is_matrix(as.table(matrix(1:4, nrow = 4, ncol = 1)))
#> is_matrix: mx does not have 2 rows.
#> [1] FALSE
is_matrix(as.table(matrix(1:4, nrow = 2, ncol = 2)))
#> [1] TRUE