0001 function SPM = pr_estimate(SPM, marsY)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 Finter = spm('FigName','Stats: estimation...'); spm('Pointer','Watch');
0018
0019
0020
0021
0022 COV_estim = 'assumed';
0023 GLM_resol = 'OLS';
0024
0025
0026
0027
0028 xX = SPM.xX;
0029 if ~isfield(xX,'X'),
0030 error('The design does not contain a design matrix');
0031 end
0032
0033
0034 marsY = marsy(marsY);
0035 Y = summary_data(marsY);
0036 n_roi = size(Y,2);
0037
0038
0039 in_cols = any(diff(Y));
0040 if ~any(in_cols), error('No variance to estimate model'); end
0041 Y = Y(:, in_cols);
0042
0043
0044 if mars_struct('isthere', xX, 'xVi', 'Form')
0045 if ~strcmp(xX.xVi.Form, 'none')
0046 warning(['Sorry, we are going to ignore autocorrelation option: ' ...
0047 xX.xVi.Form]);
0048 end
0049 end
0050
0051
0052
0053 fprintf('\nEstimating covariance...');
0054 switch COV_estim
0055
0056 case {'AR(p)'}
0057
0058 if ~isfield(xX,'xVi')
0059 xX.xVi = struct( 'Vi', speye(size(xX.X,1)),...
0060 'Form', 'AR(p)');
0061 end
0062
0063
0064
0065 case {'assumed'}
0066 if ~isfield(xX,'xVi')
0067 xX.xVi = struct( 'Vi', speye(size(xX.X,1)),...
0068 'Form', 'none');
0069 end
0070
0071
0072
0073 otherwise
0074 warning('COV_estim does not exist');
0075 end
0076 fprintf('Done\n');
0077
0078 switch GLM_resol
0079
0080 case {'OLS'}
0081 fprintf('Using OLS\n');
0082
0083 if ~isfield(xX,'K')
0084 xX.K = speye(size(xX.X,1));
0085 end
0086
0087
0088 KVi = pr_spm_filter('apply', xX.K, xX.xVi.Vi);
0089 V = pr_spm_filter('apply', xX.K, KVi');
0090 Y = pr_spm_filter('apply', xX.K, Y);
0091 fprintf('Setting filter...');
0092 KXs = spm_sp('Set', pr_spm_filter('apply', xX.K, xX.X));
0093 fprintf('Done.\n');
0094 clear KVi;
0095
0096 case {'MaxLik'}
0097 'MaxLik'
0098
0099
0100
0101
0102 otherwise
0103 warning('GLM_resol does not exist');
0104 end
0105
0106
0107 fprintf('Computing estimates...');
0108 if ~spm_sp('isspc',KXs), Xs = spm_sp('set',KXs); else Xs = KXs; end
0109
0110 [trRV trRVRV] = spm_SpUtil('trRV',Xs,V);
0111 beta = spm_sp('x-', Xs, Y);
0112 res = spm_sp('r', Xs, Y);
0113 ResMS = sum(res.^2)./trRV;
0114 xX.erdf = trRV^2/trRVRV;
0115
0116 fprintf('Done.\n');
0117
0118
0119 xX.V = V;
0120 xX.xKXs = KXs;
0121 xX.pKX = spm_sp('x-',xX.xKXs);
0122 xX.pKXV = xX.pKX*xX.V;
0123 xX.Bcov = xX.pKXV*xX.pKX';
0124 [xX.trRV,xX.trRVRV] ...
0125 = spm_SpUtil('trRV',xX.xKXs,xX.V);
0126 xX.nKX = spm_DesMtx('sca',xX.xKXs.X,xX.Xnames);
0127
0128
0129 nBeta = size(xX.X, 2);
0130 SPM.betas = ones(nBeta, n_roi) + NaN;
0131 SPM.betas(:, in_cols) = beta;
0132 SPM.ResidualMS = ones(1, n_roi) + NaN;
0133 SPM.ResidualMS(in_cols) = ResMS;
0134
0135 SPM.xX = xX;
0136 SPM.marsY = marsY;
0137
0138
0139
0140 F_iX0 = [];
0141 if isfield(SPM, 'F_iX0')
0142 F_iX0 = SPM.F_iX0;
0143 end
0144 if isempty(F_iX0)
0145 F_iX0 = struct( 'iX0', [],...
0146 'name', 'all effects');
0147 elseif ~isstruct(F_iX0)
0148 F_iX0 = struct( 'iX0', F_iX0,...
0149 'name', 'effects of interest');
0150 end
0151
0152
0153
0154 xCon = spm_FcUtil('Set',F_iX0(1).name,'F','iX0',F_iX0(1).iX0,xX.xKXs);
0155 for i = 2:length(F_iX0)
0156 xcon = spm_FcUtil('Set',F_iX0(i).name,'F','iX0',F_iX0(i).iX0,xX.xKXs);
0157 xCon = [xCon xcon];
0158 end
0159 SPM.xCon = xCon;
0160
0161
0162
0163
0164 spm_progress_bar('Clear')
0165 spm('FigName','Stats: done',Finter); spm('Pointer','Arrow')
0166 fprintf('%-40s: %30s\n','Completed',spm('time'))
0167 fprintf('...use the results section for assessment\n\n')
0168
0169 return