This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quick wrapper for the awesome commandlinefu.com API | |
# http://www.commandlinefu.com/site/api | |
using Requests | |
using JSON | |
BASE_URL = "http://www.commandlinefu.com/commands/" | |
function bestfu() | |
q = BASE_URL * "browse/sort-by-votes/json" | |
return JSON.parse(IOBuffer(Requests.get(q).data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prepare SpatialPolygonsDataFrame for plotting with ggplot2 | |
# Follows https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles | |
# Assumes you are in Hadleyverse and already have dplyr loaded. | |
prepare_spdf <- function(spdf) { | |
require(dplyr) | |
reguire(ggplot2) | |
spdf@data$id <- rownames(spdf@data) | |
spdf.points <- ggplot2::fortify(spdf, region = "id") | |
if (sum(is.na(spdf.points$hole))) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load the MNIST digit recognition dataset into R | |
# http://yann.lecun.com/exdb/mnist/ | |
# assume you have all 4 files and gunzip'd them | |
# creates train$n, train$x, train$y and test$n, test$x, test$y | |
# e.g. train$x is a 60000 x 784 matrix, each row is one digit (28x28) | |
# call: show_digit(train$x[5,]) to see a digit. | |
# brendan o'connor - gist.github.com/39760 - anyall.org | |
load_mnist <- function(path = "mnist") { | |
# Usage: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Prints a LaTeX table with numeric columns aligned on their decimal points. | |
#' | |
#' This function wraps the \code{\link{xtable}} and \code{\link{print.xtable}} | |
#' functions in the \code{xtable} package so that numeric columns are aligned | |
#' on their decimal place. | |
#' | |
#' See \url{http://jason.bryer.org/posts/2013-01-04/xtable_with_aligned_decimals.html} | |
#' for more information. | |
#' | |
#' @author Jason Bryer <jason@@bryer.org> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Grouped summary statistics | |
#' | |
#' Wraps \code{\link{aggregate}} to generate common summary statistics over | |
#' subsets. | |
#' | |
#' @param data A data.frame to be summarized. | |
#' @param by Grouping variables specified by a formula as used in | |
#' \code{\link{aggregate}}. | |
#' @param stats A character vector of statistical functions. Default is c("n", | |
#' "mean", "sd", "min", "max"). More functions can be added by modifying the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TODO: (1) What if I want to keep the remote zipfile after downloading? [x] | |
# (2) Other common formats: - GeoJSON [x] | |
# - KML [ ] | |
library(rgdal) | |
# Functions to check filenames | |
is_remote <- function(x) grepl("(ht|f)tp(s)?://", x) | |
is_zip <- function(x) grepl("\\.zip$", basename(x)) | |
is_shp <- function(x) grepl("\\.shp$", basename(x)) | |
is_json <- function(x) grepl("\\.(geo)?json$", basename(x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(maptools) | |
library(mapproj) | |
library(ggthemes) | |
library(sp) | |
library(raster) | |
library(rgeos) | |
library(RColorBrewer) | |
# Get administrative boundaries as SpatialPolygonsDataFrame |
This note summarizes several tools for traditional econometric analysis using R
. The CRAN Task View - Econometrics provides a very comprehensive overview of available econometrics packages in R
. Rather the duplicate this resource, I will highlight several functions and tools that accommodate 95% of my econometric analyses.
stats::lm
- the standard OLS routine included in the baseR
packagestats
. The callsummary(lm(y ~ x1 + x2, data = mydata))
produces output most similar toreg y x1 x2
in Stata.lfe
- Linear Fixed Effects models. In addition to efficiently handling high-dimension fixed effects, the workhorse functionfelm
also supports instrumental variables and clustered standard errors. As it improveslm
by incorp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 | |
height: 650 |
OlderNewer