bend: Matrix bending to positive-definite

Description Usage Arguments Value Examples

View source: R/bend.R

Description

Bending a symmetric non-positive-definite matrix to positive-definite, using weighted or unweighted methods.

Usage

1
2
3
4
5
6
7
8
bend(
  inmat,
  wtmat,
  reciprocal = FALSE,
  max.iter = 10000,
  small.positive = 1e-04,
  method = "hj"
)

Arguments

inmat

: The matrix to be bent.

wtmat

: The weight matrix for weighted bending. If no input is provided, the unweighted method (default) is used.

reciprocal

: If TRUE, reciprocal of the weighting factors are used. If no input is provided, default = FALSE.

max.iter

: Maximum number of iterations. If no input is provided, default = 10000.

small.positive

: Eigenvalues smaller than this value are replaced with this value. If no input is provided, default = 0.0001.

method

: "hj" (Jorjani et al., 2003) or "lrs" (Schaeffer, 2014), default = "hj"

Value

bent : The bent matrix.

init.ev : Eigenvalues of the initial (inmat) matrix.

final.ev : Eigenvalues of the bent matrix.

min.dev : min(bent - inmat).

max.dev : max(bent - inmat).

loc.min.dev : Location (indices) of min.dev element.

loc.max.dev : Location (indices) of max.dev element.

ave.dev : Average deviation (bent - inmat) of the upper triangle elements (excluding diagonal elements for correlation matrices).

AAD : Average absolute deviation of the upper triangle elements (excluding diagonal elements for correlation matrices) of bent and inmat.

Cor : Correlation between the upper triangle elements (excluding diagonal elements for correlation matrices) of bent and inmat.

RMSD : Root of mean squared deviation of the upper triangle elements (excluding diagonal elements for correlation matrices) of bent and inmat.

w_gt_0 : Number of weight elements greater than 0, in the upper triangle of wtmat (for weighted bending).

wAAD : Weighted AAD (for weighted bending).

wCor : Weighted Cor (for weighted bending).

wRMSD : Weighted RMSD (for weighted bending).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Test data
V = matrix(nrow=5, ncol=5, c( # matrix to be bent
100,  95,  80,  40,  40,
 95, 100,  95,  80,  40,
 80,  95, 100,  95,  80,
 40,  80,  95, 100,  95,
 40,  40,  80,  95, 100))
W = matrix(nrow=5, ncol=5, c( # matrix of weights
1000,  500,   20,   50,  200,
 500, 1000,  500,    5,   50,
  20,  500, 1000,   20,   20,
  50,    5,   20, 1000,  200,
 200,   50,   20,  200, 1000))

# Example 1: Unweighted bending
bend(V)
## The default method (Jojani et al. 2003) is used.

# Example 2: Weighted bending using reciprocal of the weighting factors
bend(inmat=V, wtmat=W, reciprocal=TRUE)

# Example 3: Bending with fixed elements
## Assume we want to keep V[1:2, 1:2] constant.
W2 = W; W2[1:2, 1:2] = 0
bend(inmat=V, wtmat=W2, reciprocal=TRUE)

# Example 4: Bending a correlation matrix
V2 = cov2cor(V)
bend(V2, W, reciprocal=TRUE)

# Example 5: Bending using the method of Schaeffer (2014)
bend(inmat=V, method="lrs")

# Example 6: Bending a correlation matrix using the method of Schaeffer (2014)
bend(V2, method="lrs")

# Example 7: Bending the same correlation matrix using a weighted development of Schaeffer (2014)
bend(V2, W, reciprocal=TRUE, method="lrs")

# Example 8: Bending a covariance matrix using a weighted development of Schaeffer (2014)
bend(V, W, reciprocal=TRUE, method="lrs")

mbend documentation built on Oct. 23, 2020, 7:16 p.m.