Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# analyse data about 2015 Polish parliamentary elections
# more info: http://smarterpoland.pl/index.php/2015/12/czy-internet-pozwala-przewidziec-wyniki-wyborow/
library(Amelia)
library(ggplot2)
library(tabplot)
# load the data
dane <- read.table("https://raw.githubusercontent.com/pbiecek/SmarterPoland_blog/master/dane/Wybory2015/2r.txt",
header=T,
sep="\t",
dec=",")
# map the missing values
missmap(dane)
# overview plot
tableplot(dane,
select = c(objekt, sm, google, sondaz),
sortCol = objekt)
# change the format
dane$data <- as.Date(dane$data, "%Y-%m-%d")
# plot the time series
ggplot(data=dane,aes(x=dane$data,y=sondaz)) +
geom_line(aes(color=objekt), size=1) +
scale_x_date("Date") +
scale_y_continuous("Opinion Poll") +
geom_smooth(method = "loess", size = 1)
ggplot(data=dane,aes(x=dane$data,y=sm)) +
geom_line(aes(color=objekt), size=1) +
scale_x_date("Date") +
scale_y_continuous("Social Media") +
geom_smooth(method = "loess", size = 1)
ggplot(data=dane,aes(x=dane$data,y=google)) +
geom_line(aes(color=objekt), size=1) +
scale_x_date("Date") +
scale_y_continuous("Google Trends") +
geom_smooth(method = "loess", size = 1)
# autocorrelation
keeps <- c("google", "sm", "sondaz")
# remove NAs to run acf
daneWOdate <- na.omit(dane[keeps])
acf(daneWOdate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment