Skip to content

Instantly share code, notes, and snippets.

Francis Smart EconometricsBySimulation

Block or report user

Report or block EconometricsBySimulation

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:fe40ec9f749213d1240011684001dda5

emailto: psteiner@umd.edu student: Francis Smart fsmart@gmail.com EDMS769G

# Text Network graph
#           Student Ability _______________________
#            /           |                         \_____
#          /             |  Public/Private Transport     \
#         ↓              ↓     ↓                          ↘
View ConsumptionInference.R
# Estimating Weekly consumption from periodic purchasing data
library(dplyr)
library(data.table)
library(reshape)
library(tidyr)
library(ggplot2)
# Day Purchase
View Campaign-Finance-Density.R
rm(list=ls())
library(data.table)
library(dplyr)
library(ggplot2)
setwd('Z:/Data/FEC')
dsum <- function(...) dplyr::summarize(...)
to.data.table <- function(x) {(class(x) <- class(data.table())) ;x}
View FEC-Clinton-PieCharts.R
rm(list=ls())
library(data.table)
library(dplyr)
library(ggplot2)
library(scales)
setwd('Z:/Data/FEC')
dsum <- function(...) dplyr::summarize(...)
View numbers2words.R
# adapted from John Fox's numbers2words function
require(magrittr); require(Rmpfr)
make.digits <- function(x) {
# This is a function breaks an input number x into the positive (left)
# and negative(right) elements and returns these as numbers
x <- toString(x)
negative <- substr(x,1,1)=="-"
if (negative) x <- substring(x,2)
@EconometricsBySimulation
EconometricsBySimulation / cubes.R
Created Sep 10, 2014
Easy Bordered Cubes in R
View cubes.R
library('rgl'); library('magrittr')
cube <- function(x=0,y=0,z=0, bordered=TRUE,
filled = TRUE, lwd=2, scale=1,
fillcol = gray(.95),
bordercol ='black', ...) {
mycube <- cube3d()
# Reduce size to unit
@EconometricsBySimulation
EconometricsBySimulation / ebola.R
Last active Aug 29, 2015
Analysis of Ebola data
View ebola.R
# First let's load some libraries
require('XML'); require('reshape2'); require('ggplot2')
require('magrittr') # See
# http://goo.gl/Wj5F87
# I have borrowed Andrie's code from stackoverflow
# http://goo.gl/noYVo7
source("http://goo.gl/w64gfp")
# Load in the google spreadsheet
@EconometricsBySimulation
EconometricsBySimulation / readGoogleSheet.R
Last active Aug 29, 2015
Read Google Spreadsheet into R
View readGoogleSheet.R
# This set of functions comes entirely form Andrie on stackoverflow
# http://stackoverflow.com/questions/22873602/importing-data-into-r-from-google-spreadsheet
readGoogleSheet <- function(url, na.string="", header=TRUE){
stopifnot(require(XML))
# Suppress warnings because Google docs seems to have incomplete final line
suppressWarnings({
doc <- paste(readLines(url), collapse=" ")
})
if(nchar(doc) == 0) stop("No content found")
@EconometricsBySimulation
EconometricsBySimulation / gist:d0af8273f15b6ccb85a4
Last active Aug 29, 2015
Rapidly sample from arbitrary pdf
View gist:d0af8273f15b6ccb85a4
I recently found myself in need of a function to sample randomly from an arbitrarily defined probability density function. An excellent post by Quantitations shows how to accomplish this using some of Rs fairly sophisticated functional approximation tools such as integrate and uniroot. The only problem with this excellent post was that the machine cost was enormous with samples of 1000 draws taking 10 seconds on my machine and repeated samples of 100,000+ draws (which I was after) clearly being unworkable.
Thus I decided to take my own crack at it. First let us review the basics of drawing random variables from non-uniform distributions. The standard method I think most algorithms use works as follows:
Assumptions
1. You can draw pseudo-random uniform variable u
2. You can integrate the pdf to construct a cdf
$$p = F(x) = \int_{-\infty}^\infty f(x) dx$$
3. You can invert the cdf in order to solve for p
$$G(F(x))=F^{-1}(F(x))=F^{-1}(p)=x$$
@EconometricsBySimulation
EconometricsBySimulation / gist:0b54b14d3040d3e89709
Created Jul 20, 2014
Graphical Anlaysis of Trends in Name Data
View gist:0b54b14d3040d3e89709
require(plyr)
require(ggplot2)
require(scales)
# Download data from:
# http://www.ssa.gov/oact/babynames/names.zip
setwd("C:/Data/SS-names/")
files<-list.files()
files<-files[grepl(".txt",files)]
You can’t perform that action at this time.