Skip to content

Instantly share code, notes, and snippets.

View brockf's full-sized avatar

Brock Ferguson brockf

View GitHub Profile
@brockf
brockf / lmer-raw-vs-agg.R
Created April 11, 2016 18:54
Compare Type 1 error rates for within-subject factor in a multi-level model between a (1) unaggregated, 'raw' model and a, (2) aggregated by subjects model.
library(lme4)
library(dplyr)
library(broom)
p_vals <- lapply(1:1000, function (x) {
df <- expand.grid(
subject = 1:30,
trial = 1:8,
condition = c('Control','Experimental')
)
@brockf
brockf / concatenate-file-paths-from-codeigniter-directory-map.php
Created April 6, 2016 21:12
Concatenate output from a CodeIgniter directory_map() array into a single array of file paths.
<?php
$map = directory_map('/path/to/folder/');
$file_paths = concatenate_filepaths($map);
function concatenate_filepaths ($map, $prefix = '') {
$return = array();
foreach ($map as $key => $file) {
if (is_array($file)) {
# create demo dataframe
data <- data.frame(
obs = 1:20,
value = rbinom(20, 2, .5)
)
# calculate runs of duplicate values
runs <- rle(data$value)
# create cluster vector use runs
@brockf
brockf / brief-eyetrackingR-example.R
Last active September 29, 2015 21:43
A brief example of eyetrackingR
# load *eyetrackingR* and set data options
library(eyetrackingR)
data_options = set_data_options(item_columns = "Trial", trial_column = "Trial", time_column = "TimeFromPhaseOnset", trackloss_column = "TrackLoss", aoi_columns = c('Animate','Inanimate'), participant_column = "ParticipantName")
# verify colums in dataset
master_clean <- verify_dataset(master_clean, data_options)
# analyze and remove trackloss-ridden trials
master_clean <- convert_non_aoi_to_trackloss(master_clean, data_options)
@brockf
brockf / beepr-mario.R
Last active August 29, 2015 14:25
Play the Mario "level complete" sound after running R code
library(beepr)
# ...run something that takes a long time...
beep(8);
@brockf
brockf / webpage_filesize.php
Last active August 29, 2015 14:05
Calculate the total download size for a webpage, including loaded images, scripts, and links
<?php
// webpage_filesize()
//
// returns the total number of Bytes downloaded
// when a single webpage is accessed without any caching
//
// requires: cURL
//
// @param string $url (e.g., 'http://www.cbc.ca')