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 / gamma_parameters.R
Created April 15, 2016 19:10
Fit a gamma distribution based on prior information Raw
# Objective
#
# Fit a gamma distribution knowing that:
# - 20% fall below 15 days
# - 80% fall below 60 days
# Inspired by http://www.johndcook.com/blog/2010/01/31/parameters-from-percentiles/
x <- c(0.2, 0.8)
y <- c(15, 60)
@dmarcelinobr
dmarcelinobr / IBGE_Dados_Publicos
Created March 30, 2016 16:01
Copia informações públicas no servidor do IBGE
#!/bin/bash
areas_de_ponderacao="ftp://geoftp.ibge.gov.br/malhas_digitais/censo_2010/areas_de_ponderacao/"
setores_censitarios="ftp://geoftp.ibge.gov.br/malhas_digitais/censo_2010/setores_censitarios/"
setores_censitarios_kmz="ftp://geoftp.ibge.gov.br/malhas_digitais/censo_2010/setores_censitarios_kmz/"
CNEFE="ftp://ftp.ibge.gov.br/Censos/Censo_Demografico_2010/Cadastro_Nacional_de_Enderecos_Fins_Estatisticos/"
date=`date +%F`
mkdir $date
<?xml version="1.0" encoding="UTF-8"?>
<!--
## SOURCE: xe.com
-->
<currency-symbol count="115">
<entry code="ALL" unicode-decimal="76, 101, 107" unicode-hex="4c, 65, 6b">Albania Lek</entry>
<entry code="AFN" unicode-decimal="1547" unicode-hex="60b">Afghanistan Afghani</entry>
<entry code="ARS" unicode-decimal="36" unicode-hex="24">Argentina Peso</entry>
<entry code="AWG" unicode-decimal="402" unicode-hex="192">Aruba Guilder</entry>
<entry code="AUD" unicode-decimal="36" unicode-hex="24">Australia Dollar</entry>
@dmarcelinobr
dmarcelinobr / ggplot-disconnected.R
Created January 1, 2016 21:54
ggplot2 geom_line() example with disconnected lines for NA values
# ggplot2 example
# Show how geom_line() does not connect the line through NA values
library(ggplot2)
# Make some fake data
mydata <- data.frame(x = 2000:2010, y = rnorm(11, 5, 2))
# First plot, all lines are connected correctly
ggplot(mydata, aes(x, y)) + geom_line()
@dmarcelinobr
dmarcelinobr / randomwalk.R
Created January 1, 2016 21:50
randomwalk
# animation-2.r
# author: Bryce Mecum ([email protected])
#
# Animations in R Tutorial
# Part 2 of 6
#
# Extend part 1 by plotting a random (uniform) walk starting in the bottom
# right-hand corner and moving North and West.
library(maps)
@dmarcelinobr
dmarcelinobr / dplyr's_tally.R
Created January 1, 2016 21:48
dplyr's tally()
library(dplyr)
# Set up an example data frame
stations = c("A", "B", "C")
species = c("M", "N", "O", "P", "Q")
baseline = c(5, 50, 500)
n <- 25
mydf <- data.frame(station=sample(stations, n, replace=TRUE), species=sample(species, n, replace=TRUE))
mydf$baseline <- baseline[match(mydf$station, stations)]
@dmarcelinobr
dmarcelinobr / golden_questions.R
Created December 31, 2015 05:22
trying to reduce dimensionality of a golden questions survey in insurance Raw
################
# Setup
################
rm(list=(ls()))
#libs
library(reshape2)
library(plyr)
library(stringr)
@dmarcelinobr
dmarcelinobr / archigos-polity.r
Created December 31, 2015 05:10
Descriptive look at Archigos leader entry/exit and tenure length for different regime types, using the Polity IV data and scheme for the latter.
# Archigos transitions and tenure by regime type
#
# Andreas Beger
# 15 December 2014
setwd("~/Desktop/archigos-polity")
library(foreign)
library(gdata)
@dmarcelinobr
dmarcelinobr / DemoR.R
Created December 31, 2015 04:51
Commands for demonstration
# run a quick demonstration
install.packages("Hmisc",dependencies=TRUE)
update.packages()
library("Hmisc")
mydata<-spss.get("http://www.rci.rutgers.edu/~rwomack/R/vermont.sav",use.value.labels=TRUE)
head(mydata)
tail(mydata)
summary(mydata)
attach(mydata)
hist(AGEP)
@dmarcelinobr
dmarcelinobr / server.R
Last active December 31, 2015 03:56
Simple Shiny survey that pushes data to a Dropbox folder
# devtools::install_github("duncantl/ROAuth")
# devtools::install_github("karthik/rDrop")
library(ROAuth)
library(rDrop)
load('my_dropbox_credentials.rdata') #credentials object from rDrop instructions
shinyServer(function(input, output) {
output$Main <- renderUI({
dynamicUi()