Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Bach committed Sep 8, 2023
1 parent 99144c7 commit f2ded63
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/pspm_cfg/pspm_cfg_glm.m
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@
time_window.name = 'Time window';
time_window.tag = 'time_window';
time_window.strtype = 'r';
time_window.num = [1 1];
time_window.help = {['In seconds, specifies over which time window ', ...
time_window.num = [1 2];
time_window.help = {['A 2-element vector in seconds, specifies over which time window ', ...
'latencies should be evaluated. Positive values mean that the ', ...
'response function is shifted to later time points, negative values ', ...
'that it is shifted to earlier time points.']};
Expand Down
15 changes: 14 additions & 1 deletion src/pspm_check_model.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,21 @@
model.latency = 'fixed';
elseif ~ismember(model.latency, {'free', 'fixed'})
warning('ID:invalid_input', 'Latency should be either ''fixed'' or ''free''.'); return;
elseif strcmpi(model.latency, 'free') && (~isnumeric(model.window) || isempty(model.window))
elseif strcmpi(model.latency, 'free') && (~isfield(model, 'window') || ...
isempty(model.window) || ~isnumeric(model.window))
warning('ID:invalid_input', 'Window is expected to be a numeric value.'); return;
elseif strcmpi(model.latency, 'free') && numel(model.window) == 1
model.window = [0, model.window];
elseif strcmpi(model.latency, 'free') && numel(model.window) > 2
warning('ID:invalid_input', 'Only first two elements of model.window are used');
model.window = model.window(1:2);
elseif strcmpi(model.latency, 'fixed') && isfield(model, 'window')
warning('ID:invalid_input', 'model.window was provided but will be ignored');
model = rmfield(model, 'window');
end

if strcmpi(model.latency, 'free') && diff(model.window < 0)
warning('ID:invalid_input', 'model.window invalid');
end

if ~isfield(model, 'modelspec')
Expand Down
20 changes: 13 additions & 7 deletions src/pspm_glm.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
% │ is set to be 'markervalues')
% │ OR a cell array of struct
% ├.timeunits: one of 'seconds', 'samples', 'markers', 'markervalues'
% ├───.window: a scalar in seconds that specifies over which time
%window (starting with the events specified in
%model.timing) the model should be evaluated. Is only
%required if model.latency equals 'free'. Is ignored
%otherwise.
% ├───.window: only required if model.latency equals 'free' and ignored
%otherwise. A scalar or 2-element vector in seconds that
%specifies over which time window (relative to the event
%onsets specified in model.timing) the model should be
%evaluated.
% │ ▶︎ optional
% ├.modelspec: 'scr' (default); specify the model to be used.
% │ See pspm_init, defaults.glm() which modelspecs are possible
Expand Down Expand Up @@ -489,7 +489,13 @@
for iCond = 1:numel(names)
tmp.regscale{iCond} = 1;
% first process event onset, then pmod
tmp.onsets = onsets{iCond};
if strcmpi(model.latency, 'free')
offset = model.window(1);
else
offset = 0;
end
tmp.onsets = onsets{iCond} - offset;
clear offset
tmp.durations = durations{iCond};
% if file starts with first event, set that onset to 1 instead of 0
if any(tmp.onsets == 0)
Expand Down Expand Up @@ -653,7 +659,7 @@
% this is where the beef is
if strcmpi(model.latency, 'free')
% prepare dictionary onsets and new design matrix
D_on = eye(ceil(model.window*glm.infos.sr));
D_on = eye(ceil(diff(model.window)*glm.infos.sr));
XMnew = NaN(size(glm.XM));
% go through columns
ncol = size(glm.XM, 2) - nR - glm.interceptno;
Expand Down

0 comments on commit f2ded63

Please sign in to comment.