Skip to content

Instantly share code, notes, and snippets.

@aschleg
aschleg / games_howell.R
Last active November 29, 2017 00:07
R function for performing Games-Howell Post-Hoc Test
games.howell <- function(grp, obs) {
#Create combinations
combs <- combn(unique(grp), 2)
# Statistics that will be used throughout the calculations:
# n = sample size of each group
# groups = number of groups in data
# Mean = means of each group sample
# std = variance of each group sample
@aschleg
aschleg / download_soda_api_data.py
Last active March 12, 2018 17:30
Simple script for extracting Socrata Open Data Access (SODA) datasets.
"""
Simple script for extracting Socrata Open Data Access (SODA) datasets. Compatible with 3+, though one can easily make it 2.7
compatible by changing the `from urllib.error import HTTPError` import to `from urllib2 import HTTPError`
Parameters
----------
endpoint : string
SODA API endpoint of the dataset.
count : int, default 1000
@aschleg
aschleg / austin_animal_center_dataset_analysis_functions.py
Created March 29, 2018 01:30
Functions used in series of analyses on the Austin Animal Center's animal intakes and outcomes datasets.
import requests
import numpy as np
import pandas as pd
from six.moves.urllib.error import HTTPError
def get_soda_api_data(endpoint, count=1000, offset=0, return_df=True):
params = {'$limit': count, '$offset': offset}
results = []
@aschleg
aschleg / linear_regression_R_example
Created March 14, 2015 21:22
Quick examples of different types of regression using R. The datasets used for each are available in all R distributions.
library(caret)
ginzberg <- read.csv('D:/Google_Drive/Google_Drive/Resources/Datasets/Rdata/car/Ginzberg.csv')
ginzberg <- ginzberg[2:4]
train <- createDataPartition(y = ginzberg$depression,
p = 0.50,
list = FALSE)
training <- ginzberg[ train,]
@aschleg
aschleg / Wordpress portfolio template with Isotope and Bootstrap
Last active September 2, 2020 00:44
When creating a custom Wordpress theme with Bootstrap, it took me forever for it to play nicely with the Isotope plugin for image filtering. Wanted to share in hopes it helps others.
<!--PHP file for adding a basic template portfolio page for Wordpress themes using the Bootstrap framework.-->
<?php
/*
Template Name: Portfolio
*/
?>
<?php get_header(); ?>
@aschleg
aschleg / lagrangian_interpolation.R
Created June 24, 2017 15:22
R function for performing Lagrangian polynomial interpolation
# Function for performing Lagrangian polynomial interpolation https://en.wikipedia.org/wiki/Lagrange_polynomial.
# Requires the package rSymPy https://cran.r-project.org/web/packages/rSymPy/index.html.
# Parameters:
# x: x values of interpolating points
# y: values corresponding to x values
# Returns:
# Simplified interpolated polynomial that passes through the given x and y points
lagrange.poly <- function(x, y) {
@aschleg
aschleg / Merge_Excel_Workbooks
Last active March 20, 2022 20:44
Merge first worksheet in all Excel workbooks in a folder
from xlwings import Workbook, Range
import pandas as pd
import os
import re
# Script to merge a folder containing Excel workbooks into a single workbook.
# The folder should only contain Excel workbooks and must all either be in csv, xls or xlsx format
# To run, open the command prompt and enter the command python Merge_Excel_Workbooks.py
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@aschleg
aschleg / split_excel_worksheets_v2.py
Last active June 1, 2022 18:11
Alternative method to split Excel worksheet into multiple worksheets based on column name
from xlwings import Workbook, Range, Sheet
import pandas as pd
import os
# Alternative method to split an Excel worksheet into multiple sheets based on a column name.
# The script will prompt four questions to enter in the required information. The workbook will then open and
# split the prompted worksheet into separate worksheets based on the desired column name.
# To run, open the command prompt and enter the command python Split_Excel_Worksheet_v2.py
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@aschleg
aschleg / split_excel_worksheet.py
Created April 11, 2015 02:52
Split Excel worksheet into multiple worksheets based on column name
from xlwings import Workbook, Range, Sheet
import pandas as pd
# Split Excel data in one worksheet into multiple worksheets based on column name.
# Copy this file into the same location as the Excel workbook with the worksheet you wish to split.
# Download the zip of the xlwings Github repo here: https://github.com/ZoomerAnalytics/xlwings and copy the
# xlwings.bas file from the xlwings folder. Import the xlwings.bas file into your Excel workbook by entering ALT+F11
# and then going to File, Import File and clicking on the file.
# Import the Split_Excel_Worksheet.bas file and run by going to the Developer tab on the Excel Ribbon, click Macros,
@aschleg
aschleg / confidence_prediction_intervals.R
Created July 12, 2016 14:07
Functions for calculating the confidence and prediction intervals of a fitted linear regression model. The linear.reg.conf.interval() function outputs a base R graphics scatterplot with a fitted linear line and confidence interval.
# Function for calculating the confidence (mean) and prediction intervals of a fitted linear regression model.
# Replicates the predict() function with arguments 'confidence' and 'prediction'
# Used in post demonstrating the confidence and prediction intervals in linear regression: http://www.aaronschlegel.com/notebook/confidence-prediction-intervals/
# Takes three arguments:
# x = vector of independent variable data points
# y = vector of dependent variable data points
# pred.x = value of x to find predicted y
conf.pred.intervals <- function(x, y, pred.x) {