library(tidyverse)
library(brms)
library(Amelia)
library(broom)
set.seed(1234)
data("africa")
# Impute missing data with Amelia (since it handles country/year panel stuff really well)
This file contains hidden or 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
##' Create an sf POINT column from long and lat columns | |
##' | |
##' This is a vectorised function that takes 2 columns of longitude and latitude | |
##' as arguments and returns a simple features geometry collection column in the | |
##' EPSG 4326 coordinate reference system (lon, lat). | |
##' | |
##' @title lon_lat_to_point | |
##' @param lon a numeric column of longitudes | |
##' @param lat a numeric column of latitudes | |
##' @return a simple features collection column of POINT geometries representing the lon/lat pairs. |
This file contains hidden or 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
# cool bash codes | |
# search a directory for all lines that match a pattern (not perfect but useful) ------ | |
## e.g. grep is searching for all lines matching "::" in `R/` to determine package calls | |
## -h hides the file names; -i ignores case | |
## sed -E uses regular expressions to search and match groups; | |
## we then sort and use -u | |
grep -hi :: -R R/* | sed -E 's/(.*)([ ]+[a-z]+::)(.*)/\2/g' | sort -u | |
# COUNT COLUMNS ----------------- |
This file contains hidden or 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
#=============================================================================== | |
# 2020-04-08 -- twitter upd 2023-01-01 ik-q | |
# Showcase the map hack -- use border lines instead of polygon outlines | |
# https://twitter.com/ikashnitsky/status/1247875600305598464 | |
# https://ikashnitsky.github.io/2023/map-borders | |
# Ilya Kashnitsky, [email protected] | |
#=============================================================================== | |
library(tidyverse) | |
library(sf) |
This file contains hidden or 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
# ---------------------------------------------------- | |
# Installing packages for new R version. | |
# Michael DeCrescenzo | |
# | |
# Hi, I'm a political science PhD student looking for | |
# a data science/quantitative research/statistics job. | |
# Learn more at <mikedecr.github.io> and <github.com/mikedecr> | |
# | |
# This script deals with the following problem: | |
# I upgraded to new major version of R, & I want to reinstall packages. |
This file contains hidden or 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
# make certain jsonlite is available | |
if(!require(jsonlite, quietly = TRUE)) { | |
install.packages("jsonlite") | |
library(jsonlite) | |
} | |
# get the path to settings file | |
path <- if (Sys.info()[["sysname"]] == "Windows") { | |
paste0(Sys.getenv('APPDATA'), "\\RStudio\\rstudio-prefs.json") | |
} else { |
This file contains hidden or 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
--- | |
title: "Power and precision" | |
author: "Richard D. Morey" | |
date: "11/06/2020" | |
output: | |
html_document: | |
dev: png | |
self_contained: no | |
editor_options: | |
chunk_output_type: console |
This file contains hidden or 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
# further to https://urbandemographics.blogspot.com/2016/04/creating-tilted-and-stacked-maps-in-r.html, | |
# an sf-friendly approach. | |
library(sf) | |
nc <- st_read(system.file('shape/nc.shp', package = 'sf')) | |
plot(nc) | |
sm <- matrix(c(2, 1.2, 0, 1), 2, 2) |
This file contains hidden or 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
#!/bin/bash | |
funzip $1| # uncompress first file in zip | |
tr -d '\000' | #remove null characters | |
sed "/^\s*$/d; s/ \{1,\}\t/\t/g; s/\t \{1,\}/\t/g; s/\r//" | #removes empty lines, whitespace around tabs, extra newlines | |
cut -s -f 1,3,4,5,6,8,12,13,14,15,16,17,18,19,20,21,23,24,25,26,34,35,36,38,40,42,44,45,46,85,86,87,88,89 #| #only select certain columns | |
pv -N Process -c | | |
gzip -9 | | |
pv -N Compress -c > $1.gz |
This file contains hidden or 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
#I wrote this code to produce the graphics used in the public policy report, "Will the Arts Come Marching In? Access to Arts Education in Post-Katrina New Orleans," by Sarah Woodward of Tulane University. Read the report here: https://educationresearchalliancenola.org/files/publications/20200915-Woodward-Will-the-Arts-Come-Marching-in-Access-to-Arts-Education-in-Post-Katrina-New-Orleans.pdf | |
library(readxl) | |
library(tidyverse) | |
library(ggplot2) | |
library(extrafont) | |
library(scales) | |
library(grid) | |
library(stringr) #lets you use str_wrap() |