Skip to content

Instantly share code, notes, and snippets.


Francis Smart EconometricsBySimulation

View GitHub Profile
View gist:9757105
####### Excel summary exporter #######
## Modified from Smart, Francis ##
## Jean P. Gibert, 2014 ##
lmOut <- function(res, file="test.csv", ndigit=3, writecsv=T) {
# If summary has not been run on the model then run summary
if (length(grep("summary", class(res)))==0) res <- summary(res)
co <- res$coefficients
nvar <- nrow(co)
ncoll <- ncol(co)
EconometricsBySimulation / gist:9958775
Created Apr 3, 2014
List of Stata packages/commands
View gist:9958775
View julia_npp.xml
<UserLang name="Julia" ext="jl">
<Global caseIgnored="no" />
<TreatAsSymbol comment="no" commentLine="yes" />
<Prefix words1="no" words2="no" words3="no" words4="no" />
<Keywords name="Delimiters">&quot;00&quot;00</Keywords>
<Keywords name="Folder+">begin function type for while if</Keywords>
EconometricsBySimulation / gist:0b54b14d3040d3e89709
Created Jul 20, 2014
Graphical Anlaysis of Trends in Name Data
View gist:0b54b14d3040d3e89709
# Download data from:
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:
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
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
readGoogleSheet <- function(url, na.string="", header=TRUE){
# Suppress warnings because Google docs seems to have incomplete final line
doc <- paste(readLines(url), collapse=" ")
if(nchar(doc) == 0) stop("No content found")
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
# I have borrowed Andrie's code from stackoverflow
# Load in the google spreadsheet
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 / 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
View server.r
shinyServer(function(input, output) {
output$main_plot <- renderPlot(width = 400, height = 300, {
probability = TRUE,
breaks = as.numeric(input$n_breaks),
xlab = "Duration (minutes)",
main = "Geyser eruption duration")
You can’t perform that action at this time.