Home > marsbar > @mardo_2 > estimate.m

estimate

PURPOSE ^

estimate method - estimates GLM for SPM2 model

SYNOPSIS ^

function [marsD] = estimate(marsD, marsY, params)

DESCRIPTION ^

 estimate method - estimates GLM for SPM2 model

 marsD           - SPM design object
 marsY           - MarsBaR data object or 2D data matrix
 params          - struct containing options, as fields
                   redo_covar     - if 1, remodels covariance 
                   redo_whitening - if 1, recalcalates whitening
                   (by default, both are set to 1)
 
 e.g.
 % Estimate model on design D and data Y, using original covariance and
 % whitening
 E = estimate(D, Y, struct('reco_covar', 0, ...
                           'redo_whitening', 0);
  
 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [marsD] = estimate(marsD, marsY, params)
0002 % estimate method - estimates GLM for SPM2 model
0003 %
0004 % marsD           - SPM design object
0005 % marsY           - MarsBaR data object or 2D data matrix
0006 % params          - struct containing options, as fields
0007 %                   redo_covar     - if 1, remodels covariance
0008 %                   redo_whitening - if 1, recalcalates whitening
0009 %                   (by default, both are set to 1)
0010 %
0011 % e.g.
0012 % % Estimate model on design D and data Y, using original covariance and
0013 % % whitening
0014 % E = estimate(D, Y, struct('reco_covar', 0, ...
0015 %                           'redo_whitening', 0);
0016 %
0017 % $Id$
0018 
0019 def_params = struct(...
0020     'redo_covar', 1, ...
0021     'redo_whitening', 1);
0022 
0023 if nargin < 2
0024   error('Need data to estimate');
0025 end
0026 if nargin < 3
0027   params = [];
0028 end
0029 
0030 % Replicate original behaviour calling with cell array of strings
0031 params = sf_call_compat(params);
0032 
0033 % Fill with defaults
0034 params = mars_struct('ffillmerge', def_params, params);
0035 
0036 % ensure we have a data object
0037 marsY = marsy(marsY);
0038 
0039 % check design is complete
0040 if ~can_mars_estimate(marsD)
0041   error('This design needs more information before it can be estimated');
0042 end
0043 
0044 % Check data and design dimensions
0045 if n_time_points(marsY) ~= n_time_points(marsD)
0046   error('The data and design must have the same number of rows');
0047 end
0048 
0049 % get SPM design structure
0050 SPM = des_struct(marsD);
0051 
0052 % process params
0053 if params.redo_covar
0054   if isfield(SPM, 'xVi') 
0055     if isfield(SPM.xVi, 'V') & isfield(SPM.xVi, 'Vi')
0056       SPM.xVi = rmfield(SPM.xVi, 'V');
0057       if verbose(marsD)
0058     disp('Re-estimating covariance');
0059       end
0060     end
0061   end
0062 end
0063 if params.redo_whitening
0064   if isfield(SPM.xX, 'W')
0065     SPM.xX = rmfield(SPM.xX, 'W');
0066     if verbose(marsD)
0067       disp('Re-estimating whitening filter');
0068     end
0069   end
0070 end
0071 
0072 SPM        = pr_estimate(SPM, marsY);
0073 SPM.marsY  = marsY;
0074 SPM.SPMid  = sprintf('SPM2: MarsBaR estimation. mardo_2 version %s', ...
0075              marsD.cvs_version);
0076 
0077 % return modified structure
0078 marsD = des_struct(marsD, SPM);
0079 
0080 return
0081 
0082 function params = sf_call_compat(params)
0083 % Replicates old calling behaviour, for backwards compatibility
0084   
0085 % Replicate result of passing empty cell array, but warn that this
0086 % will be removed soon
0087 if ischar(params) | iscell(params)
0088   warning(['Cell / char form of params deprecated, ' ...
0089        'please use struct form instead']);
0090 end
0091 if iscell(params) & isempty(params)
0092   warning(['Empty cell array changes default options; '...
0093       'This behaviour will change for future versions']);
0094   params = struct(...
0095     'redo_covar', 0, ...
0096     'redo_whitening', 0);
0097 end
0098 if ischar(params)params = {params}; end
0099 if iscell(params)
0100   params = params(:); 
0101   params = cell2struct(num2cell(ones(size(params))), params, 1);
0102 end
0103 return

Generated on Thu 17-Mar-2016 01:14:46 by m2html © 2005