### Import data (data are imported from internet)

```{r}
decathlon <- read.table("https://www.institut-agro-rennes-angers.fr/math/RforStat/decathlon.csv", 
   header=TRUE, sep=";",dec=".", row.names=1, check.names=FALSE)
```

```header=TRUE``` : indicates that the file contains the names of the variables

```sep=";"``` : indicates the fields separator (usually ";" or "," for csv files)

```dec="."``` : indicates the decimal points used in the file

```row.names=1``` : indicates the column of the table which contains the row names

It is important to check that the import is well done

```{r}
summary(decathlon)
```

# Loading FactoMineR
```{r}
library(FactoMineR)
```

# PCA
```{r eval=FALSE}
res <- PCA(decathlon, quanti.sup=11:12, quali.sup=13, ncp=Inf)
```
```{r echo=FALSE}
res <- PCA(decathlon, quanti.sup=11:12, quali.sup=13,graph=FALSE,ncp=Inf)
plot(res,cex=.7)
```
```{r echo=FALSE}
plot(res,choi="var",cex=.7)
```
```{r}
res$eig # table of eigenvalues
# PCA with 8 dimensions kept in the results
res <- PCA(decathlon, quanti.sup=11:12, quali.sup=13, ncp=8, graph=FALSE)
```

\newpage

# Hierarchical ascendant clustering
```{r echo=FALSE}
res.hcpc <- HCPC(res, kk=Inf, min=3, max=10, consol=TRUE, graph=FALSE)
```

```{r eval=FALSE}
# Hierarchical ascendant clustering with consolidation
res.hcpc <- HCPC(res, kk=Inf, min=3, max=10, consol=TRUE)
```

```{r echo=FALSE}
plot(res.hcpc, choice="tree")
```
```{r echo=FALSE}
plot(res.hcpc, choice="3D.map")
```
```{r echo=FALSE}
plot(res.hcpc, choice="map",draw.tree=FALSE)
```

## Hierarchical tree on the PCA dimensions 3 and 4
```{r}
plot(res.hcpc, axes=3:4)
```

# Outputs
```{r}
names(res.hcpc)
res.hcpc$call$t
```
## The original data with a column called clust containing the partition
```{r}
res.hcpc$data.clust
```
## Description of the clusters by the variables
```{r}
res.hcpc$desc.var
```
## Description of the clusters by the axes
```{r}
res.hcpc$desc.axes
```
## Hierarchical tree on the PCA dimensions 1 and 3
```{r}
plot(res.hcpc,axes=c(1,3))
```

## Description of the clusters by the individuals
```{r}
res.hcpc$desc.ind
```
