-
Notifications
You must be signed in to change notification settings - Fork 5
/
ConvGLM.m
76 lines (72 loc) · 2.97 KB
/
ConvGLM.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
% CovariateGLM sub-class where a set of onsets and condition labels are
% used to re-build a convolved design matrix online. For documentation on
% inputs, see convolveonsets. Any varargin are passed on to this function.
%
% This class has significant performance costs compared to using a
% pre-convolved design matrix but is useful for permutation tests based on
% reassigning the labels (conind). We override drawpermsample to support
% such tests here.
%
% model = ConvGLM(onsets,conind,frameperiod,data,covariates,[varargin])
classdef ConvGLM < CovariateGLM
properties
onsets
conind
frameperiod
convargs
end
methods
function gl = ConvGLM(onsets,conind,frameperiod,data,covariates,varargin)
convargs = varargin;
if nargin == 0 || isempty(onsets)
[X,onsets,conind,frameperiod,data,covariates] = deal([]);
else
X = convolveonsets(onsets,conind,frameperiod,size(data,1),...
convargs{:});
end
gl = gl@CovariateGLM(X,data,covariates);
[gl.onsets,gl.conind,gl.frameperiod,gl.convargs] = deal(onsets,...
conind,frameperiod,convargs);
% update number of independent observations to number of
% trials, not number of samples
gl.nrandsamp = numel(onsets);
end
function X = getdesign(self)
nrun = numel(self);
for r = 1:nrun
% re-convolve
self(r).X = convolveonsets(self(r).onsets,...
self(r).conind,self(r).frameperiod,self(r).nsamples,...
self(r).convargs{:});
end
% use super-class to do covariate filter
X = getdesign@CovariateGLM(self);
end
function model = drawpermsample(self,inds)
% return a new instance where the condition labels in the design
% matrix have been re-ordered according to inds. Note that you must
% supply the same number of inds as numel(self(1).conind).
%
% model = drawpermsample(self,inds)
n = cellfun(@numel,{self.conind});
assert(numel(inds)==n(1),'got %d inds for %d samples',...
numel(inds),n(1));
assert(all(n(1) == n),['design must have same number of ' ...
'events in each run.'])
model = copy(self);
for r = 1:length(self)
model(r).conind = model(r).conind(inds);
end
% flatten to GLM class for speed (prevents all of these
% filtering operations from happening unnecessarily after the
% permutation has been done)
model = asglm(model);
end
function model = asglm(self)
% flatten the ConvGLM to a simple GLM for faster code execution
for r = 1:numel(self)
model(r) = GLM(getdesign(self(r)),getdata(self(r)));
end
end
end
end