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
require(MCMCpack)
## the more recent polls, the better they are.
##http://es.wikipedia.org/wiki/Elecciones_presidenciales_de_Uruguay_de_2014
polls = NULL
polls <- data.frame( rbind(
Factum = c(52,37, 1004),
Cifra = c(52, 35, 1000),
Equipos = c(52, 39, 600),
# caTools is handy because it provides write.gif function
library(caTools)
cols <- colorRampPalette(c("#00007F", "brown", "blue", "#007FFF", "green", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000", "magenta"))
m <- 1200 # define size
C <- complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ),
imag=rep(seq(-1.2,1.2, length.out=m), m ) )
C <- matrix(C,m,m) # reshape as square matrix
Z <- 0 # initialize Z to zero
X <- array(0, c(m,m,20)) # initialize output 3D array
for (k in 1:20) { # loop with 20 iterations
#Comments
1. All code is written with the original, vague priors.
2. Runs were made with the logicals compiled.
3. Note that inprod() could be used, but is much slower (in versions of BUGS up to 3.0.1): with no missing covariate information it should be more efficient.
4. Parameters that I monitored are highlighted in this fetching shade .
5. Initial valus are given: the burn-in was not our main interest, so they were set to make this small.
6. Comments on the no selection, fixed effect, apply to all models. Similarly, comments on fixed effect models also apply to the corresponding random effect model
Data for all models in here
@dmarcelinobr
dmarcelinobr / Tufte's_Weather_Chart.R
Last active October 15, 2015 19:11
Provides a step-by-step approach to creating the Brasilia temperature visualization, which mirrors the illustration in Edward Tufte's classic book Visual Display of Quantitative Information
# The original R code is Bradley Boehmke
# https://rpubs.com/bradleyboehmke/weather_graphic
# Packages
library(dplyr)
library(tidyr)
library(magrittr)
library(ggplot2)
"http://academic.udayton.edu/kissock/http/Weather/gsod95-current/BZBRSLIA.txt" %>%
read.table() %>% data.frame %>% tbl_df -> data
names(data) <- c("month", "day", "year", "temp")
## Exported as an SVG of 1200 width and 525 height
poly_coords<- function(shapefile){
if (nrow(data.frame(shapefile$ID))< 1)
{
print ("No ID field in SpatialPolygon")
}else{
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')
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
@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)
# 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')
library(ggplot2)
#install.packages("lme4")
library(lme4)
library(doBy)
library(mice)
############### ###############
# MI adjustments for final estimates
############### ###############
finalMI <- function(var,beta,m){