290 lines
7.8 KiB
Text
290 lines
7.8 KiB
Text
install.packages("FactoMineR")
|
|
install.packages("factoextra")
|
|
setwd("~/Bureau/Ana_donn/TP3")
|
|
library(knitr)
|
|
## Global options
|
|
options(max.print="75")
|
|
opts_chunk$set(echo=TRUE,
|
|
cache=FALSE,
|
|
prompt=FALSE,
|
|
tidy=TRUE,
|
|
comment=NA,
|
|
message=FALSE,
|
|
warning=FALSE,
|
|
class.source="badCode")
|
|
opts_knit$set(width=75)
|
|
library(corrplot)
|
|
library(ggplot2)
|
|
library(gridExtra)
|
|
library(FactoMineR)
|
|
library(factoextra)
|
|
library(reshape2)
|
|
library(knitr)
|
|
## Global options
|
|
options(max.print="75")
|
|
opts_chunk$set(echo=TRUE,
|
|
cache=FALSE,
|
|
prompt=FALSE,
|
|
tidy=TRUE,
|
|
comment=NA,
|
|
message=FALSE,
|
|
warning=FALSE,
|
|
class.source="badCode")
|
|
opts_knit$set(width=75)
|
|
library(knitr)
|
|
## Global options
|
|
options(max.print="75")
|
|
opts_chunk$set(echo=TRUE,
|
|
cache=FALSE,
|
|
prompt=FALSE,
|
|
tidy=TRUE,
|
|
comment=NA,
|
|
message=FALSE,
|
|
warning=FALSE,
|
|
class.source="badCode")
|
|
opts_knit$set(width=75)
|
|
library(corrplot)
|
|
library(ggplot2)
|
|
library(gridExtra)
|
|
library(FactoMineR)
|
|
library(factoextra)
|
|
library(reshape2)
|
|
Ozone<-read.table("Ozone.txt",header=T)
|
|
Ozone$pluie<-as.factor(Ozone$pluie)
|
|
Ozone$vent<-as.factor(Ozone$vent)
|
|
Ozone<-Ozone[,-11]
|
|
summary(Ozone)
|
|
dim(Ozone)
|
|
ggplot(melt(Ozone[,-c(11,12)]),aes(x=variable,y=value))+geom_boxplot()
|
|
g1<-ggplot(Ozone,aes(x=maxO3))+geom_density()
|
|
g2<-ggplot(melt(Ozone[,c(2:4)]),aes(x=value,color=variable))+geom_density()
|
|
g3<-ggplot(melt(Ozone[,c(5:7)]),aes(x=value,color=variable))+geom_density()
|
|
g4<-ggplot(melt(Ozone[,c(8:10)]),aes(x=value,color=variable))+geom_density()
|
|
grid.arrange(g1,g2,g3,g4,ncol=2)
|
|
ggplot(Ozone, aes(x = pluie)) +
|
|
geom_bar(aes(y = (..count..)/sum(..count..)))+ylab("")+ggtitle("Frequences")
|
|
quan <- as.vector(table(Ozone$vent))/nrow(Ozone)
|
|
df <- data.frame(group = levels(Ozone$vent),value = quan)
|
|
ggplot(df, aes(x="", y=value, fill=group))+
|
|
geom_bar(width = 1, stat = "identity")+ coord_polar("y", start=0)+ theme(legend.position="bottom")
|
|
corrplot(cor(Ozone[,-c(1,2)]),method = "ellipse")
|
|
corrplot(cor(Ozone[,-c(9,10)]),method = "ellipse")
|
|
corrplot(cor(Ozone[,-(9:10)]),method = "ellipse")
|
|
corrplot(cor(Ozone[,-(9,10)]),method = "ellipse")
|
|
corrplot(cor(Ozone[,-c(9,10)]),method = "ellipse")
|
|
corrplot(cor(Ozone[,-c(9,10)]),method = "ellipse")
|
|
dim(Ozone)
|
|
corrplot(cor(Ozone[,-c(11,12)]),method = "ellipse")
|
|
help("scale")
|
|
OzoneC<-scale(Ozone[,-c(11,12)],scale=FALSE) # A COMPLETER
|
|
apply(OzoneC,2,mean)
|
|
n=112
|
|
p=10
|
|
W<-diag(1/n,nrow=n,ncol=n)
|
|
M<- diag(1,nrow = p, ncol = p)
|
|
Gamma<- t(OzoneC)%*%W%*%OzoneC # A COMPLETER
|
|
A<-eigen(Gamma
|
|
Gamma<- t(OzoneC)%*%W%*%OzoneC # A COMPLETER
|
|
A<-eigen(Gamma)
|
|
Gamma<- t(OzoneC)%*%W%*%OzoneC # A COMPLETER
|
|
A<-eigen(Gamma)
|
|
A
|
|
n=112
|
|
p=10
|
|
W<- diag(1/n,nrow(OzoneC))
|
|
M<- diag(1,ncol(OzoneC))
|
|
n=nrow(OzoneC)
|
|
p=ncol(OzoneC)
|
|
W<- diag(1/n,n)
|
|
M<- diag(1,p)
|
|
Gamma<- t(OzoneC)%*%W%*%OzoneC # A COMPLETER
|
|
A<-eigen(Gamma)
|
|
A$values
|
|
A$values
|
|
"La trace de gamma est l'inertie de Ozone"
|
|
sum(A$values)
|
|
dim(OzoneC)
|
|
dim(W)
|
|
dim(M)
|
|
A$values
|
|
"La trace de gamma est l'inertie de Ozone"
|
|
sum(A$values)
|
|
mean(OzoneC**2)
|
|
A$values
|
|
"La trace de gamma est l'inertie de Ozone"
|
|
sum(A$values)
|
|
sum(OzoneC**2)/n
|
|
A$values
|
|
"La trace de gamma est l'inertie de Ozone"
|
|
sum(A$values)
|
|
sum(OzoneC**2)/n
|
|
sum(A$values)==sum(OzoneC**2)/n
|
|
A$values
|
|
"La trace de gamma est l'inertie de Ozone"
|
|
sum(A$values)
|
|
sum(OzoneC**2)/n
|
|
sum(A$values)===sum(OzoneC**2)/n
|
|
A$values/sum(A$values)
|
|
A$values/sum(A$values)
|
|
cumsum(A$values)/sum(A$values)
|
|
A$values/sum(A$values)
|
|
B=cumsum(A$values)/sum(A$values)
|
|
hist(B)
|
|
B=A$values/sum(A$values)
|
|
C=cumsum(A$values)/sum(A$values)
|
|
hist(B)
|
|
hist(C)
|
|
A$values/sum(A$values)
|
|
cumsum(A$values)/sum(A$values)
|
|
C=OzoneC%*%A$vectors
|
|
C=OzoneC%*%A$vectors
|
|
C
|
|
dim(C)
|
|
C=OzoneC%*%A$vectors
|
|
C
|
|
dim(C)
|
|
boxplot(OzoneC)
|
|
respca<-PCA(Ozone,quali.sup=c(11,12),scale.unit = F,graph=F)
|
|
respca$eig
|
|
fviz_eig(respca)
|
|
respca$ind$coord$
|
|
2
|
|
respca<-PCA(Ozone,quali.sup=c(11,12),scale.unit = F,graph=F)
|
|
respca$eig
|
|
fviz_eig(respca)
|
|
fviz_pca_ind(respca,geom=c("point"))
|
|
fviz_pca_ind(respca,geom=c("point"))
|
|
fviz_pca_ind(respca,col.ind="contrib",geom=c("point"))
|
|
fviz_pca_ind(respca,geom=c("point"),select.ind = list(cos2=0.95))
|
|
fviz_pca_ind(respca,habillage=11,geom=c("point"))
|
|
fviz_pca_ind(respca,habillage=12,geom=c("point"))
|
|
plot(respca,choix="varcor")
|
|
corrplot(respca$var$cor,method="ellipse")
|
|
s<-sqrt((n-1)*apply(OzoneC,2,var)/n)
|
|
OzoneCR<-OzoneC%*%diag(1/s)
|
|
s<-sqrt((n-1)*apply(OzoneC,2,var)/n)
|
|
OzoneCR<-OzoneC%*%diag(1/s)
|
|
OzoneCR
|
|
scale(Ozone[,-c(11,12)])
|
|
Gamma2<- t(OzoneCR)%*%W%*%OzoneCR # A COMPLETER
|
|
B<-eigen(Gamma2)
|
|
Gamma2<- t(OzoneCR)%*%W%*%OzoneCR # A COMPLETER
|
|
B<-eigen(Gamma2)
|
|
B
|
|
sum(B$values)
|
|
Gamma2<- t(OzoneCR)%*%W%*%OzoneCR # A COMPLETER
|
|
B<-eigen(Gamma2)
|
|
B
|
|
n=nrow(OzoneC)
|
|
p=ncol(OzoneC)
|
|
W<- diag(1/n,n)
|
|
M<- diag(1,p)
|
|
M
|
|
n=nrow(OzoneC)
|
|
p=ncol(OzoneC)
|
|
W<- diag(1/n,n)
|
|
M<- diag(1,p)
|
|
sum(B$values)
|
|
Gamma2<- t(OzoneC)%*%W%*%OzoneC
|
|
B<-eigen(Gamma2)
|
|
B
|
|
Gamma2<- t(OzoneC)%*%W%*%OzoneC
|
|
B<-eigen(Gamma2)
|
|
B
|
|
Gamma2
|
|
Gamma2<- t(OzoneCR)%*%W%*%OzoneCR
|
|
B<-eigen(Gamma2)
|
|
B
|
|
Gamma2
|
|
M2<-diag(1/apply(OzoneC,2,var))
|
|
GammaM=Gamma%*%M2
|
|
eigen(Gamma2)
|
|
eigen(GammaM)
|
|
M2<-diag(1/apply(OzoneC,2,var))
|
|
GammaM=Gamma%*%M2
|
|
G=eigen(Gamma2)
|
|
GM=eigen(GammaM)
|
|
G$values
|
|
GM$values
|
|
M2<-diag(1/apply(OzoneC,2,var))
|
|
GammaM=Gamma%*%M2
|
|
G=eigen(Gamma2)
|
|
GM=eigen(GammaM)
|
|
sum(G$values)
|
|
sum(GM$values)
|
|
M2<-diag(1/apply(OzoneC,2,var))
|
|
GammaM=Gamma%*%M2
|
|
G=eigen(Gamma2)
|
|
GM=eigen(GammaM)
|
|
sum(G$values)
|
|
sum(GM$values)
|
|
G$vectors
|
|
GM$vectors
|
|
M2<-diag(1/(apply(OzoneC,2,var)*(n-1)/n))
|
|
GammaM=Gamma%*%M2
|
|
G=eigen(Gamma2)
|
|
GM=eigen(GammaM)
|
|
sum(G$values)
|
|
sum(GM$values)
|
|
G$vectors
|
|
GM$vectors
|
|
respca2<-PCA(Ozone,quali.sup=c(11,12),scale.unit=T,graph=F)
|
|
respca2$eig
|
|
fviz_eig(respca2)
|
|
fviz_pca_ind(respca2,geom=c("point"))
|
|
fviz_pca_ind(respca2,geom=c("point"))
|
|
fviz_pca_var(respca2)
|
|
corrplot(OzoneCR)
|
|
corrplot(OzoneCR([,-c(11,12)]))
|
|
corrplot(respca2$var$cor,method="ellipse")
|
|
fviz_pca_ind(respca2,col.ind="contrib",geom=c("point"))
|
|
fviz_pca_ind(respca2,geom=c("point"),select.ind = list(cos2=0.95))
|
|
fviz_pca_ind(respca2,habillage=11,geom=c("point"))
|
|
fviz_pca_ind(respca2,habillage=12,geom=c("point"))
|
|
fviz_pca_ind(respca2,geom=c("point"))
|
|
fviz_pca(respca2)
|
|
fviz_pca_ind(respca2,geom=c("point"))
|
|
fviz_pca(respca2,geom=c("point"))
|
|
g1<-fviz_pca_ind(respca2,geom=c("point"))
|
|
g2<-fviz_pca_var(respca2)
|
|
library(gridExtra)
|
|
grid.arrange(g1,g2,ncol=2)
|
|
fviz_pca_ind(respca2,col.ind="contrib",geom=c("point"))
|
|
fviz_pca_ind(respca2,geom=c("point"),select.ind = list(cos2=0.95))
|
|
fviz_pca_ind(respca2,habillage=11,geom=c("point"))
|
|
fviz_pca_ind(respca2,habillage=11,geom=c("point"))
|
|
fviz_pca_ind(respca2,col.ind="contrib",geom=c("point"))
|
|
fviz_pca_ind(respca2,geom=c("point"),select.ind = list(cos2=0.95))
|
|
fviz_pca_ind(respca2,habillage=11,geom=c("point"))
|
|
fviz_pca_ind(respca2,habillage=12,geom=c("point"))
|
|
g1<-fviz_pca_ind(respca2,geom=c("point"),habillage = 11)
|
|
g2<-fviz_pca_var(respca2)
|
|
library(gridExtra)
|
|
grid.arrange(g1,g2,ncol=2)
|
|
g1<-fviz_pca_ind(respca2,geom=c("point"))
|
|
g2<-fviz_pca_var(respca2,habillage = 11)
|
|
library(gridExtra)
|
|
grid.arrange(g1,g2,ncol=2)
|
|
g1<-fviz_pca_ind(respca2,geom=c("point"))
|
|
g2<-fviz_pca_var(respca2)
|
|
library(gridExtra)
|
|
grid.arrange(g1,g2,ncol=2)
|
|
fviz_pca_ind(respca2,col.ind="contrib",geom=c("point"))
|
|
fviz_pca_ind(respca2,geom=c("point"),select.ind = list(cos2=0.95))
|
|
fviz_pca_ind(respca2,habillage=11,geom=c("point"))
|
|
fviz_pca(respca2,habillage=12,geom=c("point"))
|
|
fviz_pca_ind(respca2,col.ind="contrib",geom=c("point"))
|
|
fviz_pca_ind(respca2,geom=c("point"),select.ind = list(cos2=0.95))
|
|
g3=fviz_pca_ind(respca2,habillage=11,geom=c("point"))
|
|
g4=fviz_pca(respca2,habillage=12,geom=c("point"))
|
|
grid.arrange(g3,g4,newpage=FALSE)
|
|
fviz_pca_ind(respca2,col.ind="contrib",geom=c("point"))
|
|
fviz_pca_ind(respca2,geom=c("point"),select.ind = list(cos2=0.95))
|
|
g3=fviz_pca_ind(respca2,habillage=11,geom=c("point"))
|
|
g4=fviz_pca_ind(respca2,habillage=12,geom=c("point"))
|
|
grid.arrange(g3,g4,newpage=FALSE)
|
|
fviz_pca_ind(respca2,col.ind="contrib",geom=c("point"))
|
|
fviz_pca_ind(respca2,geom=c("point"),select.ind = list(cos2=0.95))
|
|
g3=fviz_pca_ind(respca2,habillage=11,geom=c("point"))
|
|
g4=fviz_pca_ind(respca2,habillage=12,geom=c("point"))
|
|
grid.arrange(g3,g4)
|