Skip to content

Instantly share code, notes, and snippets.

View duarteguilherme's full-sized avatar

Guilherme Jardim Duarte duarteguilherme

  • Wharton School
  • Philadelphia
View GitHub Profile
@duarteguilherme
duarteguilherme / gnp_heavy_metal
Created November 19, 2014 20:35
gnp_heavy_metal
#Este post foi inspirado pelo mapa postado no perfil da "International Association for Political Science Students", que mostrava o número de bandas de metal por cada 100.000 habitantes por país. [Confira aqui.](https://www.facebook.com/IAPSS/photos/a.153193376080.144801.65123606080/10152913814401081/?type=1&theater)
#Eu, que sou um grande fã do estilo, adorei a ideia. A partir disso, resolvi desdobrar os resultados: será que haveria uma associação entre a proporção de bandas de metal e desenvolvimento econômico? Aparentemente pelo gráfico sim. Será que existe?
#Como não possuímos o banco de dados, vamos utilizar o R para coleta-los do mesmo site (http://www.metal-archives.com/browse/country) de onde o mapa foi tirado:
library(rvest) # para o scraping
library(dplyr) # para data-frames
# Simulando dados de probit
set.seed(1928506)
x1 <- rnorm(5000,0,1)
P <- pnorm(1.5 + 1.2*x1) #- 2.3*x2 + 1.9*x3 + rnorm(5000))
y <- rbinom(5000, 1,P)
# Dá uma olhada. Aqui dá o resultado certinho.
glm(y ~ x1 , family=binomial(link="probit"))
return_tosses <- function(value1, value2) {
t1 <- rbinom(1,1,.5)
i <- 1
while ( TRUE ) {
t2 <- rbinom(1,1,.5)
i <- i + 1
if ( t1 == value1 & t2 == value2)
return(i)
t1 <- t2
}
# Simulating shit
library(tidyverse)
library(magrittr)
# Model
# 10 parties
np <- 10
# uniform distribution for this parties seq(10) - number of legislators
nl <- sample(10:40, np, replace = T)
import requests
from bs4 import BeautifulSoup
from pymongo import MongoClient
banco = MongoClient().denicola.denicola
url = "http://www.conasems.org.br/conasems_dados/municipios.php?"
estados = [ "AC", "AL", "AM", "AP", "BA", "CE", "DF", "ES",
"GO", "MA", "MG", "MS", "MT", "PA", "PB", "PE",
import re
import requests
from bs4 import BeautifulSoup
from pymongo import MongoClient
#banco = MongoClient.trf2.trf2
class Crawler:
def __init__(self,palavra_chave):
self.palavra_chave = palavra_chave

O que ainda falta para arrumar no banco:

  1. Verificar tempo em tjal.csv
# Análise CNJ
library(tidyverse)
library(tidytext)
library(RCurl)
library(tm)
dados <- readRDS('~/Downloads/data_cnj (2).rds')
library(devtools)
devtools::install_github('RobertMyles/congressbr')
library(congressbr)
library(tidyverse)
library(stringr)
library(lubridate)
`%p%` <- function(e1,e2) return(paste0(e1,e2))
erros <- c()
download_year <- function(year) {
> cat(content(b, "text"))
<div id="ContentPlaceHolder">
<script type="text/javascript">
function funcFecharHandler() {
$("#divExibirConsultaDetalhada").hide();
$("#divConsultaDetalhada").html("");
$("#divPrincipal").show();
$("#divLinkConsultas").show();
}