Diff for "Extracting_beta,_standard_error_and_confidence_interval_for_a_coordinate" - MRC CBU Imaging Wiki
location: Diff for "Extracting_beta,_standard_error_and_confidence_interval_for_a_coordinate"
Differences between revisions 1 and 2
Revision 1 as of 2010-06-11 16:19:54
Size: 1655
Editor: JohanCarlin
Comment:
Revision 2 as of 2010-06-11 16:20:47
Size: 1651
Editor: JohanCarlin
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
It is sometimes useful to pull out the parameter estimates and measures of dispersion from your current location in the SPM results viewer. You could click through the GUI and get the data from the 'contrasts' struct that appears in your workspace (do plot > Contrast estimates and 90% CI. > Which contrast?), but if you all you really want is the data for the current contrast at the current voxel, [attachment:extractSPMData.m this function] is faster. It is sometimes useful to pull out the parameter estimates and measures of dispersion from your current location in the SPM results viewer. You could click through the GUI and get the data from the 'contrasts' struct that appears in your workspace (do plot > Contrast estimates and 90% CI. > Which contrast?), but if all you really want is the data for the current contrast at the current voxel, [attachment:extractSPMData.m this function] is faster.

Extracting beta, standard error and confidence interval for a coordinate

It is sometimes useful to pull out the parameter estimates and measures of dispersion from your current location in the SPM results viewer. You could click through the GUI and get the data from the 'contrasts' struct that appears in your workspace (do plot > Contrast estimates and 90% CI. > Which contrast?), but if all you really want is the data for the current contrast at the current voxel, [attachment:extractSPMData.m this function] is faster.

All code is adapted from spm_graph.

% This function extracts beta, st error and 90% CI
% for the voxel at the current location in the SPM
% results viewer.
% [beta,sterr,ci90] = extractSPMData(xSPM,SPM);
% 11/6/2010 J Carlin
function [cbeta,SE,CI] = extractSPMData(xSPM,SPM);

hReg = findobj('Tag','hReg'); % get results figure handle

% This is mostly pulled out of spm_graph
[xyz,i] = spm_XYZreg('NearestXYZ',spm_XYZreg('GetCoords',hReg),xSPM.XYZmm);
spm_XYZreg('SetCoords',xyz,hReg);
XYZ     = xSPM.XYZ(:,i); % coordinates

%-Parameter estimates:   beta = xX.pKX*xX.K*y;
%-Residual mean square: ResMS = sum(R.^2)/xX.trRV
%----------------------------------------------------------------------
beta  = spm_get_data(SPM.Vbeta, XYZ);
ResMS = spm_get_data(SPM.VResMS,XYZ);
Bcov  = ResMS*SPM.xX.Bcov;

CI    = 1.6449;
% compute contrast of parameter estimates and 90% C.I.
%------------------------------------------------------------------
Ic = xSPM.Ic; % Use current contrast
cbeta = SPM.xCon(Ic).c'*beta;
SE    = sqrt(diag(SPM.xCon(Ic).c'*Bcov*SPM.xCon(Ic).c));
CI    = CI*SE;

CbuImaging: Extracting_beta,_standard_error_and_confidence_interval_for_a_coordinate (last edited 2013-03-07 21:23:53 by localhost)