Generate two type of covariance matrix

cov.mat(sdvec,rho, type='toeplitz')

Arguments

sdvec

a positive vector, standard deviation of each random variable.

rho

a value between 0 and 1, a baseline vlaue of correlation coefficient.

type

a character, specify the type of correlation matrix and only include 'toeplitz' and 'identity' in current version.

Details

The argument rho specify the size of correlation coeffient. As for argument type, if type='toeplitz', sigma_ij=rho^|i-j|; if type ='identity', sigma_ij=rho when i!=j and sigma_ij=1 when i=j.

Value

return a covariance matrix with a type of specified structure.

References

nothing.

Author

Liu Wei

Note

nothing

See also

cov2cor

Examples

cov.mat(rep(5,5), 0.5)
#> [,1] [,2] [,3] [,4] [,5] #> [1,] 25.0000 12.500 6.25 3.125 1.5625 #> [2,] 12.5000 25.000 12.50 6.250 3.1250 #> [3,] 6.2500 12.500 25.00 12.500 6.2500 #> [4,] 3.1250 6.250 12.50 25.000 12.5000 #> [5,] 1.5625 3.125 6.25 12.500 25.0000
cov.mat(c(2,4,3), 0.5, type='identity')
#> [,1] [,2] [,3] #> [1,] 4 4 3 #> [2,] 4 16 6 #> [3,] 3 6 9