Skip to content

Instantly share code, notes, and snippets.

View mike-lawrence's full-sized avatar

Mike Lawrence mike-lawrence

  • Halifax, Nova Scotia, Canada
View GitHub Profile
@mike-lawrence
mike-lawrence / code.R
Created August 30, 2011 08:39
lmer factors vs ordered
library(lme4)
a = dget('data.txt')
#this should yield an error
m1 = lmer(
formula = rt ~ (1|id) + arrow*tone*flanker*sstroop*target*location
, data = a
)
b = a
@mike-lawrence
mike-lawrence / lmer_oneway_sim.R
Created October 29, 2011 14:33
lmer_oneway_sim
library(plyr)
library(MASS)
library(lme4a)
generate_data = function(
n # number of units
, k # number of trials within each condition within each unit
, noise # measurement noise variance
, I # population intercept
, vI # across-units variance of intercepts
@mike-lawrence
mike-lawrence / multiprocessingPygameIO.py
Created November 12, 2011 09:20
Example of using multiprocessing module for seperating input and output from a main pygame display loop. The code creates a window that displays any key that is typed (escape quits) and writes data to a file called "output.txt" containing some timing data
#import used modules
import pygame
import sys
import time
import multiprocessing
#initialize pygame
pygame.init()
#create a window
@mike-lawrence
mike-lawrence / Apple crash report.txt
Created November 12, 2011 17:01
Pygame multiprocessing errors on 10.7.2
Process: Python [28444]
Path: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Identifier: Python
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: Python [28443]
PlugIn Path: /Library/Frameworks/SDL.framework/Versions/A/SDL
PlugIn Identifier: SDL
PlugIn Version: 1.2.14 (1.2.14)
@mike-lawrence
mike-lawrence / lmer_oneway_Gaussian.R
Created November 16, 2011 13:03
Simulating a mixed effects model with one random effect, one fixed effect. Gaussian and binomial versions.
library(MASS)
library(lme4)
generate_data = function(
n # number of units
, k # number of trials within each condition within each unit
, noise # measurement noise variance
, I # population intercept
, vI # across-units variance of intercepts
, A # population A effect
@mike-lawrence
mike-lawrence / PygameMultiprocessingIO.py
Created November 18, 2011 01:11
pygame & multiprocessing for IO
#import used modules
import sys
import time
import multiprocessing
#create a multiprocessing Queue object for sending messages to an input process
queueToInputProcess = multiprocessing.Queue()
#create a multiprocessing Queue object for receiving messages from an input process
@mike-lawrence
mike-lawrence / analysis.R
Created November 30, 2011 16:55
raw scores vs difference scores
#see file `dput_of_a.R` below this file for the data object `a`
#load helpful libraries
library(MASS)
library(plyr)
library(reshape)
library(lme4)
########
# Method 1: Model and sample, then collapse
#load doMC for parallelism
library(doMC)
options(cores=4) #adjust to match your system
registerDoMC()
#load plyr to use doMC implicitly
library(plyr)
#load the toy data set
source('data.R')
@mike-lawrence
mike-lawrence / CEEMD.R
Created December 31, 2011 04:25
Complimentary Ensemble Empirical Mode Decomposition
#Functions (and contents) that need to be converted to OpenCL: extrema, envelope, extractimf, emd
#function to find the extrema indices of a time series, y.
extrema = function(y){
ny = length(y)
nym1 = ny-1
maxindex = NULL
minindex = NULL
slope_signs = sign(diff(y))
if(slope_signs[1]==1){
@mike-lawrence
mike-lawrence / main.py
Created January 5, 2012 13:56
Pygame & SimpleCV crashing/segfaulting
window_res = (800,600)
detection_image_scale = 4 #faster & more reliable to shrink the image before face detection
pupil_threshold = 240
cam_scale = 1
import pygame
import time
import sys
import cv