MP law simulation
一个简单的例子解释随机矩阵里的MP law,
############################# ## ## A example to show the MP law in random matrix theory. ## ############################# library(ggplot2) ## The empirical distribution p <- 1000 n <- 2000 dat <- matrix(rnorm(p*n), nrow=p) dat.cov <- cov(t(dat)) dat.eig <- eigen(dat.cov) dat.val <- dat.eig$values dat.dsty <- density(dat.val) ## plot df.dsty <- data.frame(x=dat.dsty$x, y=dat.dsty$y) p <- ggplot(df.dsty, aes(x = x, y = y)) p + geom_line() + ylab('density') + ggtitle("MP law") ## The largest eigenvalue p <- 1000 n <- 2000 K0 <- 100 lam <- list() for (k in 1:K0){ dat <- matrix(rnorm(p*n), nrow=p) dat.cov <- cov(t(dat)) dat.eig <- eigen(dat.cov) dat.val <- dat.eig$values lam[[k]] <- dat.val } lam.max <- unlist(lapply(lam,max)) lam.min <- unlist(lapply(lam,min)) ###################### ## plot the max and min eigenvalue ###################### plot(lam.max, ylim=c(0,3), main='extreme eigenvalues of sample covariance matrix', xlab='Id', ylab='extreme eigenvalue', col='red', type='p') lines(lam.min,type='p', col='blue') ###################### ## Save the data ###################### lam.MP <- lam save(lam.MP, file="D:/BinbinChen/Literature/Orcal Defence/Simulation.MP.Rdata")