Skip to content

Instantly share code, notes, and snippets.

View AndrewTheTM's full-sized avatar
🏃‍♂️

Andrew Rohne AndrewTheTM

🏃‍♂️
View GitHub Profile
@AndrewTheTM
AndrewTheTM / IterErrStat.R
Created March 5, 2014 14:22
Iterate through DBF files and run a few summary statistics
library(foreign)
library(ggplot2)
#This is where my files are at
setwd("C:\\Modelrun\\10a10b10a08aV80")
#This is the data frame that will hold the output statistics
stats<-data.frame(iter=1:99,mae=0,mse=0)
#Loop through files
@AndrewTheTM
AndrewTheTM / AutoOwnership.R
Created July 25, 2014 15:19
Simple Random Survey Sampler
#
# AutoOwnership.R
# Estimates an auto ownership model
#
# requires: run ProcessTSkim.R first
library(foreign)
HH<-subset(read.dbf("data/hhdbf4.dbf"),INCOME<=4)
HHSamp<-HH[0,]
HHTest<-HH[0,]
s=1
t=1
for(i in 1:4){
print(paste(c("Income ",i),collapse=""))
for(a in 0:4){
print(paste(c("Autos ",a),collapse=""))
ss=subset(HH,TOTVEH==a & INCOME==i)
if(nrow(ss)<10 & nrow(ss)>=2){
@AndrewTheTM
AndrewTheTM / jsonTemp.R
Created November 3, 2014 13:27
Reading a JSON temperature sensor from Phant with R.
library(rjson)
library(ggplot2)
library(reshape2)
url<-'http://www.siliconcreek.net/jsonFiles/2B63LXLE3gfMaYqjGELesD0djGk.json'
dat<-fromJSON(file=url, method='C')
datdf=lapply(dat,ldply)
datdf=ldply(datdf)
datdf$obsId=rep(1:(nrow(datdf)/3),each=3)
datdf<-dcast(datdf,obsId~.id,value.var="V1")
pTemp=ggplot(datdf,aes(x=timestamp,y=temp))+geom_point()
library(foreach)
countData<-list.files(path="data/",pattern="*.csv")
fileList<-foreach(f=files,.combine="rbind") %do% {
return(read.csv(paste("data/",f,sep="")))
}
# My files are stored in the data subfolder relative to the script location, and they are all .csv files.
# Reads log files and generates statistics and pretty charts about the closure
library(stringr)
library(ggplot2)
library(scales)
# Folder for my model. Change this!
modelFolder="C:/Modelrun/GitModel80/Base/"
# Reads print files from assignment steps. Change the filenames!
@AndrewTheTM
AndrewTheTM / TLFExample.R
Created May 8, 2015 14:14
Example of Trip Length Frequencies in R
source("00Keys.R")
source("http://raw.githubusercontent.com/osPlanning/omx/dev/api/r/omx.R")
library(ggplot2)
library(plyr)
hskimpk=readMatrixOMX(paste(modelFolder,"HSKIM_PK1.OMX",sep=""),"TIME")
askimam=readMatrixOMX(paste(modelFolder,"AMAsn.OMX",sep=""),"TIME")
H5close()
@AndrewTheTM
AndrewTheTM / NPMAT00B
Created July 24, 2015 15:00
Voyager Pearsons Correlation Coefficient
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=MATRIX PRNFILE="C:\MODELRUN\TRUCKMODEL\CUBE\NPMAT00A.PRN"
FILEO PRINTO[1] = "C:\Modelrun\TruckModel\Cube\Inputs\InitStats.RPT"
FILEI DBI[1] = "C:\Modelrun\TruckModel\Cube\Inputs\TrucksLoaded.DBF"
PAR ZONES = 1
LOOP r = 1, DBI.1.NUMRECORDS
x=DBIReadRecord(1, r)
IF(DI.1.TSCN > 0)
@AndrewTheTM
AndrewTheTM / ReadExcel.R
Created September 16, 2015 13:03
Code to read an Excel file in R
library(openxlsx)
dat<-read.xlsx("file path","Sheetname")
# Optionally, add startRow = 13, possibly colNames=F
@AndrewTheTM
AndrewTheTM / getCensusJSON.py
Created July 16, 2012 14:13
Read Census Data via Python
import json,urllib,cairoplot
url='http://thedataweb.rm.census.gov/data/2010/sf1?key={YOUR_KEY_HERE}&get=P0010001,NAME&for=county:025,017,061,165&in=state:39'
result=json.load(urllib.urlopen(url))
graphData=[]
graphLabels=[]
for row in result: