Test if the data are positive before applying the log.

time-shift
Stéphane Adjemian (Scylla) 2014-01-30 17:44:47 +01:00
parent 8829baa3aa
commit f1e4ca2f48
1 changed files with 10 additions and 5 deletions

View File

@ -21,11 +21,11 @@ function dataset_ = initialize_dataset(datafile,varobs,first,nobs,transformation
% Original author: stephane DOT adjemian AT univ DASH lemans DOT fr % Original author: stephane DOT adjemian AT univ DASH lemans DOT fr
if isempty(datafile) if isempty(datafile)
error('Estimation:: You have to declare a dataset file!') error('Estimation::initialize_dataset: You have to declare a dataset file!')
end end
if isempty(varobs) if isempty(varobs)
error('Estimation:: You have to declare a set of observed variables') error('Estimation::initialize_dataset: You have to declare a set of observed variables')
end end
% Get raw data. % Get raw data.
@ -36,7 +36,7 @@ if isempty(nobs) || rows(rawdata)<nobs+first-1 %case 2: dataset has changed
nobs = rows(rawdata)-first+1; nobs = rows(rawdata)-first+1;
end end
% Get the (default) prefilter option. % Set the (default) prefilter option.
if isempty(prefilter) if isempty(prefilter)
prefilter = 0; prefilter = 0;
end end
@ -65,12 +65,17 @@ rawdata = rawdata(first:(first+dataset_.info.ntobs-1),:);
if isempty(transformation) if isempty(transformation)
dataset_.rawdata = rawdata; dataset_.rawdata = rawdata;
else else
if isequal(transformation,@log)
if ~isreal(rawdata)
error(['Estimation::initialize_dataset: Some of the variables have non positive observations, I cannot take the log of the data!'])
end
end
dataset_.rawdata = arrayfun(transformation,rawdata); dataset_.rawdata = arrayfun(transformation,rawdata);
end end
% Test if the observations are real numbers. % Test if the observations are real numbers.
if ~isreal(dataset_.rawdata) if ~isreal(dataset_.rawdata)
error('Estimation:: There are complex values in the data! Probably a wrong (log) transformation...') error('Estimation::initialize_dataset: There are complex values in the data!')
end end
% Test for missing observations. % Test for missing observations.
@ -96,4 +101,4 @@ if prefilter == 1
dataset_.data = transpose(bsxfun(@minus,dataset_.rawdata,dataset_.descriptive.mean)); dataset_.data = transpose(bsxfun(@minus,dataset_.rawdata,dataset_.descriptive.mean));
else else
dataset_.data = transpose(dataset_.rawdata); dataset_.data = transpose(dataset_.rawdata);
end end