0001 function [marsD] = estimate(marsD, marsY, params)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
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
0031 params = sf_call_compat(params);
0032
0033
0034 params = mars_struct('ffillmerge', def_params, params);
0035
0036
0037 marsY = marsy(marsY);
0038
0039
0040 if ~can_mars_estimate(marsD)
0041 error('This design needs more information before it can be estimated');
0042 end
0043
0044
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
0050 SPM = des_struct(marsD);
0051
0052
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
0078 marsD = des_struct(marsD, SPM);
0079
0080 return
0081
0082 function params = sf_call_compat(params)
0083
0084
0085
0086
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