KPCA protocol
#version information: v0.2 #date of update: 28/Dec/2017 library(kernlab) #"kernlab" is the name of R package used for analyses data_pre<-read.csv("filename.csv") #"filename" is the name of prepared csv file # An example of dataset prepared for KPCA # sample No. | variable 1 | variable 2 | variable 3 | ... # 1 | 0.1 | 10 | 1.9 | ... # 2 | 1.2 | 0.4 | 0.8 | ... # 3 | 5 | 1.2 | 0.6 | ... # ... | ... | ... | ... | ... #In this case, you have to delete the first column (sample No.) for the analyses, #i.e., the next command is required #data_pre<- data_pre[,-1] #parameter optimization (sigma in this case) sigma <- seq(0.01,0.09,by=0.01) par(mfrow=c(3,3)) for(i in 1:length(sigma)) {anova<-kpca(data_pre,kernel="anovadot",features=2,kpar=list(sigma=sigma[i],degree=1)) plot(pcv(anova), col=as.integer(label), main=paste("sigma = ",as.character(sigma[i]))) } #Kernel means a function type, #features means numbers of output variables, #kpar means hyperparameters of the associated kernel function. #The “label” is data of sample information (class, color, etc.), you should prepare. # Calculation of KPCA data.kpca <- kpca(data_pre,kernel="anova",features=2,kpar=list(sigma=0.135,degree=1)) #Print the principal component vectors pcv(data.kpca) #principal component vectors rotated(data.kpca) #loading value eig(data.kpca) #eigen value