Skip to content

Instantly share code, notes, and snippets.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Name: Tom Fish
DOB: YYYYMMDD
ID: NNNNNN
Issuing Country: United States of America
Issuing Group: Centers for Disease Control and Prevention
-----BEGIN PGP SIGNATURE-----
Version: Keybase OpenPGP v2.1.13
@Guerillero
Guerillero / CensusDataHandler.r
Last active August 17, 2021 02:09
Census Data Handler
library(PL94171)
library(tigris)
library(rgdal)
library(dplyr)
# Simplifed Rename function
renameColums <- function(dat){
a <- rename_with(dat, ~gsub(".x", "_2020", .x))
a <- rename_with(a, ~gsub(".y", "_2010", .x))
}
library(PL94171)
library(tigris)
library(rgdal)
library(dplyr)
va_raw_2020 <- pl_read(pl_url("VA", 2020))
va_2020 <- pl_subset(va_raw_2020, sumlev="140")
va_fin_2020 <- pl_select_standard(va_2020, clean_names = TRUE)
va_tracts_2020 <- tracts("VA", year=2020, progress_bar=FALSE)
vashp_2020 <- full_join(va_fin_2020, va_tracts, by="GEOID")
. brier outcome bitecoffer
Mean probability of outcome 0.5098
of forecast 0.5537
Correlation 0.9167
ROC area 0.9969 p = 0.0000
Brier score 0.0421
Spiegelhalter's z-statistic -0.5024 p = 0.6923
@Guerillero
Guerillero / extractOSMRoads.py
Created October 23, 2020 14:06
Extracts the OSM road data from a directory of country zip files downloaded from geofabrik and names the road layer after the country
# Download data from https://download.geofabrik.de/
import shutil
import os
import zipfile
path = r"C:\\\roadNetwork"
files = os.listdir(r"%s\RAW" % (path))
for fi in files:
rm -rfv homepage
git clone https://github.com/Guerillero/homepage.git
cd homepage/
cp -vr * /var/www/guerillero.net/html/
@Guerillero
Guerillero / DataFromAPI.py
Last active July 12, 2019 17:17
Creates a CSV for each requested survey with subnational data from The DHS Program API to easily join to boundary fiels
import csv
import json
import urllib2
indicators = ["WS_SRCE_P_IMP", "ED_EDUC_W_SEH", "MA_CWIV_W_1WV", "MA_CWIV_W_2PW",
"FE_FRTR_W_TFR", "FE_TNPG_W_CBR", "FP_CUSM_W_MOD", "FP_NADM_W_UNT"]
surveys = ["CM2011DHS", "CF1994DHS", "TD2014DHS", "CG2011DHS"]
for survey in surveys:
@Guerillero
Guerillero / NigeriaMerge.do
Last active October 30, 2018 17:57
Merge an IR file with the GC (points) file in STATA
/******************************************************************************************
* Title: NigeriaMerge.do
* Created by: Tom Fish
* Created on: 30 October 2018
* Purpose: Explan how to merge an IR file with the GC (points) file in STATA
******************************************************************************************/
clear all
set more off
* Set folders that I am working on
@Guerillero
Guerillero / ConvertGCFiles.do
Last active October 30, 2018 18:04
Convert the DHS Geospatial Covariate files from CSV to DTA
/******************************************************************************************
* Title: ConvertGCFiles.do
* Created by: Tom Fish
* Created on: 8 October 2018
* Purpose: Convert the DHS Geospatial Covariate files from CSV to DTA
******************************************************************************************/
clear
*Set paths to the various files
local pathIn = "C:\in"
@Guerillero
Guerillero / OpeningHandProb.do
Last active April 20, 2018 19:28
The probabilities of seeing a particular card in your first opening hand in Magic:The Gathering
forvalues i=1/28{
local Cards = `i'
local Prob = 1-hypergeometric(60,`i',7,0)
display "`Cards' : `Prob'"
}