-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCovariateGLM.m
56 lines (52 loc) · 1.79 KB
/
CovariateGLM.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
% GLM sub-class where a set of covariates are projected out of data and
% design matrix prior to fitting.
%
% Mainly useful when the number of covariates might vary (e.g., ncovtouse
% is a free parameter tuned with crossvalidateproperty as part of
% GLMdenoise-like fits), or when the design matrix is convolved on the fly
% (see ConvGLM sub-class).
%
% model = CovariateGLM(X,data,covariates)
classdef CovariateGLM < GLM
properties
covariates
ncovariates
ncovtouse
end
methods
function gl = CovariateGLM(X,data,covariates)
if ~any(nargin)
[X,data,covariates] = deal([]);
end
gl = gl@GLM(X,data);
assert(gl.nsamples==size(covariates,1),...
'covariates do not match nsamples');
gl.covariates = covariates;
gl.ncovariates = size(covariates,2);
gl.ncovtouse = gl.ncovariates;
end
function data = getdatac(self)
nrun = numel(self);
% filter each run separately to preserve independence
data = cell(nrun,1);
for r = 1:nrun
data{r} = getprojectionmatrix(self(r)) * ...
self(r).data;
end
end
function X = getdesign(self)
nrun = numel(self);
Xcovcache = cell(nrun,1);
for r = 1:nrun
Xcovcache{r} = getprojectionmatrix(self(r)) * ...
self(r).X;
end
X = vertcat(Xcovcache{:});
end
function pmat = getprojectionmatrix(self)
assert(numel(self)==1,['covariates should be processed ' ...
'separately for each run']);
pmat = projectionmatrix(self.covariates(:,1:self.ncovtouse));
end
end
end