Skip to content

Instantly share code, notes, and snippets.

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

Andrew Rohne AndrewTheTM

🏃‍♂️
View GitHub Profile
@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 / 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()
# 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!
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.
@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()
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 / 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)
@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 / KExample.r
Created December 6, 2013 14:50
Code used to illustrate effects of K factors.
########################################
# K Factor Example #
########################################
# Apply the gravity model
gravity<-function(T0,f,k){
Zones=nrow(T0)
T1<-matrix(0,Zones,Zones)
for(i in 1:Zones){
P=sum(T0[i,])
@AndrewTheTM
AndrewTheTM / gravmodel.r
Created November 25, 2013 13:27
Gravity model example
# Test data for Philip A. Viton's examples from
# http://facweb.knowlton.ohio-state.edu/pviton/courses2/crp5700/Gravity-beamer.pdf
# ARohne 11/22/2013
Zones=3
#Trip data
T0<-matrix(0,Zones,Zones)
T0[1,1]=100
T0[1,2]=350