corr_vec2mat: [+] Construct a correlation matrix from a coefficients'...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/corr_vec2mat.R

Description

Construct a correlation matrix from a vector vector of coefficients, that will be placed in the lower triangle of a matrix (as illustrated in example Example 1B) and then mirrored symetrically to the upper triangle.

Usage

1

Arguments

vec

A Vector with known correlation coefficients.

Details

@details The number of elements in the vector should be equal to the number of elements in lower triangle of a n*n matrix. If there's insufficient number of elements in vector, hen only first m melements will be used to construct(n-1)*(n-1) matrix.

Value

A constructed correlation matrix.

Author(s)

Vilmantas Gegzna

See Also

Other matrix operations in spMisc: indMatrix(), nTri2nDiag(), revalueMatrix(), sort_matrix_elements, which.in(), which.max.all(), which.max.perRow()

Other simmulation functions in spMisc: simCorrVars()

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
# ------------------------------------------------------------
# Example 1A: Vector into a matrix

vector = c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6)
corr_vec2mat(vector)

# ------------------------------------------------------------


## Not run: 

 # Example 1B: Vector is transformed to a matrix by filling
 # it column-wise:

  ## vector = c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6)
  ##
  ##  matrix =
  ##       [,1] [,2] [,3] [,4]
  ##  [1,]   .     .   .    .
  ##  [2,]  0.1    .   .    .
  ##  [3,]  0.2  0.4   .    .
  ##  [4,]  0.3  0.5  0.6   .
  ##
  ## In this example only the matrix elements of interest are shown.

 # -----------------------------------------------------------------
 # Example 2: inappropriate number of coefficients - warning appears

 corr_vec2mat(vector[1:5])
  ## Warning message:
  ## Only first 3 coefficient(s) out of 5 will be used to construct symmetric matrix with 3 rows.

 # ------------------------------------------------------------
 # Example 3: ERROR appears - values of coeffs must be between [-1;1]

 corr_vec2mat(1:5)
  ## Error in corr_vec2mat(1:5) :
  ## All values in input vector must be between [-1 and 1]

## End(Not run)

GegznaV/spMisc documentation built on April 26, 2020, 5:59 p.m.