Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile

Using open legislative data to map bill co-sponsorship networks in 15 countries

[Published at Opening Parliament.org](published at http://blog.openingparliament.org/post/113803051548/using-open-legislative-data-to-map-bill).

A few years back, Kamil Gregor published a post on the OpeningParliament.org blog under the title “Visualizing politics: Network analysis of bill sponsors”.

His post, which focused on the lower chamber of the Czech Parliament, showed how basic social network analysis can support the exploration of parliamentary work, by revealing the ties that Members of Parliament create between each other through the cosponsorship of private bills.

As Kamil observed, this kind of research is heavily dependent on open legislative data, which do not exist for many parliaments. There has been, however, some amount of progress in that area -- and even when parliaments do not develop open data _portals

library(ROAuth)
requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
# replace XYZ with your Twitter API consumer key
consumerKey <- "XYZ"
# replace ... with your Twitter API consumer secret
# introduction vite fait au t-test (comparaison de moyennes)
# le jeu de données fictif ci-dessous est à remplacer par
# data = read.csv("/chemin/vers/votre/fichier.csv", stringsAsFactors = FALSE)
data = data.frame(site = letters[ 1:15 ],
categorie = sample(LETTERS[ 1:2 ], 15, replace = TRUE),
mesure = runif(15))
# voilà à quoi doivent ressembler les données
@briatte
briatte / ess.r
Last active August 29, 2015 14:21
library(dplyr)
library(ggplot2)
library(readr)
library(survey)
ess5 = read_csv("ESS5_FR_SDDF.csv") %>%
left_join(read_csv("ESS5FR.csv"), by = c("cntry", "idno")) %>%
ess_prepare
ess5 = svydesign(
library(Matrix)
## building a 729670 x 1167 object (fast enough)
M = list()
pb = txtProgressBar(min = 1, max = length(followers_m))
for(i in 1:length(followers_m)) {
@briatte
briatte / 01-dz.r
Last active August 29, 2015 14:27
Scrape current MPs of the lower chamber of the Algerian parliament: http://www.apn.dz/ (mirrors this scraper: https://github.com/tmtmtmtm/algeria-assemblee/blob/master/scraper.rb -- at the exception that it won't encode constituencies as OCD entities)
library(dplyr)
library(rvest)
r = "http://www.apn.dz"
n <- function(h, g) {
h = html_nodes(h, ".listing-summary")
data_frame(
id = html_attr(h, "data-link-id"),
@briatte
briatte / icelandic-legal-code-network.md
Last active August 29, 2015 18:37
network projection of cross-references in the Icelandic legal code
@briatte
briatte / edge_assignment_with_network_package.r
Last active September 9, 2015 10:54
differences in edge assignment methods of R network package
# issue when assigning a vector of edge values:
# x %e% "y" = 1:z ## does not assign 1:z, creates duplicates
# set.edge.value(x, "y", 1:z) ## does not assign 1:z, creates duplicates
# set.edge.attribute(x, "y", 1:z) ## assigns 1:z, as expected
# using version 1.12.0
library(network)
# minimal reprex
@briatte
briatte / cleanup.sh
Created June 26, 2012 01:40
SRQM scripts (deprecated by GitHub and Stata magics)
### delete tex files in slides folder
cd ~/Documents/Teaching/SRQM/Course
rm *.aux *.dvi *.toc *.log *.nav *.out *.snm *.synctex.gz *.tex.bak *.vrb *.run.xml *-blx.bib *.idx *.fdb_latexmk
### delete log files in replication folder
cd ~/Documents/Teaching/SRQM/Replication/
@briatte
briatte / print.css
Last active October 8, 2015 13:08
SRQM style for README files
/*
Styling for Markdown preview in TextMate, copty to:
~/Library/Application Support/TextMate/Managed/Bundles/Themes.tmbundle/Support/web-themes/SRQM/style.css
*/
@import url(http://fonts.googleapis.com/css?family=Ubuntu:400,500,400italic);
@import url(http://fonts.googleapis.com/css?family=Ubuntu+Mono);
*, p {
font-family: "Ubuntu", sans-serif;