update to latest version

This commit is contained in:
2015-07-07 16:34:44 +03:00
parent e009060084
commit 5d1877aa41
7 changed files with 582 additions and 522 deletions
+479 -479
View File
@@ -1,281 +1,175 @@
load(file = "tweets_untagged.RData") xlab("Zeitraum") + ylab("Tweets pro Tag") +
setwd("~/Dokumente/Uni/Aktuell/BA-Arbeit/uni-ba-issuecomp") scale_colour_discrete(name = "Tweets", labels = c("Gesamt", "Allgemein", "Sensation")) +
results_files <- "matched-ids/all.csv" theme(legend.title = element_text(size=14)) +
load(file = "tweets_untagged.RData") theme(legend.text = element_text(size=12)) +
View(issues) theme(axis.text = element_text(size = 18))
issues <- data.frame(date = drange) g_perday
issuelist <- readLines("issues.xml") g_perday <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) +
issuelist <- str_replace_all(string = issuelist, pattern = ".*<!-- .+ -->", "") geom_line()+
issuelist <- xmlToList(issuelist) geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
issueheads <- names(issuelist) xlab("Zeitraum") + ylab("Tweets pro Tag") +
issues[issueheads] <- 0 scale_colour_discrete(name = "Tweets", labels = c("Gesamt", "Allgemein", "Sensation")) +
tweets$issue <- "" theme(legend.title = element_text(size=14)) +
tweets$tags <- "" theme(legend.text = element_text(size=12)) +
View(results) theme(axis.title = element_text(size = 18))
rm(r, results_temp, results_files) g_perday
results <- results[!duplicated(results), ] g_perday <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) +
names(results) <- c("date", "id_str", "issue", "tags") geom_line()+
results <- results[order(results$id_str), ] geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
row.names(results) <- NULL xlab("Zeitraum") + ylab("Tweets pro Tag") +
for(r in 1:nrow(results)) { scale_colour_discrete(name = "Tweets", labels = c("Gesamt", "Allgemein", "Sensation")) +
curdate <- as.character(results$date[r]) theme(legend.title = element_text(size=14)) +
curid <- as.character(results$id_str[r]) theme(legend.text = element_text(size=12)) +
curissue <- as.character(results$issue[r]) theme(axis.title = element_text(size = 12))
curtag <- as.character(results$tags[r]) g_perday
cat("Sorting match", r, "of 53383 \n") g_perday <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) +
# Update issue counter (date and issue) geom_line()+
issues[issues[, "date"] == curdate, curissue] <- issues[issues[, "date"] == curdate, curissue] + 1 geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
# Update tweet dataframe (id, issue and tags) xlab("Zeitraum") + ylab("Tweets pro Tag") +
oldissue <- tweets[tweets[, "id_str"] == curid, "issue"] scale_colour_discrete(name = "Tweets", labels = c("Gesamt", "Allgemein", "Sensation")) +
tweets[tweets[, "id_str"] == curid, "issue"] <- str_c(oldissue, curissue, ",") theme(legend.title = element_text(size=14)) +
oldtag <- tweets[tweets[, "id_str"] == curid, "tags"] theme(legend.text = element_text(size=12)) +
tweets[tweets[, "id_str"] == curid, "tags"] <- str_c(oldtag, curtag, ",") theme(axis.title = element_text(size = 13))
} g_perday
curdate g_perday <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) +
curissue geom_line()+
issues[issues[, "date"] == curdate, curissue] geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
issueheads xlab("Zeitraum") + ylab("Tweets pro Tag") +
issuelist <- readLines("issues-v2.xml") scale_colour_discrete(name = "Tweets", labels = c("Gesamt", "Allgemein", "Sensation")) +
issues <- data.frame(date = drange) theme(legend.title = element_text(size=14, face="plain")) +
issuelist <- readLines("issues-v2.xml") theme(legend.text = element_text(size=12)) +
issuelist <- str_replace_all(string = issuelist, pattern = ".*<!-- .+ -->", "") theme(axis.title = element_text(size = 13))
issuelist <- xmlToList(issuelist) g_perday
issueheads <- names(issuelist) g_perday <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) +
issues[issueheads] <- 0 geom_line()+
tweets$issue <- "" geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
tweets$tags <- "" xlab("Zeitraum") + ylab("Tweets pro Tag") +
for(r in 1:nrow(results)) { scale_colour_discrete(name = "Tweets", labels = c("Gesamt", "Allgemein", "Sensation")) +
curdate <- as.character(results$date[r]) theme(legend.title = element_text(size=14)) +
curid <- as.character(results$id_str[r]) theme(legend.text = element_text(size=12)) +
curissue <- as.character(results$issue[r]) theme(axis.title = element_text(size = 13))
curtag <- as.character(results$tags[r]) g_perday
cat("Sorting match", r, "of 53383 \n") g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
# Update issue counter (date and issue) geom_line() +
issues[issues[, "date"] == curdate, curissue] <- issues[issues[, "date"] == curdate, curissue] + 1 geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
# Update tweet dataframe (id, issue and tags) xlab("Zeitraum") + ylab("Entropie") +
oldissue <- tweets[tweets[, "id_str"] == curid, "issue"] scale_colour_discrete(name = "", labels = "Entropie") +
tweets[tweets[, "id_str"] == curid, "issue"] <- str_c(oldissue, curissue, ",") theme(legend.title = element_text(size=14)) +
oldtag <- tweets[tweets[, "id_str"] == curid, "tags"] theme(legend.text = element_text(size=12)) +
tweets[tweets[, "id_str"] == curid, "tags"] <- str_c(oldtag, curtag, ",") theme(axis.title = element_text(size = 13))
} g_entrop
results[33170,] g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
results[33171,] geom_line() +
results$date[33170] geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
results$date[33170] <- "2014-08-21" xlab("Zeitraum") + ylab("Entropie") +
for(r in 33170:nrow(results)) { scale_colour_discrete(name = "", labels = "Entropie")# +
curdate <- as.character(results$date[r]) # theme(legend.title = element_text(size=14)) +
curid <- as.character(results$id_str[r]) # theme(legend.text = element_text(size=12)) +
curissue <- as.character(results$issue[r]) # theme(axis.title = element_text(size = 13))
curtag <- as.character(results$tags[r]) g_entrop
cat("Sorting match", r, "of 53383 \n") detach("package:ggplot2", unload=TRUE)
# Update issue counter (date and issue) library("ggplot2", lib.loc="/usr/lib/R/site-library")
issues[issues[, "date"] == curdate, curissue] <- issues[issues[, "date"] == curdate, curissue] + 1 g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
# Update tweet dataframe (id, issue and tags) geom_line() +
oldissue <- tweets[tweets[, "id_str"] == curid, "issue"] geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
tweets[tweets[, "id_str"] == curid, "issue"] <- str_c(oldissue, curissue, ",") xlab("Zeitraum") + ylab("Entropie") +
oldtag <- tweets[tweets[, "id_str"] == curid, "tags"] scale_colour_discrete(name = "", labels = "Entropie")# +
tweets[tweets[, "id_str"] == curid, "tags"] <- str_c(oldtag, curtag, ",") # theme(legend.title = element_text(size=14)) +
} # theme(legend.text = element_text(size=12)) +
save(tweets, file="tweets_tagged.RData") # theme(axis.title = element_text(size = 13))
write.csv(tweets, file="tweets.csv") g_entrop
save(issues, file="issues.RData") theme()
require(stringr) require(stringr)
require(reshape2) require(reshape2)
require(ggplot2) require(ggplot2)
require(vars) require(vars)
drop_s <- which(str_detect(names(issues), "^s")) theme()
drop_i <- which(str_detect(names(issues), "^i")) g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
issues_i <- issues[,-drop_s] geom_line() +
issues_s <- issues[,-drop_i] geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
issues_i$total <- rowSums(issues_i[2:ncol(issues_i)]) xlab("Zeitraum") + ylab("Entropie") +
issues_i$entropy <- 0 scale_colour_discrete(name = "", labels = "Entropie")# +
for(r in 1:nrow(issues_i)) { # theme(legend.title = element_text(size=14)) +
curtotal <- as.numeric(issues_i$total[r]) # theme(legend.text = element_text(size=12)) +
curp <- 0 # theme(axis.title = element_text(size = 13))
for(c in 2:ncol(issues_i)) { g_entrop
curcount <- as.numeric(issues_i[r,c]) g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
curp[c] <- curcount / curtotal geom_line() +
} geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
curp <- curp [2:length(curp)-2] xlab("Zeitraum") + ylab("Entropie") +
curdrop <- which(curp==0) scale_colour_discrete(name = "", labels = "Entropie")
curp <- curp[-curdrop] g_entrop
issues_i$entropy[r] <- sum(-1 * curp * log(curp)) g_perday <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) +
}
issues_s$total <- rowSums(issues_s[2:ncol(issues_s)])
issues_s$entropy <- 0
for(r in 1:nrow(issues_s)) {
curtotal <- as.numeric(issues_s$total[r])
curp <- 0
for(c in 2:ncol(issues_s)) {
curcount <- as.numeric(issues_s[r,c])
curp[c] <- curcount / curtotal
}
curp <- curp [2:length(curp)-2]
curdrop <- which(curp==0)
curp <- curp[-curdrop]
issues_s$entropy[r] <- sum(-1 * curp * log(curp))
}
stats_total <- data.frame(date=drange)
stats_total$tpd <- 0
stats_total$ipd <- issues_i$total
stats_total$spd <- issues_s$total
# Total number of tweets per day over time
for(r in 1:length(drange)) {
stats_total$tpd[r] <- length(tweets[tweets[, "created_at"] == drange[r], "id_str"])
}
g1 <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line()+ geom_line()+
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
xlab("Zeitraum") + ylab("Tweets pro Tag") +
scale_colour_discrete(name = "Tweets", labels = c("Gesamt", "Allgemein", "Sensation"))
g_perday
g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line() +
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
xlab("Zeitraum") + ylab("Entropie") +
scale_colour_discrete(name = "", labels = "Entropie")
g_entrop
g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line() +
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1)
g1 g_entrop
stats_entropy <- data.frame(date=drange) stats_entropy <- data.frame(date=drange)
stats_entropy$entropy <- issues_i$entropy stats_entropy$entropy <- issues_i$entropy
stats_entropy <- melt(stats_entropy, id="date") stats_entropy <- melt(stats_entropy, id="date")
g1 <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) + g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line() + geom_line() +
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
g1 xlab("Zeitraum") + ylab("Entropie") +
test <- VAR(issues[,2:32], p=1, type="none") scale_colour_discrete(name = "", labels = "Entropie")
View(issues_i) g_entrop
View(issues_s) g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
View(issues) geom_line() +
test <- VAR(issues[,2:44], p=1, type="none") geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
VAR(issues_s[,2:23], p=1, type=c("const", "trend", "both", "none"), season=NULL, exogen = issues_i[2:22]) xlab("Zeitraum") + ylab("Entropie") +
plot(irf(test, impulse = names(issues_s[2:23]), response = names(issues_i[2:22]))) scale_colour_discrete(name = "", labels = "Entropie") +
rm(c_correct, c_curissue, c_errcode, c_errid, c_errissue, c_error1, c_error2, c_errors) theme(legend.title = element_text(size=14)) +
rm(c_issues, c_issuelist, c_issueheads) theme(legend.text = element_text(size=12)) +
rm(c_errtags, c_errtext, c_result, c_tag, c_tmp, c_tweets) theme(axis.title = element_text(size = 13))
g_entrop
g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line() +
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
xlab("Zeitraum") + ylab("Entropie") +
scale_colour_discrete(name = "", labels = "Entropie") +
theme(legend.title = element_text(size=14)) +
theme(legend.text = element_text(size=12)) +
theme(axis.title = element_text(size = 14))
g_entrop
g_perday <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line()+
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
xlab("Zeitraum") + ylab("Tweets pro Tag") +
scale_colour_discrete(name = "Tweets", labels = c("Gesamt", "Allgemein", "Sensation")) +
theme(legend.title = element_text(size=14)) +
theme(legend.text = element_text(size=12)) +
theme(axis.title = element_text(size = 14))
g_perday
g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line() +
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
xlab("Zeitraum") + ylab("Entropie") +
scale_colour_discrete(name = "", labels = "Entropie") +
theme(legend.title = element_text(size=14)) +
theme(legend.text = element_text(size=12)) +
theme(axis.title = element_text(size = 14))
g_entrop
acc_parties <- data.frame(party = c("cducsu", "spd", "linke", "gruene"))
acc_parties$btw13 <- c(49.3, 30.6, 10.1, 10.0) # seats of party / 631 seats
acc_parties$twitter <- 0
for(p in 1:nrow(acc_parties)) {
acc_parties$twitter[p] <- round(nrow(acc_df[acc_df$party == as.character(acc_parties$party[p]), ]) / 280 * 100)
}
require(jsonlite)
require(stringr) require(stringr)
require(XML) require(devtools)
readYN <- function(question) { require(RTwitterAPI)
n <- readline(prompt=question)
n <- as.character(n)
return(n)
}
checkIssue <- function(string, issuelist) {
status <- any(str_detect(string, issuelist))
return(status)
}
checkAllIssues <- function(string, issuelist) {
status <- NULL
for(i in 1:length(string)) {
if(checkIssue(string[i], issuelist)) {
status[i] <- TRUE
}
else {
cat("Issue",string[i],"does not exist. Please try again.\n")
status[i] <- FALSE
}
}
return(status)
}
View(tweets)
c_tweets <- read.csv("tweets.csv", colClasses="character")
for(r in 1:nrow(c_tweets)) {
curtext <- as.character(c_tweets$text[r])
if(str_detect(curtext, "\"")) {
c_tweets$text[r] <- str_replace(curtext, "\"", "")
}
}
c_tweets$X <- NULL
c_issues <- data.frame(date = drange)
c_issuelist <- xmlToList("issues-v2.xml")
c_issueheads <- names(issuelist)
c_issues[issueheads] <- 0
source("issuecomp-codingsample-function.R")
require(stringr)
curtext
curtext <- str_replace_all(curtext, "#", "")
curtext <- str_replace_all(curtext, "-", " ")
curtext
curtext
str_replace_all(curtext, "[^[:alnum:]]", "")
str_replace_all(curtext, "[^[:alnum:]\s]", "")
str_replace_all(curtext, "[^[:alnum:]\\s]", "")
str_replace_all(curtext, "[^[:alnum:]^\\s]", "")
str_replace_all(curtext, "[^[:alnum:]^\\S]", "")
str_replace_all(curtext, "[^[:alnum:]][^\\s]", "")
str_replace_all(curtext, "[^[:alnum:]][^\\S]", "")
str_replace_all(curtext, "[^[:alnum:]][^[:blank]]", "")
str_replace_all(curtext, "[^[:alnum:]][^[:blank:]]", "")
str_replace_all(curtext, "[^[:alnum:]]", "")
str_replace_all(curtext, "\\W", "")
str_replace_all(curtext, "[\\W|\\S]", "")
str_replace_all(curtext, "(\\W|\\S)", "")
str_replace_all(curtext, "\\W|\\S", "")
str_replace_all(curtext, "\\W", "")
str_replace_all(curtext, "[\\W\\S]", "")
str_replace_all(curtext, "[\\S\\W]", "")
str_replace_all(curtext, "[\\s\\W]", "")
str_replace_all(curtext, "[\\W\\s]", "")
str_replace_all(curtext, "[\\W\s]", "")
str_replace_all(curtext, "[\\Ws]", "")
str_replace_all(curtext, "[\\W]", "")
str_replace_all(curtext, "\\W", "")
str_replace_all(curtext, "\\W|\\S", "")
str_replace_all(curtext, "\\W|\\s", "")
str_replace_all(curtext, "[^[:alnum:]]", "")
str_replace_all(curtext, "[^[:alnum:] ]", "")
str_replace_all(curtext, "[^[:alnum:]\\s]", "")
str_replace_all(curtext, "[^[:alnum:] ]", "")
curtext
curtext <- "liebe @cdu, wir finden #Steuer gut, aber die KFZ-Steuer nicht!"
curtext <- str_replace_all(curtext, "-", " ")
curtext <- str_replace_all(curtext, "[^[:alnum:] ]", "")
curtext
curtext <- "liebe @cdu, wir finden #Steuer gut, aber die KFZ--Steuer nicht!"
curtext <- str_replace_all(curtext, "-", " ")
curtext <- str_replace_all(curtext, "[^[:alnum:] ]", "")
curtext
str_replace_all(curtext, " ", " ")
smartPatternMatch
require(vars)
require(stringr)
adf1 <- summary(ur.df(issues))
issues
summary(issues)
summary(issues[2:44])
summary(issues[2:44], digits = 2)
adf1 <- summary(ur.df(issues[, 2:44]), type ="trend", lags=1)
data("Canda")
data("Canada")
class(Canada)
class(issues)
view(Canada)
View(Canada)
as.ts(issues)
issues_ts <- as.ts(issues)
class(issues_ts)
View(issues_ts)
View(issues)
adf1 <- summary(ur.df(issues_ts[, 2:44]), type ="trend", lags=1)
adf1 <- summary(ur.df(issues_ts[, 2]), type ="trend", lags=1)
adf1 <- summary(ur.df(issues_ts[, 2], type ="trend", lags=1))
adf1 <- summary(ur.df(issues_ts[, 2:44], type ="trend", lags=1))
adf1 <- summary(ur.df(issues_ts[, 2], type ="trend", lags=1))
adf1
adf1 <- summary(ur.df(issues_ts[, 3], type ="trend", lags=1))
adf1
adf1 <- summary(ur.df(issues_ts[, 2], type ="none", lags=1))
adf1
adf1 <- summary(ur.df(issues_ts[, 2], type ="trend", lags=1))
adf1
summary(ur.df(issues_ts[, 2], type ="none", lags=1))
VARselect(issues_ts[2:44], lag.max = 8, type = "both")
VARselect(issues_ts[1:44], lag.max = 8, type = "both")
VARselect(issues[1:44], lag.max = 8, type = "both")
VARselect(issues[2:44], lag.max = 8, type = "both")
VARselect(issues_ts[2:44], lag.max = 8, type = "both")
VARselect(issues[2:44], lag.max = 8, type = "none")
VARselect(issues[2:44], lag.max = 8, type = "trend")
VARselect(issues[2:44], lag.max = 8, type = "const")
VARselect(issues[2:44], lag.max = 8, type = "both")
test <- VAR(issues[,2:44], p=1, type="both")
# VAR(issues_s[,2:23], p=1, type=c("const", "trend", "both", "none"), season=NULL, exogen = issues_i[2:22])
plot(irf(test, impulse = names(issues_s[2:23]), response = names(issues_i[2:22])))
summary(ur.df(issues_ts[, 2], type ="both", lags=1))
summary(ur.df(issues_ts[, 2], type ="none", lags=1))
test <- VAR(issues_ts[,2:44], p=1, type="both")
plot(irf(test, impulse = names(issues_s[2:23]), response = names(issues_i[2:22])))
acc_df <- read.csv("MdB-twitter.csv") acc_df <- read.csv("MdB-twitter.csv")
delrow <- NULL delrow <- NULL
for(r in 1:nrow(acc_df)) { for(r in 1:nrow(acc_df)) {
@@ -288,225 +182,331 @@ acc_df <- acc_df[-delrow, ]
rm(delrow, r, acc) rm(delrow, r, acc)
acc_df$row.names <- NULL acc_df$row.names <- NULL
row.names(acc_df) <- NULL row.names(acc_df) <- NULL
View(acc_df) acc_parties <- data.frame(party = c("cducsu", "spd", "linke", "gruene"))
View(c_tweets) acc_parties$btw13 <- c(49.3, 30.6, 10.1, 10.0) # seats of party / 631 seats
issueheads acc_parties$twitter <- 0
length(issueheads) for(p in 1:nrow(acc_parties)) {
issuelist acc_parties$twitter[p] <- round(nrow(acc_df[acc_df$party == as.character(acc_parties$party[p]), ]) / 280 * 100)
length(issuelist)
length(issuelist[*])
length(issuelist[[*]])
length(issuelist[1:43])
length(issuelist[1)
length(issuelist[1])
length(issuelist[2])
length(issuelist[[1]])
length(issuelist[[2]])
length(issuelist[[70]])
length(issuelist[[43]])
length(issuelist[[44]])
length(issuelist[[1:43]])
length(issuelist[[1-43]])
length(issuelist[[2]])
test <- 0
num <- 0
for(i in 1:length(issuelist)) {
j <- length(issuelist[[i]])
num <- num + j
rm(j)
} }
num pie(acc_parties$btw13, col=c("black", "red", "purple", "green"), labels = c("CDU/CSU", "SPD", "Die LINKE", "Bündnis 90/Grüne"), clockwise = T,
drop_s <- which(str_detect(names(issues), "^s")) main = "Seats of parties in the parliament")
drop_i <- which(str_detect(names(issues), "^i")) pie(acc_parties$twitter, col=c("black", "red", "purple", "green"), labels = c("CDU/CSU", "SPD", "Die LINKE", "Bündnis 90/Grüne"), clockwise = T,
issues_i <- issues[,-drop_s] main = "Percentage of parties' MdBs of all Twitter accounts")
issues_s <- issues[,-drop_i] pie(acc_parties$btw13, col=c("black", "red", "purple", "green"), labels = c("CDU/CSU", "SPD", "Die LINKE", "Bündnis 90/Grüne"), clockwise = T)
require(stringr) pie(acc_parties$twitter, col=c("black", "red", "purple", "green"), labels = c("CDU/CSU", "SPD", "Die LINKE", "Bündnis 90/Grüne"), clockwise = T)
drop_s <- which(str_detect(names(issues), "^s")) View(acc_parties)
drop_i <- which(str_detect(names(issues), "^i")) pie(acc_parties$btw13, col=c("black", "red", "purple", "green"),
issues_i <- issues[,-drop_s] labels = c("CDU/CSU (49.3%)", "SPD", "Die LINKE", "Bündnis 90/Grüne"), clockwise = T)
issues_s <- issues[,-drop_i] pie(acc_parties$btw13, col=c("black", "red", "purple", "green"),
issues_i$total <- rowSums(issues_i[2:ncol(issues_i)]) labels = c("CDU/CSU (49,3%)", "SPD (30,6%)", "Die LINKE (10,1%)", "Bündnis 90/Grüne(10.0%)"),
issues_i$entropy <- 0 clockwise = T)
for(r in 1:nrow(issues_i)) { acc_parties <- data.frame(party = c("cducsu", "spd", "gruene", "linke"))
curtotal <- as.numeric(issues_i$total[r]) acc_parties$btw13 <- c(49.3, 30.6, 10.0, 10.1) # seats of party / 631 seats
curp <- 0 acc_parties$twitter <- 0
for(c in 2:ncol(issues_i)) { for(p in 1:nrow(acc_parties)) {
curcount <- as.numeric(issues_i[r,c]) acc_parties$twitter[p] <- round(nrow(acc_df[acc_df$party == as.character(acc_parties$party[p]), ]) / 280 * 100)
curp[c] <- curcount / curtotal
} }
curp <- curp [2:length(curp)-2] pie(acc_parties$btw13, col=c("black", "red", "green", "purple"),
curdrop <- which(curp==0) labels = c("CDU/CSU (49,3%)", "SPD (30,6%)", "Bündnis 90/Grüne(10.0%)", "Die LINKE (10,1%)"),
curp <- curp[-curdrop] clockwise = T)
issues_i$entropy[r] <- sum(-1 * curp * log(curp)) pie(acc_parties$btw13, col=c("black", "red", "green", "purple"),
} pie(acc_parties$btw13, col=c("black", "red", "green", "purple"),
issues_s$total <- rowSums(issues_s[2:ncol(issues_s)]) labels = c("CDU/CSU (49,3%)", "SPD (30,6%)", "Bündnis 90/Grüne(10,0%)", "Die LINKE (10,1%)"),
issues_s$entropy <- 0 clockwise = T)
for(r in 1:nrow(issues_s)) { pie(acc_parties$btw13, col=c("black", "red", "green", "purple"),
curtotal <- as.numeric(issues_s$total[r]) labels = c("CDU/CSU (49,3%)", "SPD (30,6%)", "Bündnis 90/Grüne(10,0%)", "Die LINKE (10,1%)"),
curp <- 0 clockwise = T)
for(c in 2:ncol(issues_s)) { pie(acc_parties$twitter, col=c("black", "red", "green", "purple"),
curcount <- as.numeric(issues_s[r,c]) labels = c("CDU/CSU (36%)", "SPD (30%)", "Bündnis 90/Grüne(19%)", "Die LINKE (15%)"),
curp[c] <- curcount / curtotal clockwise = T)
} pie(acc_parties$twitter, col=c("black", "red", "green", "purple"),
curp <- curp [2:length(curp)-2] pie(acc_parties$twitter, col=c("black", "red", "green", "purple"),
curdrop <- which(curp==0) labels = c("CDU/CSU (36%)", "SPD (30%)", "Bündnis 90/Grüne(19%)", "Die LINKE (15%)"),
curp <- curp[-curdrop] clockwise = T, init.angle = 90)
issues_s$entropy[r] <- sum(-1 * curp * log(curp)) pie(acc_parties$twitter, col=c("black", "red", "green", "purple"),
} labels = c("CDU/CSU (36%)", "SPD (30%)", "Bündnis 90/Grüne(19%)", "Die LINKE (15%)"),
stats_total <- data.frame(date=drange) clockwise = T)
stats_total$tpd <- 0 pie(acc_parties$twitter, col=c("black", "red", "green", "purple"),
stats_total$ipd <- issues_i$total labels = c("CDU/CSU (36%)", "SPD (30%)", "Bündnis 90/Grüne(19%)", "Die LINKE (15%)"),
stats_total$spd <- issues_s$total clockwise = T, init.angle = 180)
# Total number of tweets per day over time pie(acc_parties$twitter, col=c("black", "red", "green", "purple"),
for(r in 1:length(drange)) { labels = c("CDU/CSU (36%)", "SPD (30%)", "Bündnis 90/Grüne(19%)", "Die LINKE (15%)"),
stats_total$tpd[r] <- length(tweets[tweets[, "created_at"] == drange[r], "id_str"]) clockwise = T, init.angle = 270)
} pie(acc_parties$twitter, col=c("black", "red", "green", "purple"),
stats_melt <- melt(stats_total, id="date") labels = c("CDU/CSU (36%)", "SPD (30%)", "Bündnis 90/Grüne(19%)", "Die LINKE (15%)"),
g1 <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) + clockwise = T, init.angle = 360)
geom_line()+ pie(acc_parties$twitter, col=c("black", "red", "green", "purple"),
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) labels = c("CDU/CSU (36%)", "SPD (30%)", "Bündnis 90/Grüne(19%)", "Die LINKE (15%)"),
g1 clockwise = T, init.angle = 20)
require(ggplot2) pie(acc_parties$twitter, col=c("black", "red", "green", "purple"),
stats_melt <- melt(stats_total, id="date") labels = c("CDU/CSU (36%)", "SPD (30%)", "Bündnis 90/Grüne(19%)", "Die LINKE (15%)"),
g1 <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) + clockwise = T, init.angle = 20)
geom_line()+ pie(acc_parties$twitter, col=c("black", "red", "green", "purple"),
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) labels = c("CDU/CSU (36%)", "SPD (30%)", "Bündnis 90/Grüne(19%)", "Die LINKE (15%)"),
g1 clockwise = T, init.angle = 90)
g1 <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) + pie(acc_parties$btw13, col=c("black", "red", "green", "purple"),
geom_line()+ labels = c("CDU/CSU (49,3%)", "SPD (30,6%)", "Bündnis 90/Grüne(10,0%)", "Die LINKE (10,1%)"),
geom_smooth(size=1,formula = y ~ x, method="lm", se=FALSE, color=1) clockwise = T)
g1 pie(acc_parties$twitter, col=c("black", "red", "green", "purple"),
g1 <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) + labels = c("CDU/CSU (36%)", "SPD (30%)", "Bündnis 90/Grüne(19%)", "Die LINKE (15%)"),
geom_line()+ clockwise = T)
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) 2359 / 200 * 100
g1
# Visuals for entropy in time series
stats_entropy <- data.frame(date=drange)
stats_entropy$entropy <- issues_i$entropy
stats_entropy <- melt(stats_entropy, id="date")
require(reshape2)
stats_melt <- melt(stats_total, id="date")
g1 <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line()+
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1)
g1
stats_entropy <- data.frame(date=drange)
stats_entropy$entropy <- issues_i$entropy
stats_entropy <- melt(stats_entropy, id="date")
g1 <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line() +
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1)
g1
g1 <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line() +
geom_smooth(size=1,formula = y ~ x, method="lm", se=FALSE, color=1)
g1
vIssues <- VAR(issues_ts[,2:44], p=1, type="both")
require(vars)
VARselect(issues_ts, lag.max = 8, type = "both")
vIssues <- VAR(issues_ts[,2:44], p=1, type="both")
VARselect(issues_ts, lag.max = 16, type = "both")
VARselect(issues_ts, lag.max = 4, type = "both")
VARselect(issues_ts, lag.max = 5, type = "both")
VARselect(issues_ts, lag.max = 6, type = "both")
VARselect(issues_ts, lag.max = 5, type = "both")
names(issues_ts)
issues_ts
issues_ts[2:44]
issues_ts <- as.ts(issues[,2:44])
issues_ts[1:1]
issues_ts[,1]
issues_ts[1,1]
issues_ts2,1]
issues_ts[2,1]
issues_ts <- as.ts(issues[,2:44]) issues_ts <- as.ts(issues[,2:44])
VARselect(issues_ts, lag.max = 5, type = "both") VARselect(issues_ts, lag.max = 5, type = "both")
VARselect(issues_ts, lag.max = 8, type = "both")
VARselect(issues_ts, lag.max = 7, type = "both")
VARselect(issues_ts, lag.max = 5, type = "both")
vIssues <- VAR(issues_ts[,2:44], p=5, type="both")
vIssues <- VAR(issues_ts, p=5, type="both") vIssues <- VAR(issues_ts, p=5, type="both")
plot(irf(vIssues, impulse = names(issues_s[2:23]), response = names(issues_i[2:22]))) vIssues <- VAR(issues_ts, p=1, type="both")
require(stringr) issues_ts <- as.ts(issues)
require(XML) VARselect(issues[2:44], lag.max = 8, type = "both")
c_errors <- read.csv("issuecomp-codingsample-error.csv", header = F, sep=",", colClasses="character") summary(ur.df(issues_ts[, 2], type ="none", lags=1))
names(c_errors) <- c("str_id", "code", "issue", "tags", "text") VARselect(issues_ts, lag.max = 5, type = "both")
for(r in 1:nrow(c_errors)) { issues_ts <- as.ts(issues[,2:44])
c_errcode <- as.character(c_errors$code[r]) VARselect(issues_ts, lag.max = 5, type = "both")
c_errissue <- as.character(c_errors$issue[r]) VARselect(issues_ts, lag.max = 5, type = "both")
c_errtags <- as.character(c_errors$tags[r]) VARselect(issues_ts, lag.max = 5, type = "both")
c_errtext <- as.character(c_errors$text[r]) VARselect(issues_ts, lag.max = 5, type = "both")
c_errid <- as.character(c_errors$str_id[r]) VARselect(issues_ts, lag.max = 5, type = "both")
cat("===============\n\n[TWEET]: ",c_errtext,"\n[ISSUES]: ", c_errissue, " (", c_errtags, ")\n", sep="") VARselect(issues_ts, lag.max = 5, type = "both")
source("issuecomp-codingsample-function2.R") VARselect(issues_ts, lag.max = 5, type = "both")
summary(ur.df(issues_ts[, 2], type ="none", lags=1))
ur.df(issues_ts[, 2], type ="none", lags=1)
head(issues_ts)
issues_ts$i1.macro
issues_ts[, "i1.macro"]
summary(ur.df(issues_ts[, "i1.macro"], type ="none", lags=1))
ncol(issues_ts)
for(i in 2:ncol(issues_ts)) {
summary(ur.df(issues_ts[, i], type ="none", lags=1))
} }
for(r in 1:nrow(c_errors)) { cat(summary(ur.df(issues_ts[, "i1.macro"], type ="none", lags=1)))
c_errcode <- as.character(c_errors$code[r]) paste(summary(ur.df(issues_ts[, "i1.macro"], type ="none", lags=1)))
c_errissue <- as.character(c_errors$issue[r]) i
c_errtags <- as.character(c_errors$tags[r]) summary(ur.df(issues_ts[, i], type ="none", lags=1))
c_errtext <- as.character(c_errors$text[r]) summary(ur.df(issues_ts[, 1], type ="none", lags=1))
c_errid <- as.character(c_errors$str_id[r]) summary(ur.df(issues_ts[, 2], type ="none", lags=1))
cat("===============\n\n[TWEET]: ",c_errtext,"\n[ISSUES]: ", c_errissue, " (", c_errtags, ")\n", sep="") summary(ur.df(issues_ts[, 1], type ="none", lags=1))
source("issuecomp-codingsample-function2.R") summary(ur.df(issues_ts[, 1], type ="none", lags=1))
names(issues_ts)
issues_ts[1,]
summary(ur.df(issues_ts[, 1], type ="none", lags=1))
summary(ur.df(issues_ts[, 2], type ="none", lags=1))
summary(ur.df(issues_ts[, 43], type ="none", lags=1))
summary(ur.df(issues_ts[, 43], type ="trend", lags=1))
summary(ur.df(issues_ts[, 43], type ="none", lags=1))
summary(ur.df(issues_ts[, 1], type ="none", lags=1))
ur.df(issues_ts[, 1], type ="none", lags=1)
for(i in 2:ncol(issues_ts)) {
ur.df(issues_ts[, i], type ="none", lags=1)
} }
ur.df(issues_ts[, i], type ="none", lags=1)
test <- ur.df(issues_ts[, i], type ="none", lags=1)
test
for(i in 2:ncol(issues_ts)) {
test <- ur.df(issues_ts[, i], type ="none", lags=1)
cat(test)
}
class(test)
as.character(test)
for(i in 2:ncol(issues_ts)) {
test[i] <- ur.df(issues_ts[, i], type ="none", lags=1)
}
ur.df(issues_ts[, 1], type ="none", lags=1)
ur.df(issues_ts[, sprintf("%s", c(1,2,3))], type ="none", lags=1)
ur.df(issues_ts[, sprintf("%i", c(1,2,3))], type ="none", lags=1)
ur.df(issues_ts[, 2], type ="none", lags=1)
ur.df(issues_ts[, 3], type ="none", lags=1)
i <- 0
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
i
issueheads issueheads
for(i in 1:length(issueheads)) {paste(issueheads[i])} length(issuelist[[2]])
for(i in 1:length(issueheads)) {cat(issueheads[i], "\n")} # List all issues in one row
for(r in 1:nrow(c_errors)) { for(i in 1:length(issueheads)) {
c_errcode <- as.character(c_errors$code[r]) cat(issueheads[i], "\n")
c_errissue <- as.character(c_errors$issue[r])
c_errtags <- as.character(c_errors$tags[r])
c_errtext <- as.character(c_errors$text[r])
c_errid <- as.character(c_errors$str_id[r])
cat("===============\n\n[TWEET]: ",c_errtext,"\n[ISSUES]: ", c_errissue, " (", c_errtags, ")\n", sep="")
source("issuecomp-codingsample-function2.R")
} }
for(r in 1:nrow(c_errors)) { vIssues <- VAR(issues_ts, p=1, type="both")
c_errcode <- as.character(c_errors$code[r]) issues_ts[1:20,1]
c_errissue <- as.character(c_errors$issue[r]) issues_ts[,1]
c_errtags <- as.character(c_errors$tags[r]) issues_ts[1,]
c_errtext <- as.character(c_errors$text[r]) issues_ts[1:21,]
c_errid <- as.character(c_errors$str_id[r]) issues_ts[,1:21]
cat("===============\n\n[TWEET]: ",c_errtext,"\n[ISSUES]: ", c_errissue, " (", c_errtags, ")\n", sep="") issues_ts[1,1:21]
source("issuecomp-codingsample-function2.R") issues_ts[1,22:43]
} issues_ts[1,22:44]
c_errors <- read.csv("issuecomp-codingsample-error.csv", header = F, sep=",", colClasses="character") issues_ts[1,22:43]
names(c_errors) <- c("str_id", "code", "issue", "tags", "text") plot(irf(vIssues, impulse = names(issues_ts[1:21]), response = names(issues_i[22:43])))
for(r in 1:nrow(c_errors)) { require(stringr)
c_errcode <- as.character(c_errors$code[r]) require(reshape2)
c_errissue <- as.character(c_errors$issue[r]) require(ggplot2)
c_errtags <- as.character(c_errors$tags[r])
c_errtext <- as.character(c_errors$text[r])
c_errid <- as.character(c_errors$str_id[r])
cat("===============\n\n[TWEET]: ",c_errtext,"\n[ISSUES]: ", c_errissue, " (", c_errtags, ")\n", sep="")
source("issuecomp-codingsample-function2.R")
}
c_tmp <- read.csv("issuecomp-codingsample-error1.csv", header = F, colClasses="character")
names(c_tmp) <- c("str_id", "all", "wrong", "tagged", "text")
c_error1 <- c_tmp[, c("wrong", "tagged", "all", "text")]
c_tmp <- read.csv("issuecomp-codingsample-error2.csv", header = F, colClasses="character")
names(c_tmp) <- c("str_id", "all", "missing", "tagged", "text")
c_error2 <- c_tmp[, c("missing", "text", "tagged", "all")]
View(c_error2)
summary(ur.df(issues_ts[, 2], type ="none", lags=1))
require(vars) require(vars)
summary(ur.df(issues_ts[, 2], type ="none", lags=1)) vIssues
stability(vIssues) plot(irf(vIssues, impulse = names(issues_ts[1:21]), response = names(issues_i[22:43])))
stability(vIssues[2:]) plot(irf(vIssues, impulse = names(issues_ts[1:21]), response = names(issues_ts[22:43])))
stability(vIssues[2:44]) issues_s
plot(stability(vIssues)) names(issues_s)
class(vIssues) names(issues_s[2:23])
summary(vIssues) names(issuesi[2:22])
plot(stability(vIssues[2])) names(issues_i[2:22])
plot(stability(vIssues), nc=2) plot(irf(vIssues, impulse = names(issues_s[2:23]), response = names(issues_i[2:22])))
plot(stability(vIssues), h=0.15) plot(irf(vIssues, impulse = names(issues_s[2:23]), response = names(issues_i[2:22])))
stability(vIssues) plot(irf(vIssues, impulse = names(issues_s[2:23]), response = names(issues_i[2:22])))
efp(formula = formula, data = data, type = type, h = h, dynamic = dynamic, irf(vIssues, impulse = names(issues_s[2:23]), response = names(issues_i[2:22]))
rescale = rescale) vIRF <- irf(vIssues, impulse = names(issues_s[2:23]), response = names(issues_i[2:22]))
plot(stability(vIssues), h=0.15) summary(vIRF)
plot(stability(vIssues, h=0.15)) vIRF$irf
plot(stability(vIssues, h=0.15, rescale = TRUE)) vIRF$boot
plot(stability(vIssues, h=0.15, rescale = TRUE), nc=2) vIRF$ortho
par("mar") vIRF$Lower
par(mar=c(1,1,1,1)) vIRF$irf[1]
plot(stability(vIssues, h=0.15, rescale = TRUE), nc=2) vIRF$irf["s.boko"]
summary(issues$hk)
summary(issues$s.hk)
summary(issues$s.nsa)
summary(issues$s.gaza)
summary(issues$s.boko)
summary(issues$s.ebola)
summary(issues$s.edathy)
summary(issues$s.ferguson)
summary(issues$s.gurlitt)
summary(issues$s.is)
summary(issues$s.pegida)
summary(issues$s.schumi)
summary(issues$s.tebartz)
summary(issues$s.wm)
summary(issues$s.wulff)
plot(vIRF)
names(issues)
summary(issues[2:44])
plot(vIRF)
plot(vIRF, x=300, y=200)
plot(vIRF, res = 300)
plot(vIRF[1])
plot(vIRF$irf[1])
summary(issues[2:44])
ur.df(issues_ts[, i], type ="none", lags=1)
summary(ur.df(issues_ts[, i], type ="none", lags=1))
summary(ur.df(issues_ts[,30], type ="none", lags=1))
summary(issues[2])
stats_entropy
names(issues)
issues_bak <- issues
issues$total <- rowSums(issues[2:ncol(issues)])
issues$entropy <- 0
names(issues)
issues$total <- rowSums(issues[2:ncol(issues)])
issues$entropy <- 0
for(r in 1:nrow(issues)) {
curtotal <- as.numeric(issues$total[r])
curp <- 0
for(c in 2:ncol(issues)) {
curcount <- as.numeric(issues[r,c])
curp[c] <- curcount / curtotal
}
curp <- curp [2:length(curp)-2]
curdrop <- which(curp==0)
curp <- curp[-curdrop]
issues$entropy[r] <- sum(-1 * curp * log(curp))
}
stats_entropy <- data.frame(date=drange)
stats_entropy$entropy <- issues$entropy
stats_entropy <- melt(stats_entropy, id="date")
g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line() +
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
xlab("Zeitraum") + ylab("Entropie") +
scale_colour_discrete(name = "", labels = "Entropie") +
theme(legend.title = element_text(size=14)) +
theme(legend.text = element_text(size=12)) +
theme(axis.title = element_text(size = 14))
g_entrop
View(issues)
summary(issues$entropy)
summary(issues$total)
stats_total
summary(issues[2:44])
+1
View File
@@ -6,3 +6,4 @@ issuecomp-analysis.log
issuecomp-codingsample-correct.csv issuecomp-codingsample-correct.csv
issuecomp-codingsample-error.csv issuecomp-codingsample-error.csv
issuecomp-codingsample-error2.csv issuecomp-codingsample-error2.csv
twitter-api-credentials.txt
+1 -1
View File
@@ -21,7 +21,7 @@ drange <- date_start + days(0:drange)
# Import issues and prepare everything # Import issues and prepare everything
# Will only be filled after the large categorisation loop # Will only be filled after the large categorisation loop
issues <- data.frame(date = drange) issues <- data.frame(date = drange)
issuelist <- readLines("issues-v2.xml") issuelist <- readLines("issues-v3.xml")
issuelist <- str_replace_all(string = issuelist, pattern = ".*<!-- .+ -->", "") issuelist <- str_replace_all(string = issuelist, pattern = ".*<!-- .+ -->", "")
issuelist <- xmlToList(issuelist) issuelist <- xmlToList(issuelist)
issueheads <- names(issuelist) issueheads <- names(issuelist)
+74 -37
View File
@@ -7,7 +7,7 @@ require(vars)
drop_s <- which(str_detect(names(issues), "^s")) drop_s <- which(str_detect(names(issues), "^s"))
drop_i <- which(str_detect(names(issues), "^i")) drop_i <- which(str_detect(names(issues), "^i"))
issues_i <- issues[,-drop_s] issues_i <- issues[,-drop_s]
issues_s <- issues[,-drop_i] issues <- issues[,-drop_i]
# # # #
# ENTROPY # ENTROPY
@@ -15,7 +15,6 @@ issues_s <- issues[,-drop_i]
# Entropy non-sensational issues # Entropy non-sensational issues
issues_i$total <- rowSums(issues_i[2:ncol(issues_i)]) issues_i$total <- rowSums(issues_i[2:ncol(issues_i)])
issues_i$entropy <- 0 issues_i$entropy <- 0
for(r in 1:nrow(issues_i)) { for(r in 1:nrow(issues_i)) {
curtotal <- as.numeric(issues_i$total[r]) curtotal <- as.numeric(issues_i$total[r])
curp <- 0 curp <- 0
@@ -30,71 +29,102 @@ for(r in 1:nrow(issues_i)) {
} }
# Entropy sensational issues # Entropy sensational issues
issues_s$total <- rowSums(issues_s[2:ncol(issues_s)]) issues$total <- rowSums(issues[2:ncol(issues)])
issues_s$entropy <- 0 issues$entropy <- 0
for(r in 1:nrow(issues)) {
for(r in 1:nrow(issues_s)) { curtotal <- as.numeric(issues$total[r])
curtotal <- as.numeric(issues_s$total[r])
curp <- 0 curp <- 0
for(c in 2:ncol(issues_s)) { for(c in 2:ncol(issues)) {
curcount <- as.numeric(issues_s[r,c]) curcount <- as.numeric(issues[r,c])
curp[c] <- curcount / curtotal curp[c] <- curcount / curtotal
} }
curp <- curp [2:length(curp)-2] curp <- curp [2:length(curp)-2]
curdrop <- which(curp==0) curdrop <- which(curp==0)
curp <- curp[-curdrop] curp <- curp[-curdrop]
issues_s$entropy[r] <- sum(-1 * curp * log(curp)) issues$entropy[r] <- sum(-1 * curp * log(curp))
}
# Entropy overall
issues$total <- rowSums(issues[2:ncol(issues)])
issues$entropy <- 0
for(r in 1:nrow(issues)) {
curtotal <- as.numeric(issues$total[r])
curp <- 0
for(c in 2:ncol(issues)) {
curcount <- as.numeric(issues[r,c])
curp[c] <- curcount / curtotal
}
curp <- curp [2:length(curp)-2]
curdrop <- which(curp==0)
curp <- curp[-curdrop]
issues$entropy[r] <- sum(-1 * curp * log(curp))
} }
# Compare total tweets vs. total issue findings
# Compare total tweets vs. total sensational & total unsensational
stats_total <- data.frame(date=drange) stats_total <- data.frame(date=drange)
stats_total$tpd <- 0 stats_total$tpd <- 0
stats_total$ipd <- issues_i$total stats_total$ipd <- issues_i$total
stats_total$spd <- issues_s$total stats_total$spd <- issues$total
# Total number of tweets per day over time # Total number of tweets per day over time
for(r in 1:length(drange)) { for(r in 1:length(drange)) {
stats_total$tpd[r] <- length(tweets[tweets[, "created_at"] == drange[r], "id_str"]) stats_total$tpd[r] <- length(tweets[tweets[, "created_at"] == drange[r], "id_str"])
} }
# VISUALS: Tweets per day vs. sensational vs. general findings
stats_melt <- melt(stats_total, id="date") stats_melt <- melt(stats_total, id="date")
g1 <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) + g_perday <- ggplot(data = stats_melt, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line()+ geom_line()+
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
g1 xlab("Zeitraum") + ylab("Tweets pro Tag") +
scale_colour_discrete(name = "Tweets", labels = c("Gesamt", "Allgemein", "Sensation")) +
theme(legend.title = element_text(size=14)) +
theme(legend.text = element_text(size=12)) +
theme(axis.title = element_text(size = 14))
g_perday
# Visuals for entropy in time series # Visuals for entropy in time series
stats_entropy <- data.frame(date=drange) stats_entropy <- data.frame(date=drange)
stats_entropy$entropy <- issues_i$entropy stats_entropy$entropy <- issues$entropy
stats_entropy <- melt(stats_entropy, id="date") stats_entropy <- melt(stats_entropy, id="date")
g1 <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) + g_entrop <- ggplot(data = stats_entropy, aes(x=date,y=value,colour=variable, group=variable)) +
geom_line() + geom_line() +
geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) geom_smooth(size=1,formula = y ~ x, method="loess", se=FALSE, color=1) +
g1 xlab("Zeitraum") + ylab("Entropie") +
scale_colour_discrete(name = "", labels = "Entropie") +
theme(legend.title = element_text(size=14)) +
theme(legend.text = element_text(size=12)) +
theme(axis.title = element_text(size = 14))
g_entrop
# VAR --------------------------------------------------------------------- # VAR ---------------------------------------------------------------------
# test <- VAR(issues[,2:32], p=1, type=c("const", "trend", "both", "none"), season=NULL, exogen = NULL, lag.max = NULL, ic = c("AIC", "HQ", "SC", "FPE")) # test <- VAR(issues[,2:32], p=1, type=c("const", "trend", "both", "none"), season=NULL, exogen = NULL, lag.max = NULL, ic = c("AIC", "HQ", "SC", "FPE"))
# test <- VAR(issues_i[,2:22], p=1, type="none", exogen = issues_s[,2:3]) # test <- VAR(issues_i[,2:22], p=1, type="none", exogen = issues[,2:3])
# test <- VAR(issues_s[,2:11], p=1, type="none") # test <- VAR(issues[,2:11], p=1, type="none")
# VAR(issues_s[,2:23], p=1, type=c("const", "trend", "both", "none"), season=NULL, exogen = issues_i[2:22]) # VAR(issues[,2:23], p=1, type=c("const", "trend", "both", "none"), season=NULL, exogen = issues_i[2:22])
issues_ts <- as.ts(issues[,2:44]) issues_ts <- as.ts(issues[,2:44])
VARselect(issues_ts, lag.max = 5, type = "both")
vIssues <- VAR(issues_ts, p=5, type="both")
plot(irf(vIssues, impulse = names(issues_s[2:23]), response = names(issues_i[2:22])))
capture.output(print(summary(test), prmsd=TRUE, digits=1), file="out.txt")
# Tests # Tests
issues_ts <- as.ts(issues) VARselect(issues_ts, lag.max = 5, type = "both")
VARselect(issues[2:44], lag.max = 8, type = "both") i <- 0
summary(ur.df(issues_ts[, 2], type ="none", lags=1)) i <- i + 1
ur.df(issues_ts[, i], type ="none", lags=1)
summary(issues[2:44])
# VAR and IRF
vIssues <- VAR(issues_ts, p=1, type="both")
vIRF <- irf(vIssues, impulse = names(issues[2:23]), response = names(issues_i[2:22]))
plot(vIRF)
# capture.output(print(summary(test), prmsd=TRUE, digits=1), file="out.txt")
# SOME TESTS -------------------------------------------------------------- # SOME TESTS --------------------------------------------------------------
@@ -116,16 +146,18 @@ rm(g1, r)
# Show party percentage of twitter users # Show party percentage of twitter users
acc_parties <- data.frame(party = c("cducsu", "spd", "linke", "gruene")) acc_parties <- data.frame(party = c("cducsu", "spd", "gruene", "linke"))
acc_parties$btw13 <- c(49.3, 30.6, 10.1, 10.0) # seats of party / 631 seats acc_parties$btw13 <- c(49.3, 30.6, 10.0, 10.1) # seats of party / 631 seats
acc_parties$twitter <- 0 acc_parties$twitter <- 0
for(p in 1:nrow(acc_parties)) { for(p in 1:nrow(acc_parties)) {
acc_parties$twitter[p] <- round(nrow(acc_df[acc_df$party == as.character(acc_parties$party[p]), ]) / 280 * 100) acc_parties$twitter[p] <- round(nrow(acc_df[acc_df$party == as.character(acc_parties$party[p]), ]) / 280 * 100)
} }
pie(acc_parties$btw13, col=c("black", "red", "purple", "green"), labels = c("CDU/CSU", "SPD", "Die LINKE", "Bündnis 90/Grüne"), clockwise = T, pie(acc_parties$btw13, col=c("black", "red", "green", "purple"),
main = "Seats of parties in the parliament") labels = c("CDU/CSU (49,3%)", "SPD (30,6%)", "Bündnis 90/Grüne(10,0%)", "Die LINKE (10,1%)"),
pie(acc_parties$twitter, col=c("black", "red", "purple", "green"), labels = c("CDU/CSU", "SPD", "Die LINKE", "Bündnis 90/Grüne"), clockwise = T, clockwise = T)
main = "Percentage of parties' MdBs of all Twitter accounts") pie(acc_parties$twitter, col=c("black", "red", "green", "purple"),
labels = c("CDU/CSU (36%)", "SPD (30%)", "Bündnis 90/Grüne(19%)", "Die LINKE (15%)"),
clockwise = T)
rm(acc_parties, p) rm(acc_parties, p)
@@ -152,6 +184,11 @@ ggplot(issues_melt,aes(x=date,y=value,colour=variable,group=variable)) + geom_sm
# POSSIBLY USEFUL CODE ---------------------------------------------------- # POSSIBLY USEFUL CODE ----------------------------------------------------
# List all issues in one row
for(i in 1:length(issueheads)) {
cat(issueheads[i], "\n")
}
# Limits of list # Limits of list
length(issuelist) length(issuelist)
length(issuelist[[2]]) length(issuelist[[2]])
-5
View File
@@ -1,5 +0,0 @@
# 1. line: consumer key, 2. consumer secret, 3. oauth token, 4. oauth secret
c9Ob2fWNSONMC0mA2JlNaeRke
cZ3Il2hmbLgK0Lc57mj5kUvymjVdsmZKYwKOGHR3NhCpvWgEOI
1007025684-RFxCDFc4OPkt02bASmdci00TB4jgaPjfqxLRT58
rvfv8MgexFKTqrPNSoGrdrZVNhV4fTJb2Bgz249nbvKNg
+5
View File
@@ -0,0 +1,5 @@
# 1. line: consumer key, 2. consumer secret, 3. oauth token, 4. oauth secret
xxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+22
View File
@@ -0,0 +1,22 @@
i1.macro & -5,869 & s.nsa & -7,3292 \\
i2.civil & -4,4172 & s.is & -7,762 \\
i3.health & -9,5973 & s.ebola & -6,1723 \\
i4.agrar & -8,5183 & s.edathy & -7,0335 \\
i5.labor & -7,523 & s.ukraine & -5,6195 \\
i6.edu & -6,4374 & s.hk & -6,7599 \\
i7.env & -7,1426 & s.mh17 & -6,1481 \\
i8.energy & -7,3613 & s.gaza & -5,3861 \\
i10.trans & -5,6718 & s.ferguson & -8,8098 \\
i12.law & -5,9882 & s.boko & -10,4431 \\
i13.social & -6,7765 & s.pegida & -6,3831 \\
i14.house & -8,9577 & s.schumi & -12,4947 \\
i15.finance & -5,9094 & s.mh370 & -7,8991 \\
i16.defense & -6,9535 & s.esc & -11,6332 \\
i17.science & -5,9651 & s.wulff & -12,4189 \\
i18.trade & -7,6121 & s.tebartz & -12,6301 \\
i19.ib & -3,8057 & s.gurlitt & -10,7665 \\
i20.pubadmin & -6,7123 & s.hoen & -9,3721 \\
i21.publand & -9,9521 & s.pistorius & -13,435 \\
i24.stateadm & -13,435 & s.philae & -12,7024 \\
i25.reuni & -5,2011 & s.wm & -8,7283 \\
& & s.sotschi & -8,2339 \\