Skip to content

Instantly share code, notes, and snippets.

View kylebgorman's full-sized avatar

Kyle Gorman kylebgorman

View GitHub Profile
@kylebgorman
kylebgorman / WALS131A.R
Last active January 22, 2023 16:27
Tests the hypothesis that vigesimal (base-20) number systems are more common at tropical latitudes
#!/usr/bin/env Rscript
# WALS131A.R
# Kyle Gorman <[email protected]>
#
# Tests the hypothesis that vigesimal (base-20) number systems are more common
# at tropical latitudes. Thanks to Richard Sproat for suggesting this
# hypothesis.
#
# The data is read directly from WALS (#131A):
#
@ctw
ctw / wagnerfischerpp.py
Last active February 8, 2016 17:44 — forked from kylebgorman/wagnerfischerpp.py
Wagner-Fischer Levenshtein distance, now with a means to generate all possible optimal alignments.
#!/usr/bin/env python
#
# Copyright (c) 2013-2014 Kyle Gorman
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
@kylebgorman
kylebgorman / ratio.pyx
Last active October 8, 2019 15:58
Log-likelihood ratio test in Cython, using scipy for distribution functions.
"""Functions for computing log-likelihood ratio statistics."""
from libc.math cimport log
from scipy.stats import binom
from scipy.stats import chi2
cpdef double LLR(int c_a, int c_b, int c_ab, int n):
@kylebgorman
kylebgorman / wcm.py
Created November 4, 2015 02:49
Stole-Gammon word complexity measure (WCM)
#!/usr/bin/env python
#
# Copyright (c) 2014 Kyle Gorman
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
@kylebgorman
kylebgorman / bktree.py
Created November 4, 2015 02:48
Burkhard-Keller trees
# Copyright (c) 2014-2015 Kyle Gorman <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
@kylebgorman
kylebgorman / mcnemar.py
Last active February 11, 2020 18:46
Compute McNemar's test (two two-sided variants) in Python
import scipy.stats
def mcnemar_p(n1: int, n2: int) -> float:
"""Computes McNemar's test.
Args:
n1: the number of "wins" for the first condition.
n2: the number of "wins" for the second condition.
@kylebgorman
kylebgorman / wagnerfischerpp.py
Last active March 3, 2023 17:27
Wagner-Fischer Levenshtein distance, now with a means to generate all possible optimal alignments.
# Copyright (c) 2013-2022 Kyle Gorman
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
@kylebgorman
kylebgorman / autoloess.R
Last active November 28, 2022 16:06
autoloess.R: set the "span" (smoothing) hyperparameter for a LOESS curve so as to minimize AIC_c (includes a cute demonstration)
# autoloess.R: compute loess metaparameters automatically
# Kyle Gorman <[email protected]>
aicc.loess <- function(fit) {
# compute AIC_C for a LOESS fit, from:
#
# Hurvich, C.M., Simonoff, J.S., and Tsai, C. L. 1998. Smoothing
# parameter selection in nonparametric regression using an improved
# Akaike Information Criterion. Journal of the Royal Statistical
# Society B 60: 271–293.
@kylebgorman
kylebgorman / .vimrc
Last active February 27, 2025 19:13
my .vimrc (pretty basic)
syn on
set ruler
" tab stuff
set expandtab
set hlsearch
set tabstop=4
" scrolling
set scrolloff=5
" backspace over everythign
set backspace=indent,eol,start
@kylebgorman
kylebgorman / em2gaus.py
Created June 26, 2012 00:02
EM for a mixture of 2 univariate Gaussians
#!/usr/bin/env python
#
# Copyright (c) 2012 Kyle Gorman
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions: