Repository navigation
Expand file tree
/
Copy pathANOVA-Education.R
More file actions
98 lines (75 loc) · 3.07 KB
/
Copy pathANOVA-Education.R
File metadata and controls
98 lines (75 loc) · 3.07 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
library(dplyr)
library(caret)
library(tidyr)
library(markdown)
library(pROC)
library(ggplot2)
library(stats)
library(car)
library(lmtest)
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]
ai_education_result <- aov(AI_Count ~ Education, data = education_matrix)
summary(ai_education_result)
human_education_result <- aov(Human_Count ~ Education, data = education_matrix)
summary(human_education_result)
write.csv(education_matrix, "tables/education-vs-correct.csv", row.names = FALSE)