Description Usage Arguments Details Value Author(s) See Also Examples
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.
1 | corr_vec2mat(vec)
|
vec |
A Vector with known correlation coefficients. |
@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.
A constructed correlation matrix.
Vilmantas Gegzna
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()
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.