Calculates Dice similarity coefficients between corresponding rows or columns of two matrices, treating all non-zero values as 1 (soft binary overlap).

dice_overlap_soft_matrix(A, B, margin = 1)

Arguments

A

Numeric matrix.

B

Numeric matrix of the same dimensions as `A`.

margin

Integer: 1 for row-wise comparison, 2 for column-wise comparison.

Value

A numeric vector of Dice coefficients (length = nrow(A) or ncol(A)).

Examples

mat1 <- matrix(c(0,1,0,2, 1,0,0,0), nrow=2, byrow=TRUE)
mat2 <- matrix(c(1,1,0,0, 0,0,1,0), nrow=2, byrow=TRUE)
dice_overlap_soft_matrix(mat1, mat2, margin = 1)
#> [1] 0.5 1.0
dice_overlap_soft_matrix(t(mat1), t(mat2), margin = 2)
#> [1] 0.5 1.0