-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting_code.R
More file actions
57 lines (44 loc) · 2.22 KB
/
sorting_code.R
File metadata and controls
57 lines (44 loc) · 2.22 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
library(rtweet, quietly=TRUE, warn.conflicts=FALSE)
library(dplyr, quietly=TRUE, warn.conflicts=FALSE)
# This is written on the assumption that R users have set the working directory
# to the folder containing the csv file, know how to use the rtweet package,
# have created an authorisation token called twitter_token,
# and can change the user part of the next line
args = commandArgs(trailingOnly=TRUE)
if (length(args)==0) {
stop("Twitter user required as an argument!", call.=FALSE)
} else {
user = args[1]
}
evidence <- get_timeline(user=user, n=1000)
#twitter_token <- "8EfMPFhSkaGNm0rpQIe4YfsZC"
#evidence <- get_timeline(user=user, n=1000, token=twitter_token)
compare_with <- read.csv("corpus_people.csv") %>% mutate(isSortee = FALSE)
candidate <- evidence %>%
mutate(has_external_links = !is.na(urls_url),
has_reply = !is.na(reply_to_screen_name),
has_reply_to_self = screen_name == reply_to_screen_name & !is.na(reply_to_screen_name),
has_retweet = !is.na(quoted_status_id) | !is.na(retweet_status_id)) %>%
group_by(screen_name) %>%
summarise(
slyth = sum(has_reply & !has_reply_to_self) / n(),
huffl = sum(has_retweet) / n(),
raven = sum(has_external_links & !has_retweet) / n(),
griff = (n() - sum(has_reply |
has_retweet |
has_external_links |
has_reply_to_self)
) / n()
) %>% mutate(isSortee = TRUE)
slyth <- bind_rows(compare_with, candidate) %>% arrange(slyth) %>% select(slyth,isSortee)
Sly <- round(which(slyth$isSortee)/nrow(slyth),3)
griff <- bind_rows(compare_with, candidate) %>% arrange(griff) %>% select(griff,isSortee)
Gry <- round(which(griff$isSortee)/nrow(griff),3)
huffl <- bind_rows(compare_with, candidate) %>% arrange(huffl) %>% select(huffl,isSortee)
Huf <- round(which(huffl$isSortee)/nrow(huffl),3)
raven <- bind_rows(compare_with, candidate) %>% arrange(raven) %>% select(raven,isSortee)
Rav <- round(which(raven$isSortee)/nrow(raven),3)
result <- data.frame(House = c("Slytherin", "Gryffindor", "Hufflepuff", "Ravenclaw"),
Proportion = c(Sly, Gry, Huf, Rav)) %>% arrange(-Proportion) %>%
mutate(Score = round(100 * Proportion/ sum(Proportion),1))
result