JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for SPM Archives


SPM Archives

SPM Archives


SPM@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

SPM Home

SPM Home

SPM  2005

SPM 2005

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: empty conditions in design

From:

Jan Gläscher <[log in to unmask]>

Reply-To:

Jan Gläscher <[log in to unmask]>

Date:

Wed, 23 Mar 2005 12:47:32 +0100

Content-Type:

multipart/signed

Parts/Attachments:

Parts/Attachments

text/plain (266 lines) , signature.asc (266 lines)

Dear Satra and list,

SPM won't let you estimate a design matrix with empty regressors as all
the other answers have correctly suggested.  I will outline a solution
for a conditional design and contrast specification below, but I must
stress that it is complicated and therefore I would therefore strongly
recommend using the batching facilities in SPM2.  If you are not
familiar with batching you will find a lot of sample batch files on this
list, e.g. Karl Friston's sample file

http://www.jiscmail.ac.uk/cgi-bin/wa.exe?A2=ind02&L=spm&P=R282882&I=-1

Now, there are 3 constraints to this problem that have to be taken into
account:

(1) There must not be any empty regressors.
(2) For a valid parametric modulation there must be at least 2 trials
    (= 2 onset) in the "onset" regressors (i.e. the one where you
	specify your onsets)
(3) Contrast specification is tricky (Therefore I recommend a spcific
    naming scheme for your regressors (and parametric modulations) which
	you can later reference)

Here is some example code for solving problem (1) and (2) ...

In the following I assume that you save your onsets (and parametric
values) in a struct array called "onset". This struct array is setup
like this 

onset(1).reg(1).name		--- name for regressor 1 in session1
onset(1).reg(1).ons			--- onsets for regressor 1 in session1
onset(1).reg(1).pm(1).name	--- name for 1st parametric values for regressors 1 in session 1
onset(1).reg(1).pm(1).P		--- 1st parametric values for regressors 1 in session 1
onset(1).reg(1).pm(2).name	--- name for 2nd parametric values for regressors 1 in session 1
onset(1).reg(1).pm(2).P		--- 2nd parametric values for regressors 1 in session 1
onset(1).reg(2).ons			--- onsets for regressor 2 in session1
onset(1).reg(2).pm(1).name	--- name for 1st parametric values for regressor2 in sesssion1
onset(1).reg(2).pm(1).P		--- 1st parametric values for regressor2 in sesssion1
onset(1).reg(2).pm(2).name	--- name for 2nd parametric values for regressor2 in sesssion1
onset(1).reg(2).pm(2).P		--- 2nd parametric values for regressor2 in sesssion1
...
onset(2).reg(1).name		--- name for regressor 1 in session2
onset(2).reg(1).ons			--- onsets for regressor 1 in session2
onset(2).reg(1).pm(1).name	--- name for 1st parametric values for regressors 1 in session 1
onset(2).reg(1).pm(1).P		--- 1st parametric values for regressors 1 in session 1
onset(2).reg(1).pm(2).name	--- name for 2nd parametric values for regressors 1 in session 1
onset(2).reg(1).pm(2).P		--- 2nd parametric values for regressors 1 in session 1
onset(2).reg(2).ons			--- onsets for regressor 2 in session2
onset(2).reg(2).pm(1).name	--- name for 1st parametric values for regressor2 in sesssion1
onset(2).reg(2).pm(1).P		--- 1st parametric values for regressor2 in sesssion1
onset(2).reg(2).pm(2).name	--- name for 2nd parametric values for regressor2 in sesssion1
onset(2).reg(2).pm(2).P		--- 2nd parametric values for regressor2 in sesssion1
...
and so on

If you are planning to look for session-specific contrast, you should
specify session-specific names for both regressors and parametric
modulation.

Now, in your batch file when you get to the point of specifying your
regressors (and parametric modulations) then you could something like
the following:

for s = 1:length(SPM.nscan) % loop over sessions

	SPM.Sess(s).U = struct;

	Rcnt = 1;		                                                                % counter for the regressors
	for r = 1:length(onset(s).reg)                                                  % loop over regressors

		if ~isempty(onset(s).reg(Rcnt).ons)											% test if onset vector is empty
			SPM.Sess(s).U(Rcnt).name 	= {onset(s).reg(Rcnt).name}
			SPM.Sess(s).U(Rcnt).ons 	= onset(s).reg(Ucnt).ons;
			SPM.Sess(s).U(Rcnt).dur		= 0; 										% if event-related
			
			Pcnt = 1;                                                               % counter for parametric modulations
			for p = 1:length(onset(s).reg(Rcnt).pm)                                 % loop over parametric modulations
				if length(onset(s).reg(Rcnt).ons > 1								% test if there are more than 1 onsets
				SPM.Sess(s).U(Rcnt).P(Pcnt).name = onset(s).reg(Rcnt).pm(Pcnt).name; 
				SPM.Sess(s).U(Rcnt).P(Pcnt).P    = onset(s).reg(Rcnt).pm(Pcnt).P;
				SPM.Sess(s).U(Rcnt).P(Pcnt).h    = 1; 								% first order polynomial expansion (linear)
				Pcnt = Pcnt + 1;
			end
			Rcnt = Rcnt + 1;
		end
	end
	
	% proceed with covariates, assuming there are none
	SPM.Sess(s).C.C    = [];
	SPM.Sess(s).C.name = {};

end

This is it!  No further code is necessary for specification of the
regressors.  As you can see, it all comes down to saving your onsets and
parametric values in a orderly fashion that can be easily looped over.
If you use a conditional design specification like the one above, then
only those regressors are included that a not empty, and only those
parametric modulations are included for which the regressors has more
than one onset.

The batch file then continues with the specifications of global
normalization etc. and then calls spm_fmri_spm_ui and spm_spm.


Now a solution for problem (2) (contrast specification). Suppose you
want to specify two T-contrast, one "main effect" (where does reg1 show
a positive effect) and one differential contrast (where does reg1 show
a greater effect than reg2).  I further assume that you want to average
over sessions and that therefore reg1 and reg2 iare the name for
regressors 1 and 2 IN ALL SESSIONS.

The strategy is to see if the regressors are present and then adjust the
contrast weight accordingly to make then available for a second level
analysis.  This adjustment is important because the con-images contain
the sum of the contrast-weighted beta-images (and not the mean).  In
matrix notation: con-value = beta*c'.  This has important consequences.
Here is an example of the problem:  Suppose subject 1 has onset for
regressor 1 in only 2 of 3 sessions, but subject 2 has onset for
regressors 2 in all 3 sessions.  If you now put simple [1]-contrasts
weights on the respective columns of the design matrix, then subject 2 
will get a much higher con-value because it contains the sum of
3 sessions, as opposed to subject 1 in which the con-value is only the
sum of 2 sessions.  Therefore we need to adjust the contrast weights to
deal with this problem.

Here is some code for a batch file that will do this conditional
contrast specification:

% constrast 1: main effect of regressors 1

% define cell array holding contrast names
cTnames = {};

% define a contrast vector of zeros
cT(1,:) = zeros(1,size(SPM.xX.X,2);			% every line of cT will contain a T-contrast vector

for c = 1:length(SPM.xX.name)				% This cell array contain all the names specified earlier 
	if ~isempty(strfind(SPM.xX.name{c},onset(1).reg(1).ons))
		cT(1,c) = 1;
	end
end
% now adjust the contrast weights (if necessary)
if ~isempty(find(cT(1,:))					% regressors 1 is present in at least one session
	cTnames{end+1} = 'ME: reg1'; 			% name of contrast, will show up on the contrast manager
	idx = find(cT(1,:);						% indices of 1's
	l   = length(idx);						% number of 1's
	cT(1,idx) = 1/l;
else
	cT = [];								% delete cT, if empty
end

This will yield contrast weights of 1/3 for subject 2, and 0.5 for
subject 1 in the example above.  Therefore you will obtain properly
scaled con-images that you can test at the second level in a one-sample
t-test.

Now for contrast 2: differential effect of reg1 - reg2

cT(end+1,:) = zeros(1,size(SPM.xX.X,2);	% 2nd contrast, but 1st could be empty, therefore cT(end,:)
for c = 1:length(SPM.xX.name)
	if ~isempty(strfind(SPM.xX.name{c},onset(1).reg(1).name))
		cT(end,c) = 1;
	end
	if ~isempty(strfind(SPM.xX.name{c},onset(1).reg(2).name))
		cT(end,c) = -1;
	end
end
% now adjust the contrast weight so that they add up to zero
if ~isempty(find(cT(end,:)==1)) & ~isempty(find(cT(end,:)==-1)) % are there any 1's and -1's in the contrast weights?
	cTnames{end+1} = 'reg1-reg2';
	pidx = find(cT(end,:)==1);		% indices of 1's
	pl   = length(pidx);			% number of 1's
	nidx = find(cT(end,:)==-1);		% indices of -1's
	nl   = length(nidx);			% number of -1's
	cT(end,pidx) = 1/pl;			% scale 1's to 1/no. of 1's
	cT(end,nidx) = -1/nl;			% scale -1's to -1/no. of -1's
end

% finally we put these T-contrast in SPM.xCon and then estimate the
% contrasts

for f = 1:size(cT,1)				% loop over all valid T-contrasts
	c = cT(f,:);					% current (scaled) contrast vector
	cname = cTnames{f};				% current contrast name
	spm_FcUtil('Set',cname,'T','c',c(:),SPM.xX.xKXs);
end

This applies only to T-contrast, or F-contrasts the case is a bit more
tricky.

I alos want to stress that I copied most of the code from some of my own
batch file and made some appropriate changes, but I have tested the code
above.  There might be errors (e.g. typos); if so, please let me know
about it.


I hope this will give you some ideas about implementing a conditional
design specification.

Best,
Jan



On 2005-03-23 (Wed) at 10:01:22 +0100, Neggers, S.F.W. (Bas)
<[log in to unmask]> wrote:
> Hi Satra, List,
> 
> I think it would be mathematically impossible to estimate the
> regression coefficients (Betas) for your Data Y (solving B= (X'X)^-1
> x X'Y ) for a design matrix X containing 3 identical regressors, i.e.
> in your case 2 regressors with a constant value for the 'empty'
> condition, plus the intercept. They are perfectly co-linear (=wrong!).
> So you will have to find another way to setup your GLM.
> 
> Cheers,
> 
> Bas
> 
> -----Oorspronkelijk bericht----- Van: SPM (Statistical Parametric
> Mapping) [mailto:[log in to unmask]]Namens Stephen J. Fromm Verzonden:
> woensdag 23 maart 2005 1:40 Aan: [log in to unmask] Onderwerp: Re:
> [SPM] empty conditions in design
> 
> 
> On Tue, 22 Mar 2005 16:50:12 -0500, Satrajit Ghosh
> <[log in to unmask]> wrote:
> 
> >Dear SPMusers,
> >
> >I have a study in which conditions are not balanced across runs.
> >Therefore, run1 may have conditions 1 and 4 and run2 may have
> >conditions 2 and 3.  SPM complains if I set the onsets for
> >a condition to be empty. All it should translate to is an empty
> >column in the design matrix, which would be eliminated when the
> >matrix is reduced. The reason for entering empty conditions is that
> >I would like to say each run has all the conditions, but only enter
> >events for the conditions that actually exist in the run.
> >
> >Is this something that's part of the design intentions? Or am I doing
> >something incorrectly?
> 
> As far as I can tell, SPM (SPM2 in my case) doesn't let one create
> empty columns.
> 
> >
> >Thanks,
> >
> >Satra
> 

-- 
Jan Gläscher                    Neuroimage Nord
+49-40-42803-7890 (office)      Dept. of Neurology, Bldg S10
+49-40-42803-9955 (fax)         University Hospital Hamburg-Eppendorf
[log in to unmask]    Martinistr. 52
                                20246 Hamburg
                                Germany
http://www.uke.uni-hamburg.de/kliniken/neurologie/index_16969.php
---------------------------------------------------------------------
GnuPG/PGP key id: FEC4B55C
fingerprint: 5A36 1EF6 8472 117E 805A  F240 3146 A410 FEC4 B55C
---------------------------------------------------------------------

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

April 2024
March 2024
February 2024
January 2024
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager