Created
January 27, 2013 04:49
-
-
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.
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
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