-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDescriptiveStatistics_Gender-Continent-Education.R
289 lines (238 loc) · 12.4 KB
/
DescriptiveStatistics_Gender-Continent-Education.R
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
library(dplyr)
library(caret)
library(tidyr)
library(markdown)
library(pROC)
library(ggplot2)
library(stats)
library(car)
library(lmtest)
# _____________ PREPARATION OF GENDER MATRIX ______
gender_matrix$AI_Count <- 0
# Loop through each row of coded_renamed_columns_data
for (i in 1:nrow(coded_renamed_columns_data)) {
# Count the occurrences of "AI" in the row
ai_count <- sum(grepl("AI", coded_renamed_columns_data[i, ]))
# Store the count in gender_matrix$AI_Count
gender_matrix$AI_Count[i] <- ai_count
}
gender_matrix$Human_Count <- 0
# Loop through each row of coded_renamed_columns_data
for (i in 1:nrow(coded_renamed_columns_data)) {
# Count the occurrences of "Human" in the row
human_count <- sum(grepl("Human", coded_renamed_columns_data[i, ]))
# Store the count in gender_matrix$Human_Count
gender_matrix$Human_Count[i] <- human_count
}
gender_matrix <- matrix(ncol = 3, nrow = nrow(na_renamed_columns_data))
colnames(gender_matrix) <- c("Gender", "AI_Count", "Human_Count")
ai_correct_count <- 0
human_correct_count <- 0
# Loop through each row of the dataset
for (row_num in 1:nrow(na_renamed_columns_data)) {
ai_count <- 0
human_count <- 0
# Loop through columns that start with "AI"/"Human"
for (i in seq_along(na_renamed_columns_data)) {
if (startsWith(names(na_renamed_columns_data)[i], "AI")) {
ai_count <- ai_count + (na_renamed_columns_data[row_num, i] == "AI")
}
}
for (i in seq_along(na_renamed_columns_data)) {
if (startsWith(names(na_renamed_columns_data)[i], "Human")) {
human_count <- human_count + (na_renamed_columns_data[row_num, i] == "Human")
}
}
# Update the result matrix
gender_matrix[row_num, ] <- c(row_num, ai_count, human_count)
# Update the total count
ai_correct_count <- ai_correct_count + ai_count
human_correct_count <- human_correct_count + human_count
}
gender_matrix <- as.data.frame(gender_matrix)
gender_matrix$Gender <- na_renamed_columns_data[, 3]
# _____________ GENDER DESCRIPTIVE STATISTICS ______
average_ai_count_male <- mean(gender_matrix$AI_Count[gender_matrix$Gender == "Male"], na.rm = TRUE)
average_ai_count_male <- round(average_ai_count_male, 5)
print(average_ai_count_male)
average_ai_count_female <- mean(gender_matrix$AI_Count[gender_matrix$Gender == "Female"], na.rm = TRUE)
average_ai_count_female <- round(average_ai_count_female, 5)
print(average_ai_count_female)
## ___ CONTINENT MATRIX PREPARATION ___
continent_matrix <- matrix(ncol = 3, nrow = nrow(na_renamed_columns_data))
colnames(continent_matrix) <- c("Continent", "AI_Count", "Human_Count")
ai_correct_count <- 0
human_correct_count <- 0
# Loop through each row of the dataset
for (row_num in 1:nrow(na_renamed_columns_data)) {
ai_count <- 0
human_count <- 0
# Loop through columns that start with "AI"/"Human"
for (i in seq_along(na_renamed_columns_data)) {
if (startsWith(names(na_renamed_columns_data)[i], "AI")) {
ai_count <- ai_count + (na_renamed_columns_data[row_num, i] == "AI")
}
}
for (i in seq_along(na_renamed_columns_data)) {
if (startsWith(names(na_renamed_columns_data)[i], "Human")) {
human_count <- human_count + (na_renamed_columns_data[row_num, i] == "Human")
}
}
# Update the result matrix
continent_matrix[row_num, ] <- c(row_num, ai_count, human_count)
# Update the total count
ai_correct_count <- ai_correct_count + ai_count
human_correct_count <- human_correct_count + human_count
}
continent_matrix <- as.data.frame(continent_matrix)
continent_matrix$Continent <- na_renamed_columns_data[, 5]
# _____________ CONTINENT DESCRIPTIVE STATISTICS ______
north_america_avg <- mean(continent_matrix$AI_Count[continent_matrix$Continent == "North America"], na.rm = TRUE)
south_america_avg <- mean(continent_matrix$AI_Count[continent_matrix$Continent == "South America"], na.rm = TRUE)
europe_avg <- mean(continent_matrix$AI_Count[continent_matrix$Continent == "Europe"], na.rm = TRUE)
africa_avg <- mean(continent_matrix$AI_Count[continent_matrix$Continent == "Africa"], na.rm = TRUE)
asia_avg <- mean(continent_matrix$AI_Count[continent_matrix$Continent == "Asia"], na.rm = TRUE)
oceania_avg <- mean(continent_matrix$AI_Count[continent_matrix$Continent == "Oceania"], na.rm = TRUE)
cat("North America Average:", sprintf("%.5f", north_america_avg), "\n")
cat("South America Average:", sprintf("%.5f", south_america_avg), "\n")
cat("Europe Average:", sprintf("%.5f", europe_avg), "\n")
cat("Africa Average:", sprintf("%.5f", africa_avg), "\n")
cat("Asia Average:", sprintf("%.5f", asia_avg), "\n")
cat("Oceania Average:", sprintf("%.5f", oceania_avg), "\n")
north_america_percentage <- (north_america_avg / 5) * 100
south_america_percentage <- (south_america_avg / 5) * 100
europe_percentage <- (europe_avg / 5) * 100
africa_percentage <- (africa_avg / 5) * 100
asia_percentage <- (asia_avg / 5) * 100
oceania_percentage <- (oceania_avg / 5) * 100
cat("North America Percentage:", sprintf("%.2f%%", north_america_percentage), "\n")
cat("South America Percentage:", sprintf("%.2f%%", south_america_percentage), "\n")
cat("Europe Percentage:", sprintf("%.2f%%", europe_percentage), "\n")
cat("Africa Percentage:", sprintf("%.2f%%", africa_percentage), "\n")
cat("Asia Percentage:", sprintf("%.2f%%", asia_percentage), "\n")
cat("Oceania Percentage:", sprintf("%.2f%%", oceania_percentage), "\n")
north_america_avg <- mean(continent_matrix$Human_Count[continent_matrix$Continent == "North America"], na.rm = TRUE)
south_america_avg <- mean(continent_matrix$Human_Count[continent_matrix$Continent == "South America"], na.rm = TRUE)
europe_avg <- mean(continent_matrix$Human_Count[continent_matrix$Continent == "Europe"], na.rm = TRUE)
africa_avg <- mean(continent_matrix$Human_Count[continent_matrix$Continent == "Africa"], na.rm = TRUE)
asia_avg <- mean(continent_matrix$Human_Count[continent_matrix$Continent == "Asia"], na.rm = TRUE)
oceania_avg <- mean(continent_matrix$Human_Count[continent_matrix$Continent == "Oceania"], na.rm = TRUE)
print("HUMAN COUNT")
cat("North America Average:", sprintf("%.5f", north_america_avg), "\n")
cat("South America Average:", sprintf("%.5f", south_america_avg), "\n")
cat("Europe Average:", sprintf("%.5f", europe_avg), "\n")
cat("Africa Average:", sprintf("%.5f", africa_avg), "\n")
cat("Asia Average:", sprintf("%.5f", asia_avg), "\n")
cat("Oceania Average:", sprintf("%.5f", oceania_avg), "\n")
north_america_percentage <- (north_america_avg / 5) * 100
south_america_percentage <- (south_america_avg / 5) * 100
europe_percentage <- (europe_avg / 5) * 100
africa_percentage <- (africa_avg / 5) * 100
asia_percentage <- (asia_avg / 5) * 100
oceania_percentage <- (oceania_avg / 5) * 100
print("HUMAN COUNT")
cat("North America Percentage:", sprintf("%.2f%%", north_america_percentage), "\n")
cat("South America Percentage:", sprintf("%.2f%%", south_america_percentage), "\n")
cat("Europe Percentage:", sprintf("%.2f%%", europe_percentage), "\n")
cat("Africa Percentage:", sprintf("%.2f%%", africa_percentage), "\n")
cat("Asia Percentage:", sprintf("%.2f%%", asia_percentage), "\n")
cat("Oceania Percentage:", sprintf("%.2f%%", oceania_percentage), "\n")
## ___ EDUCATION MATRIX PREPARATION ___
education_matrix$AI_Count <- 0
# Loop through each row of coded_renamed_columns_data
# for (i in 1:nrow(coded_renamed_columns_data)) {
# # Count the occurrences of "AI" in the row
# ai_count <- sum(grepl("AI", coded_renamed_columns_data[i, ]))
#
# # Store the count in education_matrix$AI_Count
# education_matrix$AI_Count[i] <- ai_count
# }
for (i in 1:nrow(coded_renamed_columns_data)) {
# Identify columns starting with "AI"
ai_columns <- grep("^AI", names(coded_renamed_columns_data), value = TRUE)
# Count the occurrences of "AI" in the selected columns of the row
ai_count <- sum(coded_renamed_columns_data[i, ai_columns] == "AI")
# Store the count in education_matrix$AI_Count
education_matrix$AI_Count[i] <- ai_count
}
education_matrix$Human_Count <- 0
# Loop through each row of coded_renamed_columns_data
# for (i in 1:nrow(coded_renamed_columns_data)) {
# # Count the occurrences of "Human" in the row
# human_count <- sum(grepl("Human", coded_renamed_columns_data[i, ]))
#
# # Store the count in education_matrix$Human_Count
# education_matrix$Human_Count[i] <- human_count
# }
for (i in 1:nrow(coded_renamed_columns_data)) {
# Identify columns starting with "Human"
human_columns <- grep("^Human", names(coded_renamed_columns_data), value = TRUE)
# Count the occurrences of "Human" in the selected columns of the row
human_count <- sum(coded_renamed_columns_data[i, human_columns] == "Human")
# Store the count in education_matrix$AI_Count
education_matrix$Human_Count[i] <- human_count
}
education_matrix <- matrix(ncol = 3, nrow = nrow(na_renamed_columns_data))
colnames(education_matrix) <- c("Education", "AI_Count", "Human_Count")
ai_correct_count <- 0
human_correct_count <- 0
# Loop through each row of the dataset
for (row_num in 1:nrow(na_renamed_columns_data)) {
ai_count <- 0
human_count <- 0
# Loop through columns that start with "AI"/"Human"
for (i in seq_along(na_renamed_columns_data)) {
if (startsWith(names(na_renamed_columns_data)[i], "AI")) {
ai_count <- ai_count + (na_renamed_columns_data[row_num, i] == "AI")
}
}
for (i in seq_along(na_renamed_columns_data)) {
if (startsWith(names(na_renamed_columns_data)[i], "Human")) {
human_count <- human_count + (na_renamed_columns_data[row_num, i] == "Human")
}
}
# Update the result matrix
education_matrix[row_num, ] <- c(row_num, ai_count, human_count)
# Update the total count
ai_correct_count <- ai_correct_count + ai_count
human_correct_count <- human_correct_count + human_count
}
education_matrix <- as.data.frame(education_matrix)
education_matrix$Education <- na_renamed_columns_data[, 4]
# ____ DESCRIPTIVE STATISTICS EDUCATION _____
in_high_school <- subset(education_matrix, Education == "In high school")
in_college <- subset(education_matrix, Education == "In college/undergraduate")
none_of_the_above <- subset(education_matrix, Education == "None of the above")
in_middle_school <- subset(education_matrix, Education == "In middle school")
avg_in_high_school <- round(mean(in_high_school$AI_Count), 5)
avg_in_college <- round(mean(in_college$AI_Count), 5)
avg_none_of_the_above <- round(mean(none_of_the_above$AI_Count), 5)
avg_in_middle_school <- round(mean(in_middle_school$AI_Count), 5)
cat("Average AI_Count for 'In high school':", avg_in_high_school, "\n")
cat("Average AI_Count for 'In college/undergraduate':", avg_in_college, "\n")
cat("Average AI_Count for 'None of the above':", avg_none_of_the_above, "\n")
cat("Average AI_Count for 'In middle school':", avg_in_middle_school, "\n")
avg_in_high_school <- round(mean(in_high_school$AI_Count), 5) / 5 * 100
avg_in_college <- round(mean(in_college$AI_Count), 5) / 5 * 100
avg_none_of_the_above <- round(mean(none_of_the_above$AI_Count), 5) / 5 * 100
avg_in_middle_school <- round(mean(in_middle_school$AI_Count), 5) / 5 * 100
cat("Average AI_Count for 'In high school':", avg_in_high_school, "%\n")
cat("Average AI_Count for 'In college/undergraduate':", avg_in_college, "%\n")
cat("Average AI_Count for 'None of the above':", avg_none_of_the_above, "%\n")
cat("Average AI_Count for 'In middle school':", avg_in_middle_school, "%\n")
avg_in_high_school <- round(mean(in_high_school$Human_Count), 5)
avg_in_college <- round(mean(in_college$Human_Count), 5)
# avg_none_of_the_above <- round(mean(none_of_the_above$Human_Count), 5)
avg_in_middle_school <- round(mean(in_middle_school$Human_Count), 5)
cat("Average Human_Count for 'In high school':", avg_in_high_school, "\n")
cat("Average Human_Count for 'In college/undergraduate':", avg_in_college, "\n")
cat("Average Human_Count for 'None of the above':", avg_none_of_the_above, "\n")
cat("Average Human_Count for 'In middle school':", avg_in_middle_school, "\n")
avg_in_high_school <- round(mean(in_high_school$Human_Count), 5) / 5 * 100
avg_in_college <- round(mean(in_college$Human_Count), 5) / 5 * 100
# avg_none_of_the_above <- round(mean(none_of_the_above$Human_Count), 5) / 5 * 100
avg_in_middle_school <- round(mean(in_middle_school$Human_Count), 5) / 5 * 100
cat("Average Human_Count for 'In high school':", avg_in_high_school, "%\n")
cat("Average Human_Count for 'In college/undergraduate':", avg_in_college, "%\n")
# cat("Average Human_Count for 'None of the above':", avg_none_of_the_above, "%\n")
cat("Average Human_Count for 'In middle school':", avg_in_middle_school, "%\n")