This function generate the pairwise difference matrix(D matrix in the paper). By default it returns a sparse matrix(matrix.csr) from the package SparseM.

RSAVS_Generate_D_Matrix(n, dense = FALSE, w_vec = 1)

Arguments

n

number of observations.

dense

logical, whether the return type should be in dense matrix or not

w_vec

a scalar value of a length \(n * (n - 1) / 2\) vector representing the weights for left part in each pair(e.g. \(\mu_i\) in \(\mu_i - \mu_j\)). If w_vec is a scalar, it will be recycled for every pair. Defaults to 1.

Value

a difference matrix with size \((n * (n - 1) / 2) \times n\)

Details

In Original RSAVS via ADMM algorithm. This functions generates the pairwise difference matrix with w_vec = 1.

In RSI, the original objective function is converted to a sparse median regression via LLA. The pairwise difference matrix is coupled with weights extracted from the penalty functions. This is supplied into this function through w_vec.

Examples

RSAVS:::RSAVS_Generate_D_Matrix(5)
#> Sparse matrix of class "matrix.csr" {use 'str(.)' to see the inner structure}:
#>       [,1] [,2] [,3] [,4] [,5]
#>  [1,]    1   -1    .    .    .
#>  [2,]    1    .   -1    .    .
#>  [3,]    1    .    .   -1    .
#>  [4,]    1    .    .    .   -1
#>  [5,]    .    1   -1    .    .
#>  [6,]    .    1    .   -1    .
#>  [7,]    .    1    .    .   -1
#>  [8,]    .    .    1   -1    .
#>  [9,]    .    .    1    .   -1
#> [10,]    .    .    .    1   -1
RSAVS:::RSAVS_Generate_D_Matrix(4, dense = TRUE)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1   -1    0    0
#> [2,]    1    0   -1    0
#> [3,]    1    0    0   -1
#> [4,]    0    1   -1    0
#> [5,]    0    1    0   -1
#> [6,]    0    0    1   -1
RSAVS:::RSAVS_Generate_D_Matrix(3, w_vec = 2)
#> Sparse matrix of class "matrix.csr" {use 'str(.)' to see the inner structure}:
#>      [,1] [,2] [,3]
#> [1,]    2   -2    .
#> [2,]    2    .   -2
#> [3,]    .    2   -2
RSAVS:::RSAVS_Generate_D_Matrix(4, dense = TRUE, w_vec = c(1, -2, 3, -4, 5, -6))
#>      [,1] [,2] [,3] [,4]
#> [1,]    1   -1    0    0
#> [2,]   -2    0    2    0
#> [3,]    3    0    0   -3
#> [4,]    0   -4    4    0
#> [5,]    0    5    0   -5
#> [6,]    0    0   -6    6