-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjet1_mat2775.R
More file actions
347 lines (242 loc) · 13.2 KB
/
Projet1_mat2775.R
File metadata and controls
347 lines (242 loc) · 13.2 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
### ETAPE 2
##importation des donnees
data <- read.csv("/Users/keliane/Downloads/StudentDepressionDataset.csv",header=T)
head(data,15)
str(data)
print(dim(data))
## nettoyage des donnes
sum(is.na(data))
data_clean <- na.omit(data)
#Convertir variables categorielles
ID_fct <- factor(data$id)
gender_fct <- factor(data$Gender)
city_fct <- factor(data$City)
profession_fct <- factor(data$Profession)
Sleep_duration_fct <- factor(data$Sleep.Duration)
dietary_habits_fct <- factor(data$Dietary.Habits)
family_history_fct <- factor(data$Family.History.of.Mental.Illness)
suicidal_thoughts_fct <- factor(data$Have.you.ever.had.suicidal.thoughts)
degree_fct <- factor(data$Degree)
depression_status_fct <- factor(data$Depression)
ID_fct
gender_fct
city_fct
profession_fct
Sleep_duration_fct
dietary_habits_fct
family_history_fct
suicidal_thoughts_fct
degree_fct
depression_status_fct
### ETAPE 3 : Analyse et exploration des donnees
##Statistiques Descriptives
#colonne Age
mean_age <- mean(data$Age, na.rm = TRUE)
median_age <- median(data$Age, na.rm = TRUE)
variance_age <- var(data$Age, na.rm = TRUE)
sd_age <- sd(data$Age, na.rm = TRUE)
min_age <- min(data$Age, na.rm = TRUE)
max_age <- max(data$Age, na.rm = TRUE)
quartiles_age <- quantile(data$Age, probs = c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE)
summary_stats_age <- summary(data$Age)
print(summary_stats_age)
#colonne CGPA
mean_cgpa <- mean(data$CGPA, na.rm = TRUE)
median_CGPA <- median(data$CGPA, na.rm = TRUE)
variance_CGPA <- var(data$CGPA, na.rm = TRUE)
sd_CGPA <- sd(data$CGPA, na.rm = TRUE)
min_CGPA <- min(data$CGPA, na.rm = TRUE)
max_CGPA <- max(data$CGPA, na.rm = TRUE)
quartiles_CGPA <- quantile(data$CGPA, probs = c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE)
summary_stats_CGPA <- summary(data$CGPA)
print(summary_stats_CGPA)
#colonne Study Satisfaction
mean_Study_satisfaction <- mean(data$Study.Satisfaction, na.rm = TRUE)
median_Study_satisfaction <- median(data$Study.Satisfaction, na.rm = TRUE)
variance_Study_satisfaction <- var(data$Study.Satisfaction, na.rm = TRUE)
sd_Study_satisfaction <- sd(data$Study.Satisfaction, na.rm = TRUE)
min_Study_satisfaction <- min(data$Study.Satisfaction, na.rm = TRUE)
max_Study_satisfaction <- max(data$Study.Satisfaction, na.rm = TRUE)
quartiles_Study_satisfaction <- quantile(data$Study.Satisfaction, probs = c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE)
summary_stats_Study_satisfaction <- summary(data$Study.Satisfaction)
print(summary_stats_Study_satisfaction)
#colonne Job Satisfaction
mean_Job_Satisfaction <- mean(data$Job.Satisfaction, na.rm = TRUE)
median_Job_Satisfaction <- median(data$Job.Satisfaction, na.rm = TRUE)
variance_Job_Satisfaction <- var(data$Job.Satisfaction, na.rm = TRUE)
sd_Job_Satisfaction <- sd(data$Job.Satisfaction, na.rm = TRUE)
min_Job_Satisfaction <- min(data$Job.Satisfaction, na.rm = TRUE)
max_Job_Satisfaction <- max(data$Job.Satisfaction, na.rm = TRUE)
quartiles_Job_Satisfaction <- quantile(data$Job.Satisfaction, probs = c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE)
summary_stats_Job_Satisfaction <- summary(data$Job.Satisfaction)
print(summary_stats_Job_Satisfaction)
#colonne Academic Pressure
mean_Academic_Pressure <- mean(data$Academic.Pressure, na.rm = TRUE)
median_Academic_Pressure <- median(data$Academic.Pressure, na.rm = TRUE)
variance_Academic_Pressure <- var(data$Academic.Pressure, na.rm = TRUE)
sd_Academic_Pressure <- sd(data$Academic.Pressure, na.rm = TRUE)
min_Academic_Pressure <- min(data$Academic.Pressure, na.rm = TRUE)
max_Academic_Pressure <- max(data$Academic.Pressure, na.rm = TRUE)
quartiles_Academic_Pressure <- quantile(data$Academic.Pressure, probs = c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE)
summary_stats_Academic_Pressure <- summary(data$Academic.Pressure)
print(summary_stats_Academic_Pressure)
#colonne Work Pressure
mean_Work_Pressure <- mean(data$Work.Pressure, na.rm = TRUE)
median_Work_Pressure <- median(data$Work.Pressure, na.rm = TRUE)
variance_Work_Pressure <- var(data$Work.Pressure, na.rm = TRUE)
sd_Work_Pressure <- sd(data$Work.Pressure, na.rm = TRUE)
min_Work_Pressure <- min(data$Work.Pressure, na.rm = TRUE)
max_Work_Pressure <- max(data$Work.Pressure, na.rm = TRUE)
quartiles_Work_Pressure <- quantile(data$Work.Pressure, probs = c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE)
summary_stats_Work_Pressure <- summary(data$Work.Pressure)
print(summary_stats_Work_Pressure)
#colonne Financial Stress
mean_Financial_stress <- mean(data$Financial.Stress, na.rm = TRUE)
median_Financial_stress <- median(data$Financial.Stress, na.rm = TRUE)
variance_Financial_stress <- var(data$Financial.Stress, na.rm = TRUE)
sd_Financial_stress <- sd(data$Financial.Stress, na.rm = TRUE)
min_Financial_stress <- min(data$Financial.Stress, na.rm = TRUE)
max_Financial_stress <- max(data$Financial.Stress, na.rm = TRUE)
quartiles_Financial_stress <- quantile(data$Financial.Stress, probs = c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE)
summary_stats_Financial_stress <- summary(data$Financial.Stress)
print(summary_stats_Financial_stress)
#correlation
correlation_matrix <- cor(data[, c("Age", "CGPA", "Study.Satisfaction", "Job.Satisfaction", "Academic.Pressure", "Work.Pressure", "Financial.Stress")], use = "complete.obs")
print(correlation_matrix)
## Visualisation
#Données catégorielles : Diagrammes en barres (geom_bar())
library(ggplot2)
ggplot(data, aes(x = gender_fct)) +
geom_bar(fill = "blue") +
labs(title = "Distribution of Gender", x = "Gender", y = "Count")
ggplot(data, aes(x = city_fct)) +
geom_bar(fill = "green") +
labs(title = "Distribution by City", x = "City", y = "Count") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) # Rotation des labels si nécessaire
ggplot(data, aes(x = profession_fct)) +
geom_bar(fill = "red") +
labs(title = "Distribution of Profession", x = "Profession", y = "Count")
# Pour Sleep Duration
ggplot(data, aes(x = Sleep_duration_fct)) +
geom_bar(fill = "purple") +
labs(title = "Distribution of Sleep Duration", x = "Sleep Duration", y = "Count")
# Pour Dietary Habits
ggplot(data, aes(x = dietary_habits_fct)) +
geom_bar(fill = "orange") +
labs(title = "Distribution of Dietary Habits", x = "Dietary Habits", y = "Count")
# Pour Family History of Mental Illness
ggplot(data, aes(x = family_history_fct)) +
geom_bar(fill = "cyan") +
labs(title = "Family History of Mental Illness", x = "Family History", y = "Count")
# Pour Suicidal Thoughts
ggplot(data, aes(x = suicidal_thoughts_fct)) +
geom_bar(fill = "magenta") +
labs(title = "Have you ever had suicidal thoughts?", x = "Suicidal Thoughts", y = "Count")
# Pour Degree
ggplot(data, aes(x = degree_fct)) +
geom_bar(fill = "yellow") +
labs(title = "Distribution of Degrees", x = "Degree", y = "Count")
# Pour Depression Status
ggplot(data, aes(x = depression_status_fct)) +
geom_bar(fill = "lightblue") +
labs(title = "Depression Status", x = "Depression", y = "Count")
# Données continues : Histogrammes (geom_histogram())
library(ggplot2)
# Histogramme pour la colonne 'Age'
ggplot(data, aes(x = Age)) +
geom_histogram(bins = 30, fill = "cornflowerblue", color = "black") +
labs(title = "Histogram of Age", x = "Age", y = "Frequency")
# Histogramme pour la colonne 'CGPA'
ggplot(data, aes(x = CGPA)) +
geom_histogram(bins = 30, fill = "steelblue", color = "black") +
labs(title = "Histogram of CGPA", x = "CGPA", y = "Frequency")
# Histogramme pour la colonne 'Study Satisfaction'
ggplot(data, aes(x = Study.Satisfaction)) +
geom_histogram(bins = 30, fill = "lightblue", color = "black") +
labs(title = "Histogram of Study Satisfaction", x = "Study Satisfaction", y = "Frequency")
# Histogramme pour la colonne 'Job Satisfaction'
ggplot(data, aes(x = Job.Satisfaction)) +
geom_histogram(bins = 30, fill = "gray", color = "black") +
labs(title = "Histogram of Job Satisfaction", x = "Job Satisfaction", y = "Frequency")
# Histogramme pour la colonne 'Academic Pressure'
ggplot(data, aes(x = Academic.Pressure)) +
geom_histogram(bins = 30, fill = "darkblue", color = "black") +
labs(title = "Histogram of Academic Pressure", x = "Academic Pressure", y = "Frequency")
# Histogramme pour la colonne 'Work Pressure'
ggplot(data, aes(x = Work.Pressure)) +
geom_histogram(bins = 30, fill = "purple", color = "black") +
labs(title = "Histogram of Work Pressure", x = "Work Pressure", y = "Frequency")
# Histogramme pour la colonne 'Financial Stress'
ggplot(data, aes(x = Financial.Stress)) +
geom_histogram(bins = 30, fill = "red", color = "black") +
labs(title = "Histogram of Financial Stress", x = "Financial Stress", y = "Frequency")
#Relations entre variables : Nuages de points (geom_point())
data_frame <- data.frame(Variable1 = data$Age, Variable2 = data$CGPA)
ggplot(data_frame, aes(x = Variable1, y = Variable2)) +
geom_point(color = "darkorange") +
theme_minimal() +
labs(title = " Age vs CGPA", x = "Variable 1", y = "Variable 2")
data_frame <- data.frame(Variable3 = data$Study.Satisfaction, Variable4 = data$Job.Satisfaction)
ggplot(data_frame, aes(x = Variable3, y = Variable4)) +
geom_point(color = "darkorange") +
theme_minimal() +
labs(title = " Study Satisfaction vs Job Satisfaction", x = "Variable 3", y = "Variable 4")
data_frame <- data.frame(Variable5 = data$Academic.Pressure, Variable6 = data$Work.Pressure)
ggplot(data_frame, aes(x = Variable5, y = Variable6)) +
geom_point(color = "darkorange") +
theme_minimal() +
labs(title = " Academic Pressure vs Work Pressure", x = "Variable 5", y = "Variable 6")
data_frame <- data.frame(Variable5 = data$Academic.Pressure, Variable7 = data$Financial.Stress, Variable4=data$Job.Satisfaction)
ggplot(data_frame, aes(x = Variable5, y = Variable7, color = factor(Study.Satisfaction), size =Variable4)) +
geom_point(color = "darkorange") +
theme_minimal() +
scale_color_manual(values = c("blue", "green", "red", "purple")) + # Exemple avec des couleurs prédéfinies
labs(title = "Age vs CGPA with Study Satisfaction and Job Satisfaction",
x = "Variable 5",
y = "Variable 7",
color = "Study Satisfaction",
size = "Job Satisfaction")
labs(title = " Academic Pressure vs Financial Stress", x = "Variable 5", y = "Variable 7")
#Détection des valeurs aberrantes : Boîtes à moustaches (geom_boxplot())
data_frame <- data.frame(Variable1=data$Age, Variable2=data$CGPA, Variable3=data$Study.Satisfaction, Variable4=data$Job.Satisfaction, Variable5 = data$Academic.Pressure, Variable6 = data$Financial.Stress, Variable7=data$Work.Pressure)
boxplot(data_frame, main="Données aléatoires | Graphiques en boîte comparatifs", ylab="Fréquence",
outpch=18, outcex=1.7, outcol="red",
col="lightblue")
### ETAPE 4 : ANALYSE STATISTIQUE
## Tendances centrales
#Moyenne et Mediane
mean_age <- mean(data$Age, na.rm = TRUE)
median_age <- median(data$Age, na.rm = TRUE)
mean_CGPA <- mean(data$CGPA, na.rm = TRUE)
median_CGPA <- median(data$CGPA, na.rm = TRUE)
mean_Study_satisfaction <- mean(data$Study.Satisfaction, na.rm = TRUE)
median_Study_satisfaction <- median(data$Study.Satisfaction, na.rm = TRUE)
mean_Job_Satisfaction <- mean(data$Job.Satisfaction, na.rm = TRUE)
median_Job_Satisfaction <- median(data$Job.Satisfaction, na.rm = TRUE)
mean_Academic_Pressure <- mean(data$Academic.Pressure, na.rm = TRUE)
median_Academic_Pressure <- median(data$Academic.Pressure, na.rm = TRUE)
mean_Work_Pressure <- mean(data$Work.Pressure, na.rm = TRUE)
median_Work_Pressure <- median(data$Work.Pressure, na.rm = TRUE)
mean_Financial_stress <- mean(data$Financial.Stress, na.rm = TRUE)
median_Financial_stress <- median(data$Financial.Stress, na.rm = TRUE)
#Variance et ecart type
variance_values <- sapply(data[c("Age", "CGPA", "Study.Satisfaction", "Job.Satisfaction", "Academic.Pressure", "Work.Pressure", "Financial.Stress")], var, na.rm = TRUE)
print(variance_values)
sd_values <- sapply(data[c("Age", "CGPA", "Study.Satisfaction", "Job.Satisfaction", "Academic.Pressure", "Work.Pressure", "Financial.Stress")], sd, na.rm = TRUE)
print(sd_values)
#Plage Interquartile
iqr_values <- sapply(data[c("Age", "CGPA", "Study.Satisfaction","Job.Satisfaction","Academic.Pressure","Work.Pressure","Financial.Stress")], IQR, na.rm = TRUE)
print(iqr_values)
#Valeurs aberrantes
variables <- c("Age", "CGPA", "Study.Satisfaction", "Job.Satisfaction", "Academic.Pressure", "Work.Pressure", "Financial.Stress")
outliers <- sapply(data[variables], function(x) boxplot.stats(x)$out)
print(outliers)
## Analyse de la symétrie et de l’asymétrie
library(e1071)
skewness_values <- sapply(data[c("Age", "CGPA", "Study.Satisfaction", "Job.Satisfaction", "Academic.Pressure", "Work.Pressure", "Financial.Stress")], skewness)
print(skewness_values)
## *COMMENTAIRES SUR RESULTATS* Les variables Age, CGPA, Study.Satisfaction, et Academic.Pressure ont des valeurs de skewness très proches de zéro, ce qui indique que leurs distributions sont relativement symétriques.
## Analyse des correlations
correlation_matrix <- cor(data[c("Age", "CGPA", "Study.Satisfaction", "Job.Satisfaction", "Academic.Pressure", "Work.Pressure", "Financial.Stress")], use = "complete.obs")
print(correlation_matrix)
## Visualisation avec nuage de points