Nothing
#' @param data is a total data set
#' @param m is the number of principal component
#' @return Ahat,Dhat,Sigmahat
#' @export cov
#' @examples
#' PC(data=data,m=m)
PC=function(data,m){
X<-scale(data)
p<-ncol(X)
n<-nrow(X)
Sigmahat<-cov(X)
eig<-eigen(Sigmahat)
lambdahat= eig$values[1:m]
ind<-order(lambdahat,decreasing=T)
lambdahat<-lambdahat[ind]
Q<- eig$vectors
Q<-Q[,ind]
Qhat<-Q[,1:m]
Ahat <- matrix(0, nrow = p, ncol = m)
for (j in 1:m) {Ahat[, j] <- sqrt(lambdahat[j]) * Qhat[, j]}; Ahat
h0 <- diag(Ahat %*% t(Ahat))
Dhat<- diag(Sigmahat - h0)
S2=Ahat %*% t(Ahat)+Dhat
return(
list(Ahat=Ahat,Dhat=Dhat,Sigmahat=Sigmahat))}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.