Skip to content

Instantly share code, notes, and snippets.

View dmarcelinobr's full-sized avatar
💭
I may be slow to respond

Daniel Marcelino dmarcelinobr

💭
I may be slow to respond
View GitHub Profile
@dmarcelinobr
dmarcelinobr / VenezuelanParliamentaryElection.Rmd
Last active December 8, 2015 01:40
Code for Venezuelan Parliamentary Election blog post
#---
#layout: post
#title: "Venezuelan Parliamentary Election: What do the Polls Say?"
#date: 2015-12-06
#category: [R]
#tags: [Venezuela, election, polls]
# comments: true
#image:
#---
@dmarcelinobr
dmarcelinobr / 2012_Federal_Election.ipynb
Last active November 30, 2015 14:16
2012 Federal Election Database of Campaign Contributions
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dmarcelinobr
dmarcelinobr / President's_height.R
Last active January 4, 2016 22:56
height of president divided by height of most successful opponent. Data from Stulp et al. 2013's paper.
height_ratio <- c(0.924324324, 1.081871345, 1, 0.971098266, 1.029761905,
0.935135135, 0.994252874, 0.908163265, 1.045714286, 1.18404908,
1.115606936, 0.971910112, 0.97752809, 0.978609626, 1,
0.933333333, 1.071428571, 0.944444444, 0.944444444, 1.017142857,
1.011111111, 1.011235955, 1.011235955, 1.089285714, 0.988888889,
1.011111111, 1.032967033, 1.044444444, 1, 1.086705202,
1.011560694, 1.005617978, 1.005617978, 1.005494505, 1.072222222,
1.011111111, 0.983783784, 0.967213115, 1.04519774, 1.027777778,
1.086705202, 1, 1.005347594, 0.983783784, 0.943005181, 1.057142857)
require(magrittr)
require(SciencesPo)
# Latest polls:
polls = NULL
polls <- data.frame( rbind(
Kapa = c(47.2,33,1000),
ProRata = c(37,46,1200),
U.Macedonia = c(42.5,43,1042),
Public.Issue=c(45.5,45,1053),
GPO=c(44.1,43.7,2453),
@dmarcelinobr
dmarcelinobr / network_basic.R
Last active June 22, 2019 06:18
network_basic
# Tutorial and data based on the network visualization workshop published over https://rpubs.com/kateto/netviz
#packages:
library(igraph)
library(RCurl)
# get the data
nodes <- read.csv("https://raw.githubusercontent.com/danielmarcelino/Datasets/master/Media-NODES.csv", header=T, as.is=T)
ties <- read.csv("https://raw.githubusercontent.com/danielmarcelino/Datasets/master/Media-EDGES.csv", header=T, as.is=T)
# Explore data:
library(ggplot2)
#install.packages("lme4")
library(lme4)
library(doBy)
library(mice)
############### ###############
# MI adjustments for final estimates
############### ###############
finalMI <- function(var,beta,m){
# written by http://hannes.muehleisen.org/
# from http://stackoverflow.com/questions/16474696/read-system-tmp-dir-in-r
gettmpdir <-
function() {
tm <- Sys.getenv(c('TMPDIR', 'TMP', 'TEMP'))
d <- which(file.info(tm)$isdir & file.access(tm, 2) == 0)
if (length(d) > 0)
tm[[d[1]]]
else if (.Platform$OS.type == 'windows')
@dmarcelinobr
dmarcelinobr / RSQLite.R
Created January 17, 2015 16:44
Script to understand how queries can be optimized using RSQLite
##################################################################################
####################### SQLite Speed #####################################
##################################################################################
install.packages("sqldf")
require(sqldf)
#DataPath<-"C:/Data/NewTables/"
#Datatbl<-list.files(DataPath)
#Cwd<-getwd()
#setwd(DataPath)
#dat = lapply(Datatbl,read.csv, header = TRUE)
library(rvest)
'http://espn.go.com/sportsnation/teamrankings#table' %>>%
html %>>%
html_table() %>>% data.frame %>>% tbl_df -> data
names(data) %<>% tolower()
c('rank','team') -> names(data)[1:2]
data$rank %>>% (gsub('\\.','',.)) %>>% as.numeric -> data$rank
data[!is.na(data$rank),] -> data
require(dplyr)
require(RCurl)
require(reshape2)
require(rvest)
require(pipeR)
getGoogleResults <- function (search.term, show = 10){
Trim <- function (x) gsub("^\\s+|\\s+$", "", x)
packages = c('rvest','dplyr','pipeR','reshape2')