# Code for psychological tasks

Online questionnaires, assessment and training. System for running online experiments. The code provides an example of an Attentional Bias Modification design including timed invitations to sessions via email, questionnaires, a dot-probe task in Javascript, and integration with Sona systems.

Geomaker. The "Warped Circular Motion" algorithm to generate abstract geometric shapes for stimuli, from basic regular polygons to weird wobbly vaguely organic Rorschach-y shapes. Defines a possibly useful distance between shapes in terms of their parameters, which can be smoothly varied for animations. Implemented in R.

# Data analysis functions

## Statistics and machine learning

teg_regr_tests. R function for testing linear hypotheses on regression coefficients using F-tests. Provides p-values and the AIC.

teg_bonsai. Regression tree function in Python/NumPy, with generation of (hierarchical) p-values and optional variations such as a "peek ahead" variation that looks one step ahead and can deal with XOR relationships, auto-selections of the alpha parameter, and cross-validation to select trees.

teg_nncorr. Non-linear neighbourhood correlation (in R). Detects any functional trend between x and y, e.g., U-curves or cosines.

tegregr. Multiple and hierarchical linear regression function in Python, providing typical statistical output for experimental research.

NumNomS. Permutation-based set-wise multiple correction method that aims to balance statistical power with precise information (in R). Could be useful in situations in which it might not matter exactly which tests are and are not significant, but it does matter whether some of them are. The code also provides a permutation-based critical p-value with familywise error rate control that takes dependencies between variables into account; this can be much more powerful than Bonferroni correction (imagine the toy example that you just copied one variable a hundred times - you don't actually need to adjust the critical p-value at all, regardless of how many copies you have).

teg_RMA. Repeated measures analyses in Matlab (be aware of implementation details!).

teg_regression. Basic linear regression in Matlab.

teg_crosstab. Crosstab and Chi squared test (automatically removes rows or columns with low expected counts).

teg_ftest. F-test.

teg_ttest. One-sample t-test.

teg_ttest2. Independent samples t-test.

teg_PCA. Returns principal components using the NIPALS algorithm: avoids having to make the covariance matrix so it's usable where the normal method would cause an Out of Memory error.

teg_scree. Function for getting the scree citerion for PCA.

## Data preprocessing and transformations

Psychophysiological Interactions (PPI). Function for running a PPI analysis.

teg_calc_D600. Calculates the D600 score for IAT data.

hiro3. Interactive plot program for resliced SPM data. Includes blob identification, anatomical labelling, command-line PPI function.

Aztec. Removes physiological confounds from fMRI data.

antici. Evolving EEG toolbox and GUI.

textToValueRecoder. Function to recode questionnaire data saved as the text of response options into numerical values.

## Signal processing

EZfilt. Simple (or just oversimplistic...) filtering function.

Wavelet toolbox. A basic toolbox (integrated in antici) for doing wavelet analysis. The functions provide transformations of vectors to instantaneous amplitude and phase-difference vectors, and averaging to event-related amplitude and the PLV. There's also a data-simulator and example program.

## Input / Output

teg_parse2nested. Reads ASCII trialwise data into nested means per condition.

gen_read_data. Reads binary .BED genetic data.

teg_read. Simple ASCII file reader, for when you might have missing values or non-number elements to ignore. Updated 24 - 05 - 2009.

## Plotting

teg_plot. Basic plotting of lines with error bars from matrices of observations.

teg_stemleaf. Stem-and-leaf plot showing descriptives of vectors.

cLine. Plots lines with standard-error bars.

cvec. An interactive vector-visualization function, allows quick navigation through a vector at changing time scales.

cmat. Util for visualization and manipulation of 3D matrices.

arrow. Function to plot arrows.

tg_pcolor. A 2-D color-coded plotter for matrices adapted from the default function pcolor.

tg_surf3d. Plots a surface in 3D, you specify x, y, z coordinates and associated value and it color-codes it. Nice for EEG scalp maps.

## General

rec_loop. A recursive looping function that allows an arbitrary depth of nested loops.

KESN. Function that finds the optimal partitioning of a set of values.

## Random

Mytrics. Bibliometrics for a given author, including prediction of development of the h-factor and the h5-factor variant of the h-factor.

EmoDet. Emotion Detection program underlying EmpathyBot. Uses a combination of natural language processing functions, including semantic vectors, to detect the emotions associated with a short text.

Trial event function. A function to generate timelines for experiment trials.

Smooth corners. Build a road where corners are replaced by arcs so that the direction is continuous. Example of a function that generates input for roadwarrior3.

Balanced latin square generator. A latin square is an N x N matrix in which every row and column contains exactly one of each of N elements. If the square is balanced, every element is followed and preceded exactly once by each other element. This script generates such squares randomly.

gameSolver. Solves finite strategic games using the pivot method.

Task. Example of how to program a cognitive task.

Dungeon1, my first attempt at Unity! Top-down 3D game, play a wizard escaping a dungeon, usual mouse + WSAD + Space for jump. Powerups improve the fireball-attack or restore health.

Fractals 1. Messing about with visualizing recursive functions. The zip includes the (C++ Builder) source code. Line and Frac toggle two types of recursion. Line gives you virus-like wormish things crawling around. Frac generates a spreading blob. The number in the text box determines the length of elements of the form. Activating "Flow" and clicking Start generates a wave pattern.

Fractals 2. A spreading network. This one's rather sensitive to parameters, and crashing can be a bit spectacular...

Rocky III, neural network simulation environment based on Wang (1999). Includes a scripting language for designing and running networks and their input.