Last active
December 13, 2015 22:09
-
-
Save erzk/3c81d6fc2be7062a4d61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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