Skip to content

Instantly share code, notes, and snippets.

View andrewheiss's full-sized avatar
👨‍💻
#rstats-ing all the things

Andrew Heiss andrewheiss

👨‍💻
#rstats-ing all the things
View GitHub Profile
@andrewheiss
andrewheiss / Regex-Excel
Created December 11, 2010 07:51
How to use regular expressions in Excel
' Using Regex Functions in Excel
'http://lispy.wordpress.com/2008/10/17/using-regex-functions-in-excel/
' Turn on VBScript Regular Expressions 5.5 reference thing
Function M(Value As String, Pattern As String, Optional IgnoreCase As Boolean = False)
Dim r As New VBScript_RegExp_55.RegExp
r.Pattern = Pattern
@andrewheiss
andrewheiss / gist:799611
Created January 28, 2011 00:45
Sample letter to Congress
Rep. X,
Over the past several weeks there has been massive political unrest throughout the Middle East. As you know, Tunisia overthrew President Ben Ali a week ago, igniting a series of peaceful protests in Egypt, Algeria, Yemen, and other Middle Eastern nations.
Egypt has been in the throes of protests for 3 days now with nary a word from the US. Egypt is one of America's biggest allies in the region and has been a keystone of our foreign policy for decades.
President Mubarak's regime is attacking these protestors violently. Several Egyptians have been killed—hundreds have been arrested without due process or reason. And yet the US remains silent.
In the past hour, the Egyptian government has shut off all internet and SMS communications. Key cities, such as Suez, have had all landlines cut off. Egypt is in a black hole, giving Mubarak a free ticket to be as oppressive and violent as he wants with no immediate international repercussions.
@andrewheiss
andrewheiss / gist:886360
Created March 25, 2011 04:22
jmp stuff
Fit Model(
Y( :CRIMARST ),
Effects( :UNEMPL, :MONTH, :CURFEW, :POLICCUR ),
Personality( Standard Least Squares ),
Emphasis( Effect Leverage ),
Run(
:CRIMARST << {Plot Actual by Predicted( 1 ), Plot Regression( 0 ),
Plot Residual by Predicted( 1 ), Plot Effect Leverage( 1 ), Show VIF( 1 )}
)
);
@andrewheiss
andrewheiss / generate_ics.vbs
Created September 3, 2011 20:03
Convert a list of birthdays to a recurring iCal file (column A = event name; column B = date)
Sub Generate_ICS()
Dim rng1 As Range, X, i As Long, v As Long
Dim objFSO, objFile
Dim FilePath As String
FilePath = "C:\output.ics"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(FilePath)
Set rng1 = Range([a2], Cells(Rows.Count, "B").End(xlUp))
X = rng1
@andrewheiss
andrewheiss / mmd2docx
Created September 7, 2011 02:23
mmd2docx
#!/usr/bin/env bash
#
#-----------
# mmd2docx
#-----------
#
# Author: Andrew Heiss - http://www.andrewheiss.com
# Project site: http://gist.github.com/1199596
# Description: Convert MultiMarkdown files into docx files using LibreOffice
# License: Licensed under the MIT License (see below)
Option Explicit
Sub switch_row()
Dim colors() As Variant
Dim current_color, i, new_index As Long
' Set up color array
colors = Array(2, 3, 4, 6, 7, 8)
@andrewheiss
andrewheiss / gist:1947224
Created March 1, 2012 04:13
Cool R summary
coolSummary <- function(x) {
if (class(x) == "data.frame") {
x.min <- apply(x, 2, min, na.rm=TRUE)
x.max <- apply(x, 2, max, na.rm=TRUE)
x.sd <- apply(x, 2, sd, na.rm=TRUE)
x.mean <- as.numeric(lapply(x, mean, na.rm=TRUE))
x.n <- apply(!is.na(x), 2, sum)
x.na <- apply(is.na(x), 2, sum)
row.names <- colnames(x)
} else {
@andrewheiss
andrewheiss / gist:2229633
Created March 28, 2012 19:18
lm summary with beta coefficients
summary.with.betas <- function(model, logit=FALSE) {
model <- update(model, x=TRUE, y=TRUE)
sd.x <- apply(model$x, 2, sd)
sd.y <- sd(model$y)
std.coef <- coef(model) * (sd.x / sd.y)
coef.table <- as.data.frame(summary(model)$coefficients)
coef.table <- cbind(coef.table, beta=std.coef, sdX=sd.x)
if (logit == TRUE) {
e.beta <- exp(coefficients(model))
e.bstdx <- exp(sd.x)
@andrewheiss
andrewheiss / gist:2242089
Created March 29, 2012 18:58
Tax forecasting
library(forecast)
budgetData <- read.csv(file.choose())
(series.ts <- ts(budgetData$taxTotals, start=c(1978, 1), frequency=4))
series.ets <- ets(series.ts, model="ZZZ")
series.forecast <- forecast(series.ets, h=5)
plot(series.forecast)
@andrewheiss
andrewheiss / lrm.R
Created March 31, 2012 04:50
Ordinal logistic regression
library(rms) # This is the library that does all the orginal logistic regression magic
EMC <- latest.EMC.2011.clean.v2 # Make a copy of the data frame with a shorter name
model <- lrm(lifeoverall ~ fire + med + streetrepair + streetclean, data=EMC) # Fit an ordinal logistic regression model
model # General model summary
exp(coefficients(model)) # Factor change coefficients?
anova(model) # Wald statistics
Predict(model, fire=0, med=0, streetrepair=0, streetclean=0) # Predict yhat based on given values