Skip to content

Instantly share code, notes, and snippets.

View chris-prener's full-sized avatar

Chris Prener chris-prener

View GitHub Profile
@chris-prener
chris-prener / asrBibTeX.tex
Last active February 19, 2024 17:27
Setting up a LaTeX document with a custom style for the American Sociological Review
%% ASR Formatted Bibliography using BibTeX
%% requires the American Sociological Review .bst file - http://people.ku.edu/~chkim/etc/asr.bst
%% requires a properly formatted .bib file
%% requires that the key inserted below matches a key in that .bib file
\documentclass{book}
\usepackage{chicago}
\begin{document}
# batch edit column names based on a particular phrase
# store data in global environment, modify
mpg <- ggplot2::mpg
colnames(mpg) <- paste("depression", colnames(mpg), sep = "_")
# as a function
rename_by_phrase <- function(.data, pattern, replacement){
# modify variable names based on input
@chris-prener
chris-prener / albers_anchorage.R
Last active April 21, 2021 00:36
Locate Anchorage, AK using the albersusa package for R
# find where to locate Anchorage, AK using the albersusa package
# dependencies
library(albersusa) # composite projection
library(dplyr) # data wrangling
library(ggplot2) # mapping
library(mapview) # preview
library(sf) # spatial data
# load composite map
@chris-prener
chris-prener / twoSamplePlot.do
Created October 24, 2016 04:20
Example of Stata plot for a independent sample t-test
// ==========================================================================
// Minimal Working Example - Independent Sample T-Test Plot
// ==========================================================================
// standard opening options
version 14
log close _all
@chris-prener
chris-prener / oneSamplePlot.do
Last active February 4, 2020 22:05
Example of Stata plot for a one sample t-test
// ==========================================================================
// Minimal Working Example - One Sample T-Test Plot
// ==========================================================================
// standard opening options
version 14
log close _all
@chris-prener
chris-prener / bivariateMapping.R
Last active August 28, 2019 05:18
Adaptation of Grossenbacher/Zehr Bivariate Tutorial
# Bivariate Choropleth Map
## this is based on Timo Grossenbacher and Angelo Zehr's tutorial -
## https://timogrossenbacher.ch/2019/04/bivariate-maps-with-ggplot2-and-sf/
# dependencies
library(dplyr) # data wrangling
library(ggplot2) # plotting
library(purrr) # iteration
library(tidyr) # data wrangling
---
title: "SOC 1120-01"
subtitle: "Fall 2019 Attendance"
author: "Christopher Prener, Ph.D."
institute: "Saint Louis University"
date: "2019/08/19 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
# dependencies
library(dplyr)
library(googledrive)
library(lubridate)
library(readr)
library(stringr)
# download form data
forms <- drive_find(pattern = "FA19-01")
@chris-prener
chris-prener / parse-bocks.R
Last active March 9, 2019 02:08
Parse Census Bureau address range data
# Parse Census Bureau address range data
# Problem:
# We need a way to match incidents (that have address-level data) to the blockface they occur on.
# By blockface, I mean the houses on either side of a street between two cross streets (i.e.
# the 100-block of Main Street between 1st and 2nd Avenues).
#
# Typically, census block and city block shapefiles do not represent a blockface. Instead,
# they have parts of up to four different streets, typically representing half of a blockface
# for each of the included streets. So a block bounded by Main Street on the south, 1st Avenue
@chris-prener
chris-prener / rename-files.R
Last active February 17, 2019 01:45
Rename files using purrr+stringr+fs
# These two functions address a common problem in my work - files named "monthYYYY.CSV.html" -
# e.g. "August2018.CSV.html". The prep_dir() function creates a vector of filenames in a given directory
# and then iterates over each using purrr::map(). The map() function calls our second function, edit_filename().
# For each time it is called, edit_filename() uses the magic of stringr and fs (okay, it isn't really magic)
# to rename the file appropriately.
# dependencies:
# install.packages(c("fs", "magrittr", "purrr", "stringr"))
# include in script: