ran_mat: Random generator of matrices with given eigenvalues.

ran_matR Documentation

Random generator of matrices with given eigenvalues.

Description

Random generator of matrices with given eigenvalues.

Usage

ran_mat(p, ev = stats::runif(p, 0, 10), seed = NULL)

Arguments

p

A positive integer >= 2, the dimension.

ev

A vector of length p, the eigenvalues of the output matrix.

seed

A number, the seed for the generator. Ignored if NULL.

Details

The function randomly fills a p by p matrix with independent Normal(0,1) entries, takes the Q matrix from its QR decomposition, and returns Q' diag(ev) Q.

Value

A p by p matrix whose eigenvalues equal to ev.

Examples

p <- 30
eigen_values <- (0.1*p-1+1:p)/p
K <- ran_mat(p, ev=eigen_values, seed=1)
sort(eigen(K)$val)-eigen_values

genscore documentation built on May 29, 2024, 9 a.m.