Skip to content

Instantly share code, notes, and snippets.


Sam Boysel sboysel

View GitHub Profile
sboysel /
Last active Jun 16, 2021
R Spatial Analysis Notes

R Spatial Analysis Notes

Spatial Analysis in R

Key Packages

  • sp - defines the set of base classes for spatial data in R. Most useful for creating, converting, merging, transforming (e.g. projection), and plotting (see spplot) Spatial* objects.
  • rgdal - wrapper
sboysel / .block
Last active Jun 1, 2021
Interactive Choropleth
View .block
license: gpl-3.0
height: 650
sboysel /
Created Jun 29, 2016
Notes on econometrics in R

Notes on Econometrics in R

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.

Packages and functions

Linear Regression

  • stats::lm - the standard OLS routine included in the base R package stats. The call summary(lm(y ~ x1 + x2, data = mydata)) produces output most similar to reg y x1 x2 in Stata.
  • lfe - Linear Fixed Effects models. In addition to efficiently handling high-dimension fixed effects, the workhorse function felm also supports instrumental variables and clustered standard errors. As it improves lm by incorp
sboysel / xtable.decimal.r
Last active Nov 21, 2020 — forked from jbryer/xtable.decimal.r
Prints a LaTeX table with numeric columns aligned on their decimal points. This function wraps the xtable and print.xtable functions in the xtable package so that numeric columns are aligned on their decimal place.
View xtable.decimal.r
#' 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{}
#' for more information.
#' @author Jason Bryer <>
sboysel /
Created Dec 2, 2019 proof of GitHub identity

Keybase proof

I hereby claim:

  • I am sboysel on github.
  • I am sboysel ( on keybase.
  • I have a public key whose fingerprint is F0BB B0B8 886D 1CDB 392D E755 2E8D EF7C 3554 032D

To claim this, I am signing this object:

sboysel / ght-restore-psql
Created Feb 13, 2019 — forked from etcwilde/ght-restore-psql
Restore the GHTorrent database to postgres instead of mysql (based on mysql-2017-01-19 image)
View ght-restore-psql
#!/usr/bin/env bash
# Evan Wilde <>
# July 20, 2017
# defaults
sboysel / query.sql
Created Feb 1, 2019
Most popular Stack Overflow tags (Stack Exchange Data Explorer query)
View query.sql
num.TagName as Tag,
row_number() over (order by num.Num desc) as TotalRank,
rate.Rate as QuestionsInMay,
num.Num as QuestionsTotal
(select count(PostId) as Rate, TagName
sboysel / ggplot2_map.R
Created Jun 17, 2016
Notes on mapping sp objects with ggplot2
View ggplot2_map.R
# Get administrative boundaries as SpatialPolygonsDataFrame
sboysel / spatialutils.R
Created Jun 7, 2016
Convenience functions for loading spatial data.
View spatialutils.R
# TODO: (1) What if I want to keep the remote zipfile after downloading? [x]
# (2) Other common formats: - GeoJSON [x]
# - KML [ ]
# 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))
sboysel / sumstats.R
Last active Mar 4, 2016
Grouped Summary Statistics
View sumstats.R
#' 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