Skip to content

Instantly share code, notes, and snippets.

@johnjosephhorton
johnjosephhorton / tableContinuous.R
Last active December 17, 2015 23:19
This is tableContinuous from reporttools - I'd like it to include the ability to pass a caption placement parameter to the function.
tableContinuous <- function (vars, weights = NA, subset = NA, group = NA, stats = c("n",
"min", "q1", "median", "mean", "q3", "max", "s", "iqr", "na"),
prec = 1, col.tit = NA, col.tit.font = c("bf", "", "sf",
"it", "rm"), print.pval = c("none", "anova", "kruskal"),
pval.bound = 10^-4, declare.zero = 10^-10, cap = "", lab = "",
font.size = "footnotesize", longtable = TRUE, disp.cols = NA,
nams = NA, caption.placement = "bottom")
{
print.pval <- match.arg(print.pval)
if (identical(disp.cols, NA) == FALSE) {
@johnjosephhorton
johnjosephhorton / get_country_specific_minimum_wages_from_wikipedia.R
Created May 21, 2013 17:08
Get country-specific wages from Wikipedia and plot them with ggplot2
############################################################################
# AUTHOR: John Horton
# PURPOSE: Extract by-country minimum hourly wages from the Wikipedia page
# LAST MODIFIED: May 22, 2013
############################################################################
library(XML)
library(ggplot2)
library(scales)
@johnjosephhorton
johnjosephhorton / make_table.R
Created September 24, 2012 17:23
Create a new table in the database with R
df.odw <- data.frame(application = df$application, p = df$p)
if(dbExistsTable(con, "predicted_response_probabilities")){
dbRemoveTable(con, "predicted_response_probabilities")
}
dbWriteTable(con, "predicted_response_probabilities", df.odw)

Papers

Published & Forthcoming Papers in Economics

"The Online Laboratory: Conducting Experiments in a Real Labor Market" (with David Rand and Richard Zeckhauser) Experimental Economics, 14:3 (2011), 399-425.

@johnjosephhorton
johnjosephhorton / .emacs
Created August 21, 2012 17:39
John Horton's .emacs file
(add-to-list 'load-path "~/.emacs.d/")
(add-to-list 'load-path "/usr/share/emacs/site-lisp/ess")
;; LaTeX stuff
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)
;; browse the kill ring
(load "browse-kill-ring.el" nil t t)
@johnjosephhorton
johnjosephhorton / memisc_update_for_lme4.R
Created August 5, 2012 16:37
Change to memisc to support lme4 models
## ----------------------------------------------------------------------------
## Author: Jason Morgan (borrowing heavily from code contained in Martin Elff's
## memisc package).
##
## Notes: Additional methods for mtable formatting of lme4 model
## objects. Requires that the memisc package be loaded prior to
## sourcing these functions.
## ----------------------------------------------------------------------------
setSummaryTemplate(mer = c("Log-likelihood" = "($logLik:f#)",
library(ggplot2)
library(RPostgreSQL)
library(plyr)
library(scales) # now needed for ggplot2
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname='db',
host = 'localhost',
user = 'db',
password ='pwd',
Coefficients:
Estimate Std. Error t value
(Intercept) -0.070957 0.022836 -3.107
log(job_desc_length) 0.032188 0.003320 9.695
grouptreatment 0.042197 0.008536 4.943
factor(level1)Business Services 0.023747 0.027189 0.873
factor(level1)Customer Service -0.010701 0.030912 -0.346
factor(level1)Design & Multimedia 0.077688 0.017592 4.416
factor(level1)Networking & Information Systems 0.048057 0.030840 1.558
factor(level1)Sales & Marketing 0.119671 0.017374 6.888
@johnjosephhorton
johnjosephhorton / missingness.R
Created June 15, 2012 00:34
Dealing with missing values in R
n <- 100
x <- runif(n)
y <- 5*x
missing <- runif(n) > .80
df <- data.frame(y = y, x = x, missing = missing)
df$x[missing] <- mean(df$x[!missing])
df$y[!df$missing] <- df$y[!df$missing] + .80
m <- lm(y ~ x + missing, data = df)
summary(m)
@johnjosephhorton
johnjosephhorton / hashfree.py
Created May 15, 2012 00:28
Makes sure there are no unsaved files
def hashfree(input_dir):
"""Makes sure---before we start doing lots of intense computations---that
there are not any files w/ hash in front of them (which the shutil utility
cannot copy for some reason) """
no_bad_files = True
bad_files = []
for root, subFolders, files in os.walk(input_dir):
for f in files:
if re.search('\.#.*', f):
no_bad_files = False