chronux tutorial: part i hemant bokil cold spring harbor laboratory

40
Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Upload: beverley-mclaughlin

Post on 17-Dec-2015

246 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Chronux Tutorial: Part I

Hemant Bokil

Cold Spring Harbor Laboratory

Page 2: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Peter Andrews

Contributors

Dan Hill Chris Fall Samar Mehta Hirak Parikh Andrew Sornborger

Partha Mitra

Hemant Bokil Catherine Loader

People

Page 3: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Outline Introduction to Chronux

► Aim ► Website

● Download ● Documentation

► Key functions

Analysis of LIP data - Example 2 of the previous talk : rates, spike and LFP spectra and coherences, coherences between cells

Analysis protocol

F-test for line noise

Page 4: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Chronux: Aim

To provide a comprehensive set of tools for the analysis of neurobiological time series data

Page 5: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Current version

Univariate and multivariate time series data.

Continuous data (e.g. LFPs) and point process data (e.g. spikes).

Multiple modalities: Image data (examples in Chris Fall’s talk)

Extensive online and within-Matlab help

GUI under active development, release in a few months

Locfit local regression and likelihood based analyses

Spike sorting

Spectral analysis

MATLAB®

Toolboxes

Page 6: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Website (www.chronux.org)

Page 7: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Documentation

Page 8: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Key routines for continuous processes

Denoising

Slow variations (e.g. movements of a patient for EEG data)

50/60 Hz line noise

locdetrend.m: Loess method rmlinesc.m

rmlinesmovingwinc.m

Page 9: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Spectra, Coherences etc

Local regression and likelihood

Fourier transforms using multiple tapers: mtfftc.m

Spectrum: mtspectrumc.m

Spectrogram: mtspecgramc.mCoherogram:mtcohgramc.m

Coherency:mtcoherencyc.m

Regression and likelihood: locfit.m

Plotting the fit: lfplot.mPlotting local confidence bands: lfband.m

Plotting global confidence bands: scb.m

Page 10: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Chronux data format Continuous/binned point process data

matrices with dimension time x channels/trials

e.g. 1000 x 10 dimensional matrix

interpreted as 1000 samples

10 channels/trials

Spikes times

struct array with dimension = number of channels/trials

e.g. data(1).times=[0.3 0.35 0.42 0.6]

data(2).times=[0.2 0.22 0.35]

2 spike trains with 4 and 3 spikes

Page 11: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Important parameter in mulitple Chronux functions

params: structure with multiple fields

Fs: sampling frequency (slightly different interpretation for spike times

tapers: controls the number of tapers

pad: controls the padding

fpass: frequency range of interest

err: controls error computation

trialave: controls whether or not to average over trials

Page 12: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Example II: Spike rates, spectra and coherence (from the previous lecture)

• Simultaneous two-cell recording from Macaque area LIP – dataset DynNeuroLIP.mat

Reach and

Saccade Task

DelayCueReach andSaccade

Pesaran et al (Unpublished)

DelayCue

Page 13: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Example II

3 local field potentials (LFP) and 2 single units, LFP sampled at 1 kHz

Trial: 3 seconds of data for 9 trials to one of the directions: 1 s (Baseline), 2 s (Delay + post movement)

Baseline: 1 second of data for 74 trials (pooled across all directions)

Page 14: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

TasksCompute the following for the Memory trials

Spike rates

LFP and spike spectra

Spike-field coherence

Spike-Spike coherence

Compare spike-spike coherence during the memory period and the baseline period.

Page 15: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

The main script for this tutorial

lip_master_script.m

Calls other scripts to run through the various analyses

Page 16: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

The main script for this tutorial

lip_master_script.m

Calls other scripts to run through the various analyses

Page 17: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

>> fit=locfit(data,'family','rate');>> lfplot(fit); >> lfband(fit);

Spike rate: 1 trial

Basic locfit usage (rate estimate)

Regression

>> fit=locfit(x,y);

Density estimate:replace 'rate‘ by ‘dens’

Page 18: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

>> fit=locfit(data,'family','rate‘,’nn’,0.3);>> lfplot(fit); >> lfband(fit);

Setting the bandwidth –fixed (h), nearest neighbor (nn)

h: fixed/absolutebandwidth e.g. h=1is interpreted as 1 s if data is in seconds

nn: fixed fraction of the total number of points e.g. nn=0.3 takes the 30% closest points to a given point

Default: nn=0.7, h=0

Page 19: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Multiple trials

pool the spikes and compute fitrescale fits and confidence intervals

Page 20: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

>>[S,f]=mtspectrumc(data);>> plot(f,10*log10(S))

S: spectrumf: frequency

LFP spectrum : mtspectrumc.m

Page 21: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Sampling frequencySet params.FsDefault = 1

>>params.Fs=1000;>>[S,f]=mtspectrumc(data,params);>> plot_vector(S,f);

plot_vector:Allows plottingerrors and choice of color and scale(default: log scalefor S)

>> plot_vector(S,f,’n’);%Uses linear scale for S

Page 22: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Restricting frequencies of interest

Set params.fpassDefault = [0 params.Fs/2]

>>params.Fs=1000;>>params.fpass=[0 100];>>[S,f]=mtspectrumc(data,params);>> plot_vector(S,f)

Page 23: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Changing the padding

Set params.padDefault=0

>> params.pad=2;>>[S,f]=mtspectrumc(data,params);>> plot_vector(S,f)

Allowed values: -1 0 1 2 ...For N=500, NFFT: 500 512 1024 2048 …Default: 0

Page 24: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

>>params.tapers=[5 9];>>[S,f]=mtspectrumc(data,params);>> plot_vector(S,f,[],[],’r’)

Set params.tapers : of the form [TW K] Default = [3 5]

TW: time-bandwidth product K<2TW: well concentrated Slepian sequences

Smoothing (changing the bandwidth)

Page 25: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Averaging over trials

Set params.trialave=1

>> params.trialave=1;>>[S,f]=mtspectrumc(data,params);>> plot_vector(S,f)

Note: computing the spectrum separately for each trial and averaging will work for the spectrum, but not for the Jackknife error bars

Page 26: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

>>p=0.05;>>params.err=[1 p];>>[S,f,Serr]=mtspectrumc(data,params);>>plot_vector(S,f,[],Serr);>> hold on

>>p=0.05;>>params.err=[2 p];>>[S,f,Serr]=mtspectrumc(data,params);>>plot(f,10*log10(Serr(1,:)),’r’);>>plot(f,10*log10(Serr(2,:)),’r’);

Errors params.err = [1 p]:

params.err=[2 p]: Jackknife

Serr: (1-p)% confidenceinterval of S

Set params.err

Page 27: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

>>params.err=[1 p];>>[S,f,R,Serr]=mtspectrumpt(data,params);

Spike spectrum

mtspectrumpt.m

Page 28: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Spectrogram: mtspecgramc

>> movingwin=[0.5 0.05];>> [S,t,f]=mtspecgramc(data,movingwin,params);

Set duration and step size of moving window:movingwin

Page 29: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

>>[S,t,f,R]=mtspecgrampt(data,movingwin,params);

Spike spectrogram

mtspecgrampt.m

Page 30: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Coherence between LFP and spikes

>>params.err=[1 p];>>[C,phi,S12,S1,S2,f,zerosp,confC,phistd]=coherencycpt(datalfp, datasp,params);

C: coherencePhi: phase

confC: Probability(C>confC)=p

phistd: asymptoticstandard deviation of phase

coherencycpt.m

Page 31: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Coherence between cells

>> params.err=[2 p]; >> [C,phi,S12,S1,S2,f,zerosp,confC,phistd,Cerr]=coherencypt(datasp1,… datasp2,params);

Phistd: Jackknifed standarddeviation of the phase

Cerr: (1-p)% confidenceintervals for C

coherencypt.m

Page 32: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Comparison of coherences and spectra

• Two experimental conditions with unequal number of trials

• Coherence and spectral estimates are biased and the bias depends on sample size

• Would like a simple hypothesis test with a corresponding p value

Bokil et al., J Neurosci Methods. 2006 Aug 28

Page 33: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Comparison of coherences and spectra

If z=tanh-1 (C)

• E(z)=tanh-1(Cpop)+1/(2m-2)

• V(z)=’(m)

Bokil et al., J Neurosci Methods. 2006 Aug 28

Null hypothesis: C1,pop=C2,pop z~N(0,1)

21

21

zVzV

zzz

For two coherence estimates C1,C2 define test statistic

Page 34: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

[dz,vdz,Adz]=two_group_test_coherence(J1c1,J2c1,J1c2,J2c2,p,'y',f);

Fourier transforms

Bokil et al, 2006

Chronux code for comparing coherences

Page 35: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Electrophysiology Analysis Protocol

Page 36: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Electrophysiolgy: Data Conditioning

Page 37: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Removing 50/60 Hz

Model: X(t)=a cos(2f0t+)+(t)

Potential Method: Least squares

(t) is non-white in general

non-linear in f0 and

N

nn

fatnfaX

1

20

},,{2cosmin

0

N samples: X1, X2, …, XN

Page 38: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Thomson’s F test

Idea: Equation can be transformed to a

linear regression in frequency

2)cos(

ixix eex

)()( 00 2*2 teetX tfitfi

Notice

Page 39: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Thomson’s F test

Multiply both sides by kth Slepian sequence uk

n and Fourier transform

000~0

~fUffX kkk

where k=1,2,…, 2TW-1

)(~)()()(~

0*

0 fffUffUfX kkkk

Data Slepian NoiseAt f=f0

kkk axy

Page 40: Chronux Tutorial: Part I Hemant Bokil Cold Spring Harbor Laboratory

Thomson’s F-test

1

1

2

1

10

0

0

0~

K

k

K

kkk

kU

UfXf

Used in touch-tone phones to detect the key

2

100

2

022,2

0~

1

K

kkk

K

UffX

fKF

MN

N

ii

FN

x

,2M

2N

2N

1

2

M

Normal variables