Home > marsbar > @mardo_5 > private > pr_spm_non_sphericity.m

pr_spm_non_sphericity

PURPOSE ^

return error covariance constraints for basic ANOVA designs

SYNOPSIS ^

function [xVi] = pr_spm_non_sphericity(xVi)

DESCRIPTION ^

 return error covariance constraints for basic ANOVA designs
 FORMAT [xVi] = pr_spm_non_sphericity(xVi)

 required fields:
 xVi.I    - n x 4 matrix of factor level indicators
              I(n,i) is the level of factor i for observation n
 xVi.var  - 1 x 4 vector of flags
              var(i) = 1; different variance among levels of factor i
 xVi.dep  - 1 x 4 vector of flags
              dep(i) = 1;      dependencies within levels of factor i

 Output:
 xVi.Vi   -  cell of covariance components
 or
 xVi.V    -  speye(n,n)

 See also; pr_spm_Ce.m & pr_spm_ui.m
___________________________________________________________________________
 Non-sphericity specification
 =========================

 In some instances the i.i.d. assumptions about the errors do not hold:

 Identity assumption:
 The identity assumption, of equal error variance (homoscedasticity), can
 be violated if the levels of a factor do not have the same error variance.
 For example, in a 2nd-level analysis of variance, one contrast may be scaled
 differently from another.  Another example would be the comparison of
 qualitatively different dependant variables (e.g. normals vs. patients).  If
 You say no to identity assumptions, you will be asked whether the error
 variance is the same over levels of each factor.  Different variances
 (heteroscedasticy) induce different error covariance components that
 are estimated using restricted maximum likelihood (see below).

 Independence assumption.
 In some situations, certain factors may contain random effects.  These induce
 dependencies or covariance components in the error terms.   If you say no
 to independence assumptions, you will be asked whether random effects
 should be modelled for each factor.  A simple example of this would be
 modelling the random effects of subject.  These cause correlations among the
 error terms of observation from the same subject.  For simplicity, it is
 assumed that the random effects of each factor are i.i.d.

 ReML
 The ensuing covariance components will be estimated using ReML in spm_spm
 (assuming the same for all responsive voxels) and used to adjust the
 statistics and degrees of freedom during inference. By default spm_spm
 will use weighted least squares to produce Gauss-Markov or Maximum
 likelihood estimators using the non-sphericity structure specified at this
 stage. The components will be found in xX.xVi and enter the estimation
 procedure exactly as the serial correlations in fMRI models.

___________________________________________________________________________
 Copyright (C) 2005 Wellcome Department of Imaging Neuroscience

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [xVi] = pr_spm_non_sphericity(xVi)
0002 % return error covariance constraints for basic ANOVA designs
0003 % FORMAT [xVi] = pr_spm_non_sphericity(xVi)
0004 %
0005 % required fields:
0006 % xVi.I    - n x 4 matrix of factor level indicators
0007 %              I(n,i) is the level of factor i for observation n
0008 % xVi.var  - 1 x 4 vector of flags
0009 %              var(i) = 1; different variance among levels of factor i
0010 % xVi.dep  - 1 x 4 vector of flags
0011 %              dep(i) = 1;      dependencies within levels of factor i
0012 %
0013 % Output:
0014 % xVi.Vi   -  cell of covariance components
0015 % or
0016 % xVi.V    -  speye(n,n)
0017 %
0018 % See also; pr_spm_Ce.m & pr_spm_ui.m
0019 %___________________________________________________________________________
0020 % Non-sphericity specification
0021 % =========================
0022 %
0023 % In some instances the i.i.d. assumptions about the errors do not hold:
0024 %
0025 % Identity assumption:
0026 % The identity assumption, of equal error variance (homoscedasticity), can
0027 % be violated if the levels of a factor do not have the same error variance.
0028 % For example, in a 2nd-level analysis of variance, one contrast may be scaled
0029 % differently from another.  Another example would be the comparison of
0030 % qualitatively different dependant variables (e.g. normals vs. patients).  If
0031 % You say no to identity assumptions, you will be asked whether the error
0032 % variance is the same over levels of each factor.  Different variances
0033 % (heteroscedasticy) induce different error covariance components that
0034 % are estimated using restricted maximum likelihood (see below).
0035 %
0036 % Independence assumption.
0037 % In some situations, certain factors may contain random effects.  These induce
0038 % dependencies or covariance components in the error terms.   If you say no
0039 % to independence assumptions, you will be asked whether random effects
0040 % should be modelled for each factor.  A simple example of this would be
0041 % modelling the random effects of subject.  These cause correlations among the
0042 % error terms of observation from the same subject.  For simplicity, it is
0043 % assumed that the random effects of each factor are i.i.d.
0044 %
0045 % ReML
0046 % The ensuing covariance components will be estimated using ReML in spm_spm
0047 % (assuming the same for all responsive voxels) and used to adjust the
0048 % statistics and degrees of freedom during inference. By default spm_spm
0049 % will use weighted least squares to produce Gauss-Markov or Maximum
0050 % likelihood estimators using the non-sphericity structure specified at this
0051 % stage. The components will be found in xX.xVi and enter the estimation
0052 % procedure exactly as the serial correlations in fMRI models.
0053 %
0054 %___________________________________________________________________________
0055 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
0056 
0057 % Karl Friston
0058 % $Id: spm_non_sphericity.m 112 2005-05-04 18:20:52Z john $
0059 
0060 
0061 % create covariance components Q{:}
0062 %===========================================================================
0063 [n f] = size(xVi.I);            % # observations, % # Factors
0064 l     = max(xVi.I);                     % levels
0065 
0066 % if var(i): add variance component for each level of factor i,
0067 %---------------------------------------------------------------------------
0068 Q     = {};
0069 for i = find(xVi.var)
0070     for j = 1:l(i)
0071         u          = xVi.I(:,i) == j;
0072         q          = spdiags(u,0,n,n);
0073         Q{end + 1} = q;
0074     end
0075 end
0076 
0077 % effects (discounting factors with dependencies) as defined by interactions
0078 %---------------------------------------------------------------------------
0079 X     = ones(n,1);
0080 for i = find(~xVi.dep & (l > 1))
0081     Xi    = sparse(1:n,xVi.I(:,i),1,n,l(i));
0082     Xj    = X;
0083     X     = sparse(n,0);
0084     for j = 1:size(Xi,2)
0085         for k = 1:size(Xj,2)
0086             X(:,end + 1) = Xi(:,j) & Xj(:,k);
0087         end
0088     end
0089 end
0090 
0091 % dependencies among repeated measures created by the hadamrad product %---------------------------------------------------------------------------
0092 for i = find(xVi.dep)
0093     q     = sparse(1:n,xVi.I(:,i),1,n,l(i));
0094     P     = q*q';
0095     for j = 1:size(X,2)
0096         for k = (j + 1):size(X,2)
0097             Q{end + 1} = (X(:,j)*X(:,k)' + X(:,k)*X(:,j)').*P;
0098         end
0099     end
0100 end
0101 
0102 % set Q in non-sphericity structure
0103 %---------------------------------------------------------------------------
0104 
0105 
0106 % if i.i.d nonsphericity (V) is known otherwise there are components {Vi}
0107 %---------------------------------------------------------------------------
0108 if length(Q) > 1
0109     xVi.Vi = Q;
0110 else
0111     xVi.V  = speye(n,n);
0112 end

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019