```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Import data
Upload the Birth dataset on your computer

```{r eval=TRUE, echo=FALSE}
 setwd("C:/users/houee/AOBOX/MOOC_anado_GB/Données")
 Birth <- read.table("data_CA_birth.csv", header=TRUE,sep=";", row.names=1, 
                    check.names=FALSE)
```
```{r eval=FALSE, echo=TRUE}
 setwd("C:/users/houee")
 Birth <- read.table("data_CA_birth.csv", header=TRUE,sep=";", 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)

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

```check.names=FALSE``` : indicated that the names of the variables in the data frame are unchecked


It is important to check that the import is well done
```{r}
summary(Birth)
```

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


#  Correspondence Analysis

```{r}
res <- CA(Birth, row.sup=7:8, col.sup=9:10)
```

Outputs can be summarized with the function ```summary```.
```{r}
summary(res)          ## function summary.CA
```
## Simultaneous representation with a title and a smaller size for the labels
```{r}
plot(res, cex=0.7, title="Simultaneous representation")
```

# Description of the dimensions

```{r}
dimdesc(res)
```
# Graphs with several selections for rows and/or columns
## Plot with only the active rows and columns 
```{r}
plot(res, invisible=c("row.sup","col.sup"), cex=0.7, shadow=TRUE, title="Active elements")
```

```selectRow="cos2 0.7"``` : select the rows with a sufficiently good representation, with cos squared of at least 0.7 on the plane

and similarly for the columns 

```selectCol="cos2 0.7"``` 

```{r}
plot(res, shadow=TRUE, cex=0.7, selectRow="cos2 0.7", selectCol="cos2 0.7")
```
# select the four best represented rows and the three best represented columns
```{r}
plot(res, shadow=TRUE, cex=0.7, selectRow="cos2 4", selectCol="cos2 3")
```
# select rows and columns with the largest contribution to the plane's construction 
```{r}
plot(res, shadow=TRUE, cex=0.7, selectRow="contrib 4", selectCol="contrib 3")
```
# select by the categories name
```{r}
plot(res, shadow=TRUE, cex=0.7, selectRow=c("Mother -20"))
```


# Graph with dimensions 1 and 3
```{r}
plot(res, shadow=TRUE, cex=0.7, axes=c(1,3), title="Representation on dimensions 1-3")
```

# Clustering on the columns
```{r eval=FALSE, echo=TRUE}
res.hcpc <- HCPC(res, cluster.CA="columns")
```
```{r eval=TRUE, echo=FALSE}
res.hcpc <- HCPC(res, cluster.CA="columns",nb.clust=3)
```

