This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gaussFiltered = gaussFilter1D(m, sigma) | |
cutoff = ceil(3*sigma); | |
h = fspecial('gaussian',[1,2*cutoff+1],sigma); % 1D filter | |
gaussFiltered = conv2(h,h,m,'same'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function normalised = normaliseXY(array, x, y) | |
% Normalize to [0, 1]: | |
m = min(array(:)); | |
range = max(array(:)) - m; | |
array = (array - m) ./ range; | |
% Then scale to [x,y]: | |
rangeXY = y - x; | |
normalised = (array*rangeXY) + x; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function y = jitter(x, factor, uniformOrGaussianFlag, smallOrRangeFlag, realOrImaginaryFlag) | |
% Adds a small amount of noise to an input vector, matrix or N-D array. The | |
% noise can be uniformly or normally distributed, and can have a magnitude | |
% based upon the range of values of X, or based upon the smallest | |
% difference between values of X (excluding 'fuzz'). | |
% | |
% NOTE: This function accepts complex values for the first input, X. If | |
% any values of X have imaginary components (even zero-valued imaginary | |
% components), then by default the noise will be imaginary. Otherwise, the | |
% default is for real noise. You can choose between real and imaginary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [h,xy]=hextile(rect,size) | |
% hextile(rect,size) | |
% rect - [x y w h] | |
% size - distance between hexes (default 1) | |
% returns | |
% h - plot handle | |
% xy - centers of all hexagons drawn | |
[x,y,w,h] = deal(rect(1),rect(2),rect(3),rect(4)); | |
if nargin < 2, size = 1; end | |
[c,s]=deal(cos(pi/6),sin(pi/6)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Please note, this script requires answers to be coded as "A" for agree, or "D" for disagree ### | |
AQ[,1:50]<-as.character(unlist(AQ[,1:50])) # recode to character | |
AQAnswers<-c('D','A','D','A','A','A','A','D','A','D','D','A','A','D','D','A','D','A','A','A','A','A','A','D','D','A','D','D','D','D','D','D','A','D','A','D','D','D','A','D','A','A','A','D','A','A','D','D','D','D') # create key for AQ | |
AQ<-data.frame(lapply(AQ, as.character), stringsAsFactors=FALSE) # convert df AQ to characters to enable matching by grepl | |
AQ<-as.data.frame(mapply(grepl,AQAnswers,AQ))*1 # calculate AQ score | |
# Subscales | |
AQ$AQ.socialSkill<-apply(AQ[,c(1,11,13,15,22,36,44,47:48)],1,sum) | |
AQ$AQ.attentionSwitching<-apply(AQ[,c(2,4,10,16,25,32,34,37,43,46)],1,sum) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> crossedBaselineRT | |
PTB-INFO: Display ':0.0' : X-Screen 0 : Assigning primary output as 2 with RandR-CRTC 0 and GPU-CRTC 0. | |
put in name test | |
PTB-INFO: This is Psychtoolbox-3 for GNU/Linux X11, under Matlab 64-Bit (Version 3.0.11 - Build date: Dec 29 2013). | |
PTB-INFO: Type 'PsychtoolboxVersion' for more detailed version information. | |
PTB-INFO: Most parts of the Psychtoolbox distribution are licensed to you under terms of the MIT License, with | |
PTB-INFO: some restrictions. See file 'License.txt' in the Psychtoolbox root folder for the exact licensing conditions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
corstars <- function(x){ | |
require(Hmisc) | |
x <- as.matrix(x) | |
R <- rcorr(x)$r | |
p <- rcorr(x)$P | |
mystars <- ifelse(p < .01, "**|", ifelse(p < .05, "* |", " |")) | |
R <- format(round(cbind(rep(-1.111, ncol(x)), R), 3))[,-1] | |
Rnew <- matrix(paste(R, mystars, sep=""), ncol=ncol(x)) | |
diag(Rnew) <- paste(diag(R), " |", sep="") | |
rownames(Rnew) <- colnames(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# check.packages function: install and load multiple R packages. | |
# Check to see if packages are installed. Install them if they are not, then load them into the R session. | |
check.packages <- function(pkg){ | |
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])] | |
if (length(new.pkg)) | |
install.packages(new.pkg, dependencies = TRUE) | |
sapply(pkg, require, character.only = TRUE) | |
} | |
# Usage example |
NewerOlder