# PRINCIPAL COMPONENT ANALYSIS ################################### #install.packages("FactoMineR") library(FactoMineR) # IRIS DATA head(iris) # faire l'ACP, en indiquant que la colonne 5 est qualitative myPCA=PCA(iris, scale.unit=TRUE, ncp=4, graph=F,quali.sup=5) myPCA$eig[,2] barplot(myPCA$eig[,2], main="Histogram of eigen values", names.arg=rownames(myPCA$eig), xlab="Axes", ylab="Pourcentage d’inertie") # on va s'interesser aux axes 1 et 2 plot.PCA(myPCA, axes=c(1, 2), choix="var") #plot.PCA(myPCA, axes=c(1, 3), choix="var") # graphe des individus # habillage = 5 => coloration des individus en fonction de la 5eme colonne plot.PCA(myPCA, axes=c(1, 2), choix="ind",habillage=5, col.hab=c("cyan","purple","red")) # Analyse Lineaire Discriminante library(MASS) myLDA <- lda(formula = Species ~ ., data = iris, prior = c(1,1,1)/3) plot(myLDA,col=as.numeric(iris$Species)) myLDA # MAIZE DATA tab<-read.table("maize_data.csv",header=T,sep=";") # create a data frame with a subset of variables # individus colores en fonction du genotype au marqueur ELF3 (colonne 2) tabPCA<-tab[,c(2,4:9)] # on garde les colonnes 2, 4 à 9 with genotype as qualitative myPCA=PCA(tabPCA, scale.unit=TRUE, graph=F,quali.sup=1) barplot(myPCA$eig[,2], main="Histogram of eigen values", names.arg=rownames(myPCA$eig), xlab="Axes", ylab="Inertia percentage") # my comments plot.PCA(myPCA, axes=c(1, 2), choix="var") plot.PCA(myPCA, axes=c(1, 2), choix="ind",habillage=1,label="none") # individus colores en fonction de l origine (colonne 3) tabPCA<-tab[,c(3:9)] # on garde les colonnes 2, 4 à 9 with genotype as qualitative myPCA=PCA(tabPCA, scale.unit=TRUE, graph=F,quali.sup=1) barplot(myPCA$eig[,2], main="Histogram of eigen values", names.arg=rownames(myPCA$eig), xlab="Axes", ylab="Inertia percentage") # my comments plot.PCA(myPCA, axes=c(1, 2), choix="var") plot.PCA(myPCA, axes=c(1, 2), choix="ind",habillage=1,label="none") # analyse discriminante en fonction de l'origine tabPCA<-tab[,c(3:9)] # on garde les colonnes 2, 4 à 9 with genotype as qualitative LDAmaize <- lda(formula = origin ~ ., data = tabPCA) plot(LDAmaize,dimen=2,col=as.numeric(as.factor(tabPCA$origin))) # analyse discriminante en fonction du marqueur tabPCA<-tab[,c(2,4:9)] # on garde les colonnes 2, 4 à 9 with genotype as qualitative LDAmaize2 <- lda(formula = ELF3 ~ ., data = tabPCA) plot(LDAmaize2,dimen=2)