Skip to content

Instantly share code, notes, and snippets.

@shippy
Created January 27, 2013 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shippy/4646363 to your computer and use it in GitHub Desktop.
Save shippy/4646363 to your computer and use it in GitHub Desktop.
Explores the relationship between regional GDP per capita and proportion of second-round votes that Milos Zeman, the Czech President-Elect, received.
library(XML)
reg_gdp_url <- "http://en.wikipedia.org/wiki/Regions_of_the_Czech_Republic"
reg_gdp <- readHTMLTable(reg_gdp_url, encoding = "UTF-8")
reg_gdp[[2]][1:14,2] -> regions
as.numeric(gsub(",", "", as.character(reg_gdp[[2]][1:14,8]))) -> GDP
nuts <- c(1100, 2100, 3100, 3200, 4100, 4200, 5100, 5200, 5300, 6200, 8100, 7100, 7200, 6100)
mz = c()
ks = c()
for (i in 1:length(nuts)) {
url <- paste("http://volby.cz/pls/prez2013/pe311?xjazyk=CZ&xnumnuts=", as.character(nuts[i]))
tab <- readHTMLTable(url)
mz <- cbind(mz, as.numeric(gsub(",", ".", as.character(tab[[2]][7,8]))))
ks <- cbind(ks, as.numeric(gsub(",", ".", as.character(tab[[2]][10,8]))))
}
lm.mz_gdp0 <- lm(as.vector(mz) ~ as.vector(GDP) - 1) # no intercept
summary(lm.mz_gdp0)
lm.mz_gdp <- lm(as.vector(mz) ~ as.vector(GDP)) # intercept
summary(lm.mz_gdp)
plot(GDP, mz)
lines(lowess(GDP, mz))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment