-
Notifications
You must be signed in to change notification settings - Fork 0
/
partisan_lean_analyses.R
112 lines (94 loc) · 4 KB
/
partisan_lean_analyses.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
#########################################
# Project: Mila Datasets #
# Coded by: Gabrielle Péloquin-Skulski #
# Date last edited: July 30, 2024. #
#########################################
rm(list=ls())
# Set working directory
if(Sys.info()["user"] == "gabriellepeloquinskulski"){
setwd("~/Dropbox (MIT)/mila_datasets")
}else{
setwd("")
}
# Packages
library(dplyr)
library(readr)
dat <- read.csv("partisan_lean.csv") |>
filter((veracity == 1 | veracity == 2) &
(X0 %in% c("A", "B", "C", "D")) &
!startsWith(source_dataset, "1864.json" ) &
!source_dataset=="{}" &
!source_dataset=="fakecovid") |>
mutate(party_lean = X0) |>
select(source_dataset, claim, veracity, party_lean)
true <- dat |>
filter(veracity==1)
false <- dat |>
filter(veracity==2)
# Create Table that shows percent of true headlines
# Calculate percentages for XO by source_dataset and veracity
result_true <- true |>
group_by(source_dataset) |>
summarise(
total = n(),
party_lean_A_count = sum(party_lean == "A", na.rm = TRUE),
party_lean_B_count = sum(party_lean == "B", na.rm = TRUE),
party_lean_C_count = sum(party_lean == "C", na.rm = TRUE),
party_lean_D_count = sum(party_lean == "D", na.rm = TRUE)
) |>
mutate(
party_lean_A_percent = round((party_lean_A_count / total) * 100, 2),
party_lean_B_percent = round((party_lean_B_count / total) * 100, 2),
party_lean_C_percent = round((party_lean_C_count / total) * 100, 2),
party_lean_D_percent = round((party_lean_D_count / total) * 100, 2)
) |>
select(source_dataset, party_lean_A_percent, party_lean_B_percent, party_lean_C_percent, party_lean_D_percent)
result_true_all <- true |>
summarise(
total = n(),
party_lean_A_count = sum(party_lean == "A", na.rm = TRUE),
party_lean_B_count = sum(party_lean == "B", na.rm = TRUE),
party_lean_C_count = sum(party_lean == "C", na.rm = TRUE),
party_lean_D_count = sum(party_lean == "D", na.rm = TRUE)
) |>
mutate(
party_lean_A_percent = round((party_lean_A_count / total) * 100, 2),
party_lean_B_percent = round((party_lean_B_count / total) * 100, 2),
party_lean_C_percent = round((party_lean_C_count / total) * 100, 2),
party_lean_D_percent = round((party_lean_D_count / total) * 100, 2)
) |>
select(party_lean_A_percent, party_lean_B_percent, party_lean_C_percent, party_lean_D_percent)
result_false <- false |>
group_by(source_dataset) |>
summarise(
total = n(),
party_lean_A_count = sum(party_lean == "A", na.rm = TRUE),
party_lean_B_count = sum(party_lean == "B", na.rm = TRUE),
party_lean_C_count = sum(party_lean == "C", na.rm = TRUE),
party_lean_D_count = sum(party_lean == "D", na.rm = TRUE)
) |>
mutate(
party_lean_A_percent = round((party_lean_A_count / total) * 100, 2),
party_lean_B_percent = round((party_lean_B_count / total) * 100, 2),
party_lean_C_percent = round((party_lean_C_count / total) * 100, 2),
party_lean_D_percent = round((party_lean_D_count / total) * 100, 2)
) |>
select(source_dataset, party_lean_A_percent, party_lean_B_percent, party_lean_C_percent, party_lean_D_percent)
result_false_all <- false |>
summarise(
total = n(),
party_lean_A_count = sum(party_lean == "A", na.rm = TRUE),
party_lean_B_count = sum(party_lean == "B", na.rm = TRUE),
party_lean_C_count = sum(party_lean == "C", na.rm = TRUE),
party_lean_D_count = sum(party_lean == "D", na.rm = TRUE)
) |>
mutate(
party_lean_A_percent = round((party_lean_A_count / total) * 100, 2),
party_lean_B_percent = round((party_lean_B_count / total) * 100, 2),
party_lean_C_percent = round((party_lean_C_count / total) * 100, 2),
party_lean_D_percent = round((party_lean_D_count / total) * 100, 2)
) |>
select(party_lean_A_percent, party_lean_B_percent, party_lean_C_percent, party_lean_D_percent)
# Export result_true to a CSV file
write.csv(result_true, "result_true.csv", row.names = FALSE)
write.csv(result_false, "result_false.csv", row.names = FALSE)