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 3 and 4
Revision 3 as of 2010-06-11 16:23:44
Size: 1652
Editor: JohanCarlin
Comment:
Revision 4 as of 2010-06-11 16:34:29
Size: 1923
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 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 a 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 [attachment:extractSPMData.m this function] is faster.

Do [beta,sterr,ci] = extractSPMData(xSPM,SPM) to get data for
your current location. To pull data from another location (in mm), try [beta,sterr,ci] = extractSPMData(xSPM,SPM,[48 -67 28]).
Line 9: Line 11:
% results viewer.
% [beta,sterr,ci90] = extractSPMData(xSPM,SPM);
% results viewer (or at a location specified in
% the third argument)
.
% [beta,sterr,ci90] = extractSPMData(xSPM,SPM,[coords]);
Line 12: Line 15:
function [cbeta,SE,CI] = extractSPMData(xSPM,SPM); function [cbeta,SE,CI] = extractSPMData(xSPM,SPM,coords);
Line 16: Line 19:
% Use current coordinates, if none were provided
if ~exist('coords','var')
 coords = spm_XYZreg('GetCoords',hReg);
end
Line 17: Line 25:
[xyz,i] = spm_XYZreg('NearestXYZ',spm_XYZreg('GetCoords',hReg),xSPM.XYZmm); [xyz,i] = spm_XYZreg('NearestXYZ',coords,xSPM.XYZmm);
Line 34: Line 42:
CI = CI*SE;
}}}
CI = CI*SE;}}}

Extracting beta, standard error and confidence intervals for a coordinate

It is sometimes useful to pull out the parameter estimates and measures of dispersion from a 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 [attachment:extractSPMData.m this function] is faster.

Do [beta,sterr,ci] = extractSPMData(xSPM,SPM) to get data for your current location. To pull data from another location (in mm), try [beta,sterr,ci] = extractSPMData(xSPM,SPM,[48 -67 28]).

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 (or at a location specified in
% the third argument).
% [beta,sterr,ci90] = extractSPMData(xSPM,SPM,[coords]);
% 11/6/2010 J Carlin
function [cbeta,SE,CI] = extractSPMData(xSPM,SPM,coords);

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

% Use current coordinates, if none were provided
if ~exist('coords','var')
        coords = spm_XYZreg('GetCoords',hReg);
end

% This is mostly pulled out of spm_graph
[xyz,i] = spm_XYZreg('NearestXYZ',coords,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)