# 退化したウィシャート行列の一般化逆行列を求める library(MASS) # トレースの関数 tr=function(w){ kk=dim(w) res=0 for (i in 1:kk[1]){ res=w[i,i]+res } return(res) } # 次元 no.of.dim<-100 # 標本数 no.of.sample<-12 tr=function(w){ kk=dim(w) res=0 for (i in 1:kk[1]){ res=w[i,i]+res } return(res) } print(no.of.sample) emp<-rep(0,no.of.dim) wishart.matrix<-matrix(rep(0,no.of.dim**2),no.of.dim) #print(wishart.matrix) for (i in 1:no.of.sample){ x<-rnorm(no.of.dim,0,1) wishart.matrix<-wishart.matrix+x%*%t(x)/no.of.sample #print(wishart.matrix) } # Wishart matrix の固有根 emp<-c(eigen(wishart.matrix)$values) for (i in 1:no.of.dim){ if(emp[i]<1.0e-10)emp[i]=0 } # 一般化逆行列の計算 G <- ginv(wishart.matrix) GG=wishart.matrix%*%G%*%wishart.matrix c(eigen(GG)$values)