-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathACP_début.qmd
139 lines (116 loc) · 3.65 KB
/
ACP_début.qmd
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
title: "ACP"
format: html
editor: visual
---
## Quarto
**Etape1: chargement et description des données**
```{r}
# importer les données
data = read.table("decathlon.txt", header = T, sep = "\t")
head(data)
```
You can add options to executable code like this
```{r}
#| echo: false
## renommer les colonnes
colnames(data) = c(
"Course100m",
"SautEnLongueur",
"lancerDePoids",
"SautEnHauteur",
"Course400m",
"course110mHaies",
"LancerDeDisque",
"SautALaPerche",
"LancerDeJavelot",
"Course1500m",
"Classement",
"Points",
"Compétition"
)
head(data)
```
```{r}
summary(data)
```
Analyse des valeurs manquantes
```{r}
# fonction pour calculer la proportion des valeurs manquantes
proportion_valeurs_manquantes = function(data) {
# calcul du nombre de valeurs manquantes par colonne
nb_valeurs_manquantes = sapply(data, function(x) sum(is.na(x)))
# calcul la proportion de valeurs manquantes
proportion_manquantes = nb_valeurs_manquantes/nrow(data)
# créer un data frame pour le résultat
resultat = data.frame(nobre=nb_valeurs_manquantes,proportion=proportion_manquantes)
return(resultat)
}
resultat = proportion_valeurs_manquantes(data)
resultat
```
```{r}
# package pour travailler les val manquantes*
# charger le package VIM
install.packages("VIM")
library(VIM)
# utilisation de la fonction aggr() pour visualiser les données manquantes
aggr(data, col =c("blue", "yellow"), numbers=TRUE, sortVars=TRUE,
labels=names(data), cex.axis=0.7, gap=3, ylab=c("histogramme of missing data", "pattern"))
```
Description des variables quantitatives
```{r}
# charger le ggplot2
library(ggplot2)
# identifier les cols contenant des variables quantiatives
var_quantitatives = sapply(data, is.numeric)
# créer un histo pour chaque variable quantitative
for(var in names(data)[var_quantitatives]) {
print(ggplot(data, aes_string(x=var))+
geom_histogram(bins=30, fill="blue", cotor="black")+
theme_minimal()+
labs(title = paste("histogramme de", var), x = var, y = "fréquence"))
}
```
```{r}
## créer des boxplot
for(var in names(data)[var_quantitatives]) {
print(ggplot(data, aes_string(x=factor(1), y=var))+
geom_boxplot(bins=30, fill="blue", cotor="black")+
theme_minimal()+
labs(title = paste("boxplot de", var), x = "", y = "var"))
}
```
```{r}
# Fonction pour créer un barplot en proportions
creer_barplot_proportion <- function(data, column_name) {
# Calculer les proportions
proportions <- data %>%
count(.data[[column_name]]) %>%
mutate(Proportion = n / sum(n))
# Créer le barplot
ggplot(proportions, aes_string(x = column_name, y = "Proportion", fill = column_name)) +
geom_bar(stat = "identity") +
scale_y_continuous(labels = scales::percent_format()) +
labs(x = column_name, y = "Proportion (%)") +
theme_minimal()
}
# Créer un barplot pour la variable "Compétition"
creer_barplot_proportion(data, "Compétition")
```
```{r}
# Relation bivariées
library(corrplot)
donnees_quantiative = data[,var_quantitatives]
# calcul de la matrice de corrélation
matrice_correlation = cor(donnees_quantiative)
## créér un heatmap de corrélation
corrplot(matrice_correlation, method = "color", type = "upper", order = "hclust",
tl.col = "black", tl.srt = 45,
addCoef.col = "black", # Couleur des coefficients
cl.pos = "n", # Position de la légende de couleur
cl.cex = 1.2, # Taille de la légende de couleur
addCoefasPercent = TRUE, # Afficher les coefficients en pourcentage
number.cex = 0.8) # Taille des chiffres des coefficients
```
The `echo: false` option disables the printing of code (only output is displayed).