html_document : toc: true toc_float: true
#ETL
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)
library(scatterplot3d)
library(cluster)
df1 <- read_excel("Données_comparatives_voitures.xlsx")
# replace missing values (NA) by zero in all the dataset
df1[is.na(df1)] <- 0
cor(df1)
## Autonomie (km) Capacité batterie (kWh) Puissance (kW)
## Autonomie (km) 1.00000000 0.32981064 0.37425186
## Capacité batterie (kWh) 0.32981064 1.00000000 0.73355662
## Puissance (kW) 0.37425186 0.73355662 1.00000000
## Volume coffre (L) 0.46123753 0.64532311 0.94218437
## Places 0.02432215 0.01828766 0.02619381
## Prix (€) 0.27309591 0.94116747 0.66608631
## Volume coffre (L) Places Prix (€)
## Autonomie (km) 0.46123753 0.02432215 0.2730959
## Capacité batterie (kWh) 0.64532311 0.01828766 0.9411675
## Puissance (kW) 0.94218437 0.02619381 0.6660863
## Volume coffre (L) 1.00000000 0.02756115 0.5774464
## Places 0.02756115 1.00000000 0.0211141
## Prix (€) 0.57744642 0.02111410 1.0000000
princomp
## function (x, ...)
## UseMethod("princomp")
## <bytecode: 0x000002126dbda438>
## <environment: namespace:stats>
princomp(df1,cor = TRUE)
## Call:
## princomp(x = df1, cor = TRUE)
##
## Standard deviations:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6
## 1.8616819 0.9999954 0.9275310 0.7585284 0.2374058 0.2052055
##
## 6 variables and 50 observations.
acp<-princomp(df1,cor=TRUE)
names(acp)
## [1] "sdev" "loadings" "center" "scale" "n.obs" "scores" "call"
eigenvector <- acp$loadings
lambda <- acp$sdev*acp$sdev #variance = écrat-type^2
sum(lambda)
## [1] 6
Importance des composants : Deviation standart, proportion de la variance, proportion cumulative
summary(acp)
## Importance of components:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
## Standard deviation 1.8616819 0.9999954 0.9275310 0.75852841 0.237405838
## Proportion of Variance 0.5776432 0.1666651 0.1433856 0.09589423 0.009393589
## Cumulative Proportion 0.5776432 0.7443084 0.8876940 0.98358819 0.992981783
## Comp.6
## Standard deviation 0.205205512
## Proportion of Variance 0.007018217
## Cumulative Proportion 1.000000000
plot(1:6,lambda,type="b",ylab="Valeurspropres",xlab="Composantes
Principales",main="Eboulis des Valeurs Propres")
plot(acp)
#Coordonnées des individus dans la nouvelle base
acp$score #C=XP
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6
## [1,] -3.74550143 -1.25754858 -0.59873704 -0.30344694 0.060999969 -0.039727945
## [2,] -3.62826619 0.20411002 -0.67343426 -0.27755664 0.001234103 -0.064082588
## [3,] -3.44970864 1.17844799 -0.70233170 -0.32119568 -0.019734554 0.009595170
## [4,] -2.86438461 -1.12908154 1.09546439 0.50452853 -0.049590320 0.193497972
## [5,] -2.72209326 0.32951381 0.99056152 0.47857454 -0.089592344 0.214585993
## [6,] -2.37838866 1.29345683 0.89575289 0.57111462 0.066439831 0.083790022
## [7,] -2.30073411 -1.13864738 1.12986414 0.60740509 0.074975900 0.121432593
## [8,] -2.13640034 0.31463938 0.97169349 0.58662640 0.077558456 0.114046838
## [9,] -1.94465220 1.28756488 0.93306559 0.59557897 0.086353820 0.131303224
## [10,] -1.85296903 -1.14016790 1.22122234 0.66162599 0.082722048 0.146963718
## [11,] -0.83342998 0.32081843 1.33605920 -0.19248416 -0.045699725 0.044395128
## [12,] -1.22525177 1.17180001 -0.25637222 -0.96664941 -0.074966976 -0.136364312
## [13,] -1.18273046 -1.25877650 -0.01672396 -0.98490339 -0.161201238 -0.179740710
## [14,] -0.91173258 0.20326974 -0.05269676 -1.07875328 -0.139489003 -0.006318904
## [15,] -0.66187100 1.16994948 -0.14381475 -1.02969353 -0.057692321 -0.067992150
## [16,] -0.56658117 -1.26185864 0.09741322 -1.01285555 -0.061543559 -0.052128222
## [17,] -1.23275061 0.19467226 -0.20071437 -0.11532877 0.041345817 -0.021948978
## [18,] -1.07610230 1.16478247 -0.27758656 -0.05169186 0.089507078 0.008733315
## [19,] -1.04001543 -1.26468932 -0.02567528 -0.02837786 0.061167674 0.082537828
## [20,] -0.80010030 0.19622830 -0.08088109 -0.10326307 -0.006364470 0.007076123
## [21,] -0.65730651 1.17110139 -0.11148228 -0.11258522 -0.047581515 0.032110059
## [22,] -0.45350813 -1.30640447 -0.37556227 0.68817054 -0.811075231 -0.329426002
## [23,] 0.21845140 0.10378505 -0.86478784 1.01928393 -0.140921208 -0.728537365
## [24,] -0.10734733 1.08018391 -0.97413604 1.64419369 0.179031857 -0.059118134
## [25,] -0.07126046 -1.34928788 -0.72222475 1.66750769 0.150692454 0.014686380
## [26,] 0.25179004 0.10636490 -0.81303062 1.61857541 0.156911256 -0.133099209
## [27,] 0.42733389 1.07845752 -0.86499019 1.63195598 0.158763338 -0.133337893
## [28,] 0.41087599 -1.48043896 -2.13311398 0.42026666 0.348192467 0.253063187
## [29,] 0.03967671 0.02288717 -1.88322123 0.10126512 -0.273482128 0.567490626
## [30,] 0.21890056 1.04158733 -1.39383322 -0.73555597 -0.039121772 -0.258120958
## [31,] 0.28724428 -1.38953762 -1.15075065 -0.69412735 -0.069415052 -0.301790174
## [32,] 0.54753452 0.06998049 -1.21863286 -0.80550463 -0.048187364 -0.131569526
## [33,] 1.04193840 1.03501167 -1.27832081 -1.04395651 0.158720953 0.232069751
## [34,] 1.12463060 -1.40170465 -1.09735329 -1.07189958 0.147706967 0.230642041
## [35,] 1.28896436 0.05158211 -1.25552394 -1.09267826 0.150289523 0.223256285
## [36,] 1.67801635 1.15489716 0.27265291 0.10592436 -0.005866545 -0.054718912
## [37,] 1.32506256 -1.24433979 0.80346858 -0.25945531 0.643360480 -0.368218313
## [38,] 0.99670550 0.25411118 0.99998289 -0.70058463 -0.037699706 0.106252589
## [39,] 1.26033767 1.24101582 1.14061557 -0.60491760 -0.019441417 0.157650067
## [40,] 1.36444514 -1.19064425 1.38540189 -0.59780587 -0.029486309 0.162624673
## [41,] 1.24266891 0.26692348 1.21360123 -0.34404939 -0.188890861 -0.233911664
## [42,] 1.37475507 1.23926845 1.15109063 -0.37089894 -0.230592453 -0.212078887
## [43,] 1.39585124 -1.19374272 1.35832875 -0.37212330 -0.259610222 -0.142755994
## [44,] 2.37205834 0.20841418 0.84922596 -0.23557506 0.662103033 -0.145787956
## [45,] 2.91608117 1.13410016 0.33448884 0.21034119 0.058376001 0.084218055
## [46,] 2.92773906 -1.30267323 0.49951919 0.25562000 0.051888242 0.077703810
## [47,] 3.02103852 0.15055647 0.32541136 0.30806320 0.058997025 0.065231518
## [48,] 3.10413278 1.11753577 0.19369581 0.35961084 0.064406240 0.053503983
## [49,] 3.11579068 -1.31923762 0.35872615 0.40488965 0.057918481 0.046989738
## [50,] 3.89106275 0.07176323 -0.39137455 1.06679533 -0.782416719 0.335324110
var(acp$score)
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
## Comp.1 3.536591e+00 -1.102252e-16 -6.910572e-16 5.498896e-16 -6.910616e-16
## Comp.2 -1.102252e-16 1.020399e+00 1.467833e-16 -5.547865e-17 5.065043e-17
## Comp.3 -6.910572e-16 1.467833e-16 8.778711e-01 1.550852e-17 9.763296e-17
## Comp.4 5.498896e-16 -5.547865e-17 1.550852e-17 5.871075e-01 8.239494e-17
## Comp.5 -6.910616e-16 5.065043e-17 9.763296e-17 8.239494e-17 5.751177e-02
## Comp.6 1.370870e-15 -1.705530e-17 -2.239998e-16 -3.907664e-17 7.419655e-16
## Comp.6
## Comp.1 1.370870e-15
## Comp.2 -1.705530e-17
## Comp.3 -2.239998e-16
## Comp.4 -3.907664e-17
## Comp.5 7.419655e-16
## Comp.6 4.296868e-02
plot(acp$score[,1],acp$score[,2],type="n",xlab="C1",ylab="C2")
abline(h=0.0,v=0.0)
text(acp$score[,1],acp$score[,2],row.names(df1))
C1 <-acp$loadings[,1]*acp$sdev[1]
C2 <-acp$loadings[,2]*acp$sdev[2]
correlation<-cbind(C1,C2)
print(correlation,digits=2)
## C1 C2
## Autonomie (km) 0.522 0.0662
## Capacité batterie (kWh) 0.904 -0.0412
## Puissance (kW) 0.920 -0.0074
## Volume coffre (L) 0.888 0.0080
## Places 0.039 0.9960
## Prix (€) 0.860 -0.0423
print(correlation^2,digits=2)
## C1 C2
## Autonomie (km) 0.2727 4.4e-03
## Capacité batterie (kWh) 0.8178 1.7e-03
## Puissance (kW) 0.8466 5.5e-05
## Volume coffre (L) 0.7880 6.4e-05
## Places 0.0015 9.9e-01
## Prix (€) 0.7392 1.8e-03
uncricle=cbind(cos((0:360)/180*pi),sin((0:360)/180*pi))
plot(uncricle,type="l",lty="solid",col="blue",lwd="2",xlab="C1",ylab="C2",cex.lab=1.2,cex.axis=1.2,cex.main=1.8)
abline(h=0.0,v=0.0)
text(C1,C2,labels=colnames(df1),cex=1)
cor(df1,acp$scores)
## Comp.1 Comp.2 Comp.3 Comp.4
## Autonomie (km) 0.52224858 0.066233077 0.77539901 0.348311238
## Capacité batterie (kWh) 0.90432478 -0.041240388 -0.29383516 0.255421018
## Puissance (kW) 0.92011989 -0.007395150 0.02183889 -0.359729250
## Volume coffre (L) 0.88769097 0.008005754 0.17847680 -0.398952456
## Places 0.03891561 0.995990036 -0.08054010 0.001391419
## Prix (€) 0.85975703 -0.042287755 -0.36594175 0.316598493
## Comp.5 Comp.6
## Autonomie (km) 0.0030137371 0.0172097374
## Capacité batterie (kWh) 0.1516576977 -0.0769212414
## Puissance (kW) 0.0664320684 0.1379471189
## Volume coffre (L) -0.0795137681 -0.1208353116
## Places 0.0008264696 -0.0003130401
## Prix (€) -0.1503863351 0.0475980209
#covarinace entre variables initial et variables composant principales
biplot(acp)
## Complément de Statistqus descriptive
names(df1) #variables initial
## [1] "Autonomie (km)" "Capacité batterie (kWh)"
## [3] "Puissance (kW)" "Volume coffre (L)"
## [5] "Places" "Prix (€)"
row.names(df1) #individus
## [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15"
## [16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
## [31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45"
## [46] "46" "47" "48" "49" "50"
n<-nrow(df1) #nombre d'individus
print(n)
## [1] 50
apply(df1,2,min) # valeur min pour chaque variable
## Autonomie (km) Capacité batterie (kWh) Puissance (kW)
## 200 50 70
## Volume coffre (L) Places Prix (€)
## 180 2 18550
apply(df1,2,function(x)(1:50)[x==min(x)])
## $`Autonomie (km)`
## [1] 1
##
## $`Capacité batterie (kWh)`
## [1] 1 2 3 4 5
##
## $`Puissance (kW)`
## [1] 1 2
##
## $`Volume coffre (L)`
## [1] 1
##
## $Places
## [1] 1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49
##
## $`Prix (€)`
## [1] 1
# xmin pour chaque variable
#apply(nomfichier,2,function(x)(1:derniére ligne)[x==min(x)]) <- xmin pour chaque variable
apply(df1,2,max) #valeur max pour chaque variable
## Autonomie (km) Capacité batterie (kWh) Puissance (kW)
## 600 150 200
## Volume coffre (L) Places Prix (€)
## 1000 7 83018
apply(df1,2,function(x)(1:50)[x==max(x)]) # xmax pour chaque variable
## $`Autonomie (km)`
## [1] 44 45 46 47 48 49 50
##
## $`Capacité batterie (kWh)`
## [1] 50
##
## $`Puissance (kW)`
## [1] 45 46 47 48 49 50
##
## $`Volume coffre (L)`
## [1] 42 43 44 45 46 47 48 49 50
##
## $Places
## [1] 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48
##
## $`Prix (€)`
## [1] 50
hist(df1[[1]])
## Distance chaque individu avec les variables initial
stars(USArrests[, 1:4], key.loc = c(14, 2), main = "USARRESTS : fullstars()",flip.labels=FALSE)
apply(df1,2,mean)
## Autonomie (km) Capacité batterie (kWh) Puissance (kW)
## 432.70 98.24 141.38
## Volume coffre (L) Places Prix (€)
## 652.80 4.62 41271.36
apply(df1,2,var)
## Autonomie (km) Capacité batterie (kWh) Puissance (kW)
## 1.750936e+04 8.979412e+02 1.753914e+03
## Volume coffre (L) Places Prix (€)
## 7.459710e+04 4.281224e+00 2.020132e+08
summary(df1)
## Autonomie (km) Capacité batterie (kWh) Puissance (kW) Volume coffre (L)
## Min. :200.0 Min. : 50.00 Min. : 70.0 Min. : 180.0
## 1st Qu.:318.8 1st Qu.: 72.00 1st Qu.:106.8 1st Qu.: 425.0
## Median :445.0 Median : 99.00 Median :143.5 Median : 665.0
## Mean :432.7 Mean : 98.24 Mean :141.4 Mean : 652.8
## 3rd Qu.:540.0 3rd Qu.:125.00 3rd Qu.:177.2 3rd Qu.: 915.0
## Max. :600.0 Max. :150.00 Max. :200.0 Max. :1000.0
## Places Prix (€)
## Min. :2.00 Min. :18550
## 1st Qu.:2.00 1st Qu.:29722
## Median :5.00 Median :40894
## Mean :4.62 Mean :41271
## 3rd Qu.:7.00 3rd Qu.:52066
## Max. :7.00 Max. :83018
boxplot(df1)
# Partie 2 : ACP en 3D ## Matrice de correlation
cor(df1)
## Autonomie (km) Capacité batterie (kWh) Puissance (kW)
## Autonomie (km) 1.00000000 0.32981064 0.37425186
## Capacité batterie (kWh) 0.32981064 1.00000000 0.73355662
## Puissance (kW) 0.37425186 0.73355662 1.00000000
## Volume coffre (L) 0.46123753 0.64532311 0.94218437
## Places 0.02432215 0.01828766 0.02619381
## Prix (€) 0.27309591 0.94116747 0.66608631
## Volume coffre (L) Places Prix (€)
## Autonomie (km) 0.46123753 0.02432215 0.2730959
## Capacité batterie (kWh) 0.64532311 0.01828766 0.9411675
## Puissance (kW) 0.94218437 0.02619381 0.6660863
## Volume coffre (L) 1.00000000 0.02756115 0.5774464
## Places 0.02756115 1.00000000 0.0211141
## Prix (€) 0.57744642 0.02111410 1.0000000
names(df1) #variables initial
## [1] "Autonomie (km)" "Capacité batterie (kWh)"
## [3] "Puissance (kW)" "Volume coffre (L)"
## [5] "Places" "Prix (€)"
row.names(df1) #individus
## [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15"
## [16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
## [31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45"
## [46] "46" "47" "48" "49" "50"
n<-nrow(df) #nombre d'individus
print(n)
## NULL
apply(df1,2,min) # valeuer min pour chaque variable
## Autonomie (km) Capacité batterie (kWh) Puissance (kW)
## 200 50 70
## Volume coffre (L) Places Prix (€)
## 180 2 18550
apply(df1,2,function(x)(1:38)[x==min(x)]) # xmin pour chaque variable
## $`Autonomie (km)`
## [1] 1
##
## $`Capacité batterie (kWh)`
## [1] 1 2 3 4 5
##
## $`Puissance (kW)`
## [1] 1 2
##
## $`Volume coffre (L)`
## [1] 1
##
## $Places
## [1] 1 4 7 10 13 16 19 22 25 28 31 34 37 NA NA NA NA
##
## $`Prix (€)`
## [1] 1
#apply(nomfichier,2,function(x)(1:derniére ligne)[x==min(x)]) <- xmin pour chaque variable
apply(df1,2,max) #valeuer max pour chaque variable
## Autonomie (km) Capacité batterie (kWh) Puissance (kW)
## 600 150 200
## Volume coffre (L) Places Prix (€)
## 1000 7 83018
apply(df1,2,function(x)(1:38)[x==max(x)]) # xmax pour chaque variable
## $`Autonomie (km)`
## [1] NA NA NA NA NA NA NA
##
## $`Capacité batterie (kWh)`
## [1] NA
##
## $`Puissance (kW)`
## [1] NA NA NA NA NA NA
##
## $`Volume coffre (L)`
## [1] NA NA NA NA NA NA NA NA NA
##
## $Places
## [1] 3 6 9 12 15 18 21 24 27 30 33 36 NA NA NA NA
##
## $`Prix (€)`
## [1] NA
#Histograms pour x1
hist(df1[[1]])
#Histograms pour X2
hist(df1[[2]])
#Histograms pour X3
hist(df1[[3]])
#Histograms pour X4
hist(df1[[4]])
hist(df1[[5]])
#Histograms pour X6
hist(df1[[6]])
## Distance chaque individu avec les variables initial
stars(df1[, 1:5], key.loc = c(14, 2), main = "Notes : full stars()",flip.labels=FALSE)
apply(df1,2,mean)
## Autonomie (km) Capacité batterie (kWh) Puissance (kW)
## 432.70 98.24 141.38
## Volume coffre (L) Places Prix (€)
## 652.80 4.62 41271.36
apply(df1,2,var)
## Autonomie (km) Capacité batterie (kWh) Puissance (kW)
## 1.750936e+04 8.979412e+02 1.753914e+03
## Volume coffre (L) Places Prix (€)
## 7.459710e+04 4.281224e+00 2.020132e+08
summary(df1)
## Autonomie (km) Capacité batterie (kWh) Puissance (kW) Volume coffre (L)
## Min. :200.0 Min. : 50.00 Min. : 70.0 Min. : 180.0
## 1st Qu.:318.8 1st Qu.: 72.00 1st Qu.:106.8 1st Qu.: 425.0
## Median :445.0 Median : 99.00 Median :143.5 Median : 665.0
## Mean :432.7 Mean : 98.24 Mean :141.4 Mean : 652.8
## 3rd Qu.:540.0 3rd Qu.:125.00 3rd Qu.:177.2 3rd Qu.: 915.0
## Max. :600.0 Max. :150.00 Max. :200.0 Max. :1000.0
## Places Prix (€)
## Min. :2.00 Min. :18550
## 1st Qu.:2.00 1st Qu.:29722
## Median :5.00 Median :40894
## Mean :4.62 Mean :41271
## 3rd Qu.:7.00 3rd Qu.:52066
## Max. :7.00 Max. :83018
boxplot(df1)
## Nuages des points des individus dans chaque pair variables
(xi,xj)
plot(df1)
pairs(df1)
## R-package pour ACP
princomp
## function (x, ...)
## UseMethod("princomp")
## <bytecode: 0x000002126dbda438>
## <environment: namespace:stats>
princomp(df1,cor = TRUE)
## Call:
## princomp(x = df1, cor = TRUE)
##
## Standard deviations:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6
## 1.8616819 0.9999954 0.9275310 0.7585284 0.2374058 0.2052055
##
## 6 variables and 50 observations.
acp<-princomp(df1,cor=TRUE)
names(acp)
## [1] "sdev" "loadings" "center" "scale" "n.obs" "scores" "call"
summary(acp)
## Importance of components:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
## Standard deviation 1.8616819 0.9999954 0.9275310 0.75852841 0.237405838
## Proportion of Variance 0.5776432 0.1666651 0.1433856 0.09589423 0.009393589
## Cumulative Proportion 0.5776432 0.7443084 0.8876940 0.98358819 0.992981783
## Comp.6
## Standard deviation 0.205205512
## Proportion of Variance 0.007018217
## Cumulative Proportion 1.000000000
plot(1:6,lambda,type="b",ylab="Valeurspropres",xlab="Composantes Principales",main="Eboulis
des Valeurs Propres")
plot(acp)
## Coordonnées des individus dans la nouvelle base
acp$score #C=XP
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6
## [1,] -3.74550143 -1.25754858 -0.59873704 -0.30344694 0.060999969 -0.039727945
## [2,] -3.62826619 0.20411002 -0.67343426 -0.27755664 0.001234103 -0.064082588
## [3,] -3.44970864 1.17844799 -0.70233170 -0.32119568 -0.019734554 0.009595170
## [4,] -2.86438461 -1.12908154 1.09546439 0.50452853 -0.049590320 0.193497972
## [5,] -2.72209326 0.32951381 0.99056152 0.47857454 -0.089592344 0.214585993
## [6,] -2.37838866 1.29345683 0.89575289 0.57111462 0.066439831 0.083790022
## [7,] -2.30073411 -1.13864738 1.12986414 0.60740509 0.074975900 0.121432593
## [8,] -2.13640034 0.31463938 0.97169349 0.58662640 0.077558456 0.114046838
## [9,] -1.94465220 1.28756488 0.93306559 0.59557897 0.086353820 0.131303224
## [10,] -1.85296903 -1.14016790 1.22122234 0.66162599 0.082722048 0.146963718
## [11,] -0.83342998 0.32081843 1.33605920 -0.19248416 -0.045699725 0.044395128
## [12,] -1.22525177 1.17180001 -0.25637222 -0.96664941 -0.074966976 -0.136364312
## [13,] -1.18273046 -1.25877650 -0.01672396 -0.98490339 -0.161201238 -0.179740710
## [14,] -0.91173258 0.20326974 -0.05269676 -1.07875328 -0.139489003 -0.006318904
## [15,] -0.66187100 1.16994948 -0.14381475 -1.02969353 -0.057692321 -0.067992150
## [16,] -0.56658117 -1.26185864 0.09741322 -1.01285555 -0.061543559 -0.052128222
## [17,] -1.23275061 0.19467226 -0.20071437 -0.11532877 0.041345817 -0.021948978
## [18,] -1.07610230 1.16478247 -0.27758656 -0.05169186 0.089507078 0.008733315
## [19,] -1.04001543 -1.26468932 -0.02567528 -0.02837786 0.061167674 0.082537828
## [20,] -0.80010030 0.19622830 -0.08088109 -0.10326307 -0.006364470 0.007076123
## [21,] -0.65730651 1.17110139 -0.11148228 -0.11258522 -0.047581515 0.032110059
## [22,] -0.45350813 -1.30640447 -0.37556227 0.68817054 -0.811075231 -0.329426002
## [23,] 0.21845140 0.10378505 -0.86478784 1.01928393 -0.140921208 -0.728537365
## [24,] -0.10734733 1.08018391 -0.97413604 1.64419369 0.179031857 -0.059118134
## [25,] -0.07126046 -1.34928788 -0.72222475 1.66750769 0.150692454 0.014686380
## [26,] 0.25179004 0.10636490 -0.81303062 1.61857541 0.156911256 -0.133099209
## [27,] 0.42733389 1.07845752 -0.86499019 1.63195598 0.158763338 -0.133337893
## [28,] 0.41087599 -1.48043896 -2.13311398 0.42026666 0.348192467 0.253063187
## [29,] 0.03967671 0.02288717 -1.88322123 0.10126512 -0.273482128 0.567490626
## [30,] 0.21890056 1.04158733 -1.39383322 -0.73555597 -0.039121772 -0.258120958
## [31,] 0.28724428 -1.38953762 -1.15075065 -0.69412735 -0.069415052 -0.301790174
## [32,] 0.54753452 0.06998049 -1.21863286 -0.80550463 -0.048187364 -0.131569526
## [33,] 1.04193840 1.03501167 -1.27832081 -1.04395651 0.158720953 0.232069751
## [34,] 1.12463060 -1.40170465 -1.09735329 -1.07189958 0.147706967 0.230642041
## [35,] 1.28896436 0.05158211 -1.25552394 -1.09267826 0.150289523 0.223256285
## [36,] 1.67801635 1.15489716 0.27265291 0.10592436 -0.005866545 -0.054718912
## [37,] 1.32506256 -1.24433979 0.80346858 -0.25945531 0.643360480 -0.368218313
## [38,] 0.99670550 0.25411118 0.99998289 -0.70058463 -0.037699706 0.106252589
## [39,] 1.26033767 1.24101582 1.14061557 -0.60491760 -0.019441417 0.157650067
## [40,] 1.36444514 -1.19064425 1.38540189 -0.59780587 -0.029486309 0.162624673
## [41,] 1.24266891 0.26692348 1.21360123 -0.34404939 -0.188890861 -0.233911664
## [42,] 1.37475507 1.23926845 1.15109063 -0.37089894 -0.230592453 -0.212078887
## [43,] 1.39585124 -1.19374272 1.35832875 -0.37212330 -0.259610222 -0.142755994
## [44,] 2.37205834 0.20841418 0.84922596 -0.23557506 0.662103033 -0.145787956
## [45,] 2.91608117 1.13410016 0.33448884 0.21034119 0.058376001 0.084218055
## [46,] 2.92773906 -1.30267323 0.49951919 0.25562000 0.051888242 0.077703810
## [47,] 3.02103852 0.15055647 0.32541136 0.30806320 0.058997025 0.065231518
## [48,] 3.10413278 1.11753577 0.19369581 0.35961084 0.064406240 0.053503983
## [49,] 3.11579068 -1.31923762 0.35872615 0.40488965 0.057918481 0.046989738
## [50,] 3.89106275 0.07176323 -0.39137455 1.06679533 -0.782416719 0.335324110
a<-acp$score
s3d <- scatterplot3d(a[,1:3], type="h", angle= 60, grid=TRUE, box = FALSE, pch=16, color ="steelblue",
main="3D Scatter Plot",
xlab = "text",
ylab = "text",
zlab = "text")
#text (s3d$xyz.convert(C[, 1:3]), labels = rownames(C),cex= 0.7)
cor(df1,acp$scores)
## Comp.1 Comp.2 Comp.3 Comp.4
## Autonomie (km) 0.52224858 0.066233077 0.77539901 0.348311238
## Capacité batterie (kWh) 0.90432478 -0.041240388 -0.29383516 0.255421018
## Puissance (kW) 0.92011989 -0.007395150 0.02183889 -0.359729250
## Volume coffre (L) 0.88769097 0.008005754 0.17847680 -0.398952456
## Places 0.03891561 0.995990036 -0.08054010 0.001391419
## Prix (€) 0.85975703 -0.042287755 -0.36594175 0.316598493
## Comp.5 Comp.6
## Autonomie (km) 0.0030137371 0.0172097374
## Capacité batterie (kWh) 0.1516576977 -0.0769212414
## Puissance (kW) 0.0664320684 0.1379471189
## Volume coffre (L) -0.0795137681 -0.1208353116
## Places 0.0008264696 -0.0003130401
## Prix (€) -0.1503863351 0.0475980209
C<-cor(df1,acp$scores)
C1<-C[,1]
C2<-C[,2]
C3<-C[,3]
barplot(C1)
barplot(C2)
barplot(C3)
# Classification Hierarchique
d <- dist(a,diag=F,upper=F)
m<-as.matrix(d)
row.names(m)
## [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15"
## [16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
## [31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45"
## [46] "46" "47" "48" "49" "50"
apply(m,2,function(x)(1:50)[x==max(x)])
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
## 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 1 1 3 1
## 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
## 1 6 4 4 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1
apply(m,2,function(x)(1:50)[x==min(x)])
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
## 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
## 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
min(d)
## [1] 0.2805737
max(d)
## [1] 7.928226
c<-scale(a)
b<-data.frame(c)
d1<-dist(b)
m<-as.matrix(d1)
row.names(m)
## [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15"
## [16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
## [31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45"
## [46] "46" "47" "48" "49" "50"
apply(m,2,function(x)(1:50)[x==max(x)])
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
## 50 50 50 23 23 50 50 50 22 50 50 50 50 50 50 50 50 50 50 50 50 44 29 22 50 50
## 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
## 50 22 37 50 50 50 22 23 22 22 50 23 23 23 28 28 29 50 22 23 22 22 23 37
apply(m,2,function(x)(1:50)[x==min(x)])
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
## 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
## 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
min(d1)
## [1] 0.2956717
max(d1)
## [1] 7.419392
hc1<-hclust(d1,method="ward.D")
plot(hc1)
## Library Cluster Dendogram
cutree(hc1, k = 1:5)
## 1 2 3 4 5
## [1,] 1 1 1 1 1
## [2,] 1 1 1 1 1
## [3,] 1 1 1 1 1
## [4,] 1 2 2 2 2
## [5,] 1 2 2 2 2
## [6,] 1 2 2 2 2
## [7,] 1 2 2 2 2
## [8,] 1 2 2 2 2
## [9,] 1 2 2 2 2
## [10,] 1 2 2 2 2
## [11,] 1 2 3 3 3
## [12,] 1 1 1 1 1
## [13,] 1 1 1 1 1
## [14,] 1 1 1 1 1
## [15,] 1 1 1 1 1
## [16,] 1 1 1 1 1
## [17,] 1 1 1 1 1
## [18,] 1 1 1 1 1
## [19,] 1 1 1 1 1
## [20,] 1 1 1 1 1
## [21,] 1 1 1 1 1
## [22,] 1 1 1 1 1
## [23,] 1 1 1 1 1
## [24,] 1 1 1 4 4
## [25,] 1 1 1 4 4
## [26,] 1 1 1 4 4
## [27,] 1 1 1 4 4
## [28,] 1 1 1 4 4
## [29,] 1 1 1 4 5
## [30,] 1 1 1 1 1
## [31,] 1 1 1 1 1
## [32,] 1 1 1 1 1
## [33,] 1 1 1 4 5
## [34,] 1 1 1 4 5
## [35,] 1 1 1 4 5
## [36,] 1 2 3 3 3
## [37,] 1 2 3 3 3
## [38,] 1 2 3 3 3
## [39,] 1 2 3 3 3
## [40,] 1 2 3 3 3
## [41,] 1 2 3 3 3
## [42,] 1 2 3 3 3
## [43,] 1 2 3 3 3
## [44,] 1 2 3 3 3
## [45,] 1 2 3 3 3
## [46,] 1 2 3 3 3
## [47,] 1 2 3 3 3
## [48,] 1 2 3 3 3
## [49,] 1 2 3 3 3
## [50,] 1 1 1 4 5
g<-cutree(hc1, k = 1:5)
plot(hc1,hang=1)
rect.hclust(hc1,k=2,border="red")
## ACP
acp<-princomp(c,cor=T)
summary(acp)
## Importance of components:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
## Standard deviation 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
## Proportion of Variance 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667
## Cumulative Proportion 0.1666667 0.3333333 0.5000000 0.6666667 0.8333333
## Comp.6
## Standard deviation 1.0000000
## Proportion of Variance 0.1666667
## Cumulative Proportion 1.0000000
b1<-acp$score
Comp<-acp$scores[,1 :2]
d2<-dist(Comp)
hc2<-hclust(d2,method="ward.D")
opar<-par(mfrow=c(1,2))
plot(hc2)
biplot(acp)
## Ceci est le petit 8
cutree(hc2, k = 1:5)
## 1 2 3 4 5
## [1,] 1 1 1 1 1
## [2,] 1 1 1 1 1
## [3,] 1 1 1 1 1
## [4,] 1 1 1 1 2
## [5,] 1 1 1 1 2
## [6,] 1 1 1 1 2
## [7,] 1 1 1 1 2
## [8,] 1 1 1 1 2
## [9,] 1 1 1 1 2
## [10,] 1 1 1 1 2
## [11,] 1 1 1 1 1
## [12,] 1 1 1 1 1
## [13,] 1 1 2 2 3
## [14,] 1 1 1 1 1
## [15,] 1 1 1 1 1
## [16,] 1 1 1 1 1
## [17,] 1 1 1 1 1
## [18,] 1 1 1 1 1
## [19,] 1 1 1 1 1
## [20,] 1 1 1 1 1
## [21,] 1 1 1 1 1
## [22,] 1 1 2 3 4
## [23,] 1 1 2 3 4
## [24,] 1 2 3 4 5
## [25,] 1 2 3 4 5
## [26,] 1 2 3 4 5
## [27,] 1 2 3 4 5
## [28,] 1 2 3 4 5
## [29,] 1 2 3 4 5
## [30,] 1 1 2 2 3
## [31,] 1 1 2 2 3
## [32,] 1 1 2 2 3
## [33,] 1 2 3 4 5
## [34,] 1 2 3 4 5
## [35,] 1 2 3 4 5
## [36,] 1 1 2 2 3
## [37,] 1 1 1 1 1
## [38,] 1 1 1 1 1
## [39,] 1 1 1 1 1
## [40,] 1 1 1 1 1
## [41,] 1 1 2 2 3
## [42,] 1 1 2 2 3
## [43,] 1 1 2 2 3
## [44,] 1 2 3 4 5
## [45,] 1 2 3 4 5
## [46,] 1 2 3 4 5
## [47,] 1 2 3 4 5
## [48,] 1 2 3 4 5
## [49,] 1 2 3 4 5
## [50,] 1 1 2 2 3
g<-cutree(hc2, k = 1:5)
plot(hc2,hang=1)
rect.hclust(hc2,k=2,border="red")
cl2<-cutree(hc2,2)
cl2
## [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 1 1 1 2 2 2 1 1 1
## [39] 1 1 1 1 1 2 2 2 2 2 2 1
clusplot(dist(b),cl2,diss=T,shade=T,color=T,labels=2,main="CHA/ACP")
cl3<-cutree(hc2,3)
clusplot(dist(b),cl3,diss=T,shade=T,color=T,labels=2,main="CHA/ACP")