# Simulation of a symmetric matrix
p <- 5
set.seed(1)
omega <- matrix(rnorm(p * p), ncol = p)
omega <- omega + t(omega)
diag(omega) <- 0
# Diagonal dominance maximising contrast
omega_pd <- MakePositiveDefinite(omega,
pd_strategy = "diagonally_dominant"
)
eigen(omega_pd$omega)$values # positive eigenvalues
# Diagonal dominance with specific proportion of explained variance by PC1
omega_pd <- MakePositiveDefinite(omega,
pd_strategy = "diagonally_dominant",
ev_xx = 0.55
)
lambda_inv <- eigen(cov2cor(solve(omega_pd$omega)))$values
max(lambda_inv) / sum(lambda_inv) # expected ev
# Version not scaled (using eigenvalues from the covariance)
omega_pd <- MakePositiveDefinite(omega,
pd_strategy = "diagonally_dominant",
ev_xx = 0.55, scale = FALSE
)
lambda_inv <- 1 / eigen(omega_pd$omega)$values
max(lambda_inv) / sum(lambda_inv) # expected ev
# Non-negative eigenvalues maximising contrast
omega_pd <- MakePositiveDefinite(omega,
pd_strategy = "min_eigenvalue"
)
eigen(omega_pd$omega)$values # positive eigenvalues
# Non-negative eigenvalues with specific proportion of explained variance by PC1
omega_pd <- MakePositiveDefinite(omega,
pd_strategy = "min_eigenvalue",
ev_xx = 0.7
)
lambda_inv <- eigen(cov2cor(solve(omega_pd$omega)))$values
max(lambda_inv) / sum(lambda_inv)
# Version not scaled (using eigenvalues from the covariance)
omega_pd <- MakePositiveDefinite(omega,
pd_strategy = "min_eigenvalue",
ev_xx = 0.7, scale = FALSE
)
lambda_inv <- 1 / eigen(omega_pd$omega)$values
max(lambda_inv) / sum(lambda_inv)
Run the code above in your browser using DataLab