Commit b2c7f16a authored by Houtan Bastani's avatar Houtan Bastani

update code

parent 2caf0712
Subproject commit 055ffb0b9e2d2b266ba33b253e3bfb86aa1584ad
Subproject commit 8a6e3cc7fe3648bbb228f8b6b10178d66219526f
......@@ -143,24 +143,37 @@ for i = 1:length(jsonmodel)
assert(length(residuals) == 1, ['More than one residual in equation ' num2str(i)]);
Y = eval(regexprep(jsonmodel{i}.lhs, regex, 'ds.$&'));
for j = 1:lhssub.vobs
Y = Y - lhssub{j};
if ~isempty(lhssub)
Y = Y - lhssub;
end
keyboard
fp = max(Y.firstobservedperiod, X.firstobservedperiod);
lp = min(Y.lastobservedperiod, X.lastobservedperiod);
if isfield(jsonmodel{i}, 'sample') && ~isempty(jsonmodel{i}.sample)
if fp > jsonmodel{i}.sample(1) || lp < jsonmodel{i}.sample(end)
if isfield(jsonmodel{i}, 'tags') ...
&& isfield(jsonmodel{i}.tags, 'sample') ...
&& ~isempty(jsonmodel{i}.tags.sample)
colon_idx = strfind(jsonmodel{i}.tags.sample, ':');
fsd = dates(jsonmodel{i}.tags.sample(1:colon_idx-1));
lsd = dates(jsonmodel{i}.tags.sample(colon_idx+1:end));
if fp > fsd
warning(['The sample over which you want to estimate contains NaNs. '...
'Adjusting estimation range to be: ' fp.char ' to ' lp.char])
'Adjusting estimation range to begin on: ' fp.char])
else
fp = fsd;
end
if lp < lsd
warning(['The sample over which you want to estimate contains NaNs. '...
'Adjusting estimation range to end on: ' lp.char])
else
fp = jsonmodel{i}.sample(1);
lp = jsonmodel{i}.sample(end);
lp = lsd;
end
end
Y = Y(fp:lp);
X = X(fp:lp).data;
if ~isempty(lhssub)
lhssub = lhssub(fp:lp);
end
if isfield(jsonmodel{i}, 'tags') && ...
isfield(jsonmodel{i}.tags, 'name')
......@@ -192,20 +205,23 @@ keyboard
end
end
oo_.ols.(tag).Yhat = dseries(X*oo_.ols.(tag).beta, fp, yhatname);
% Residuals
oo_.ols.(tag).resid = Y - oo_.ols.(tag).Yhat;
% Correct Yhat reported back to user
if ~isempty(lhssub)
Y = Y + lhssub;
oo_.ols.(tag).Yhat = oo_.ols.(tag).Yhat + lhssub;
end
% Apply correcting function for Yhat if it was passed
if any(idx) ...
&& length(fitted_names_dict(idx, :)) == 3 ...
&& ~isempty(fitted_names_dict{idx, 3})
oo_.ols.(tag).Yhat = ...
feval(fitted_names_dict{idx, 3}, oo_.ols.(tag).Yhat);
end
% Residuals
oo_.ols.(tag).resid = Y - oo_.ols.(tag).Yhat;
% Correct Yhat reported back to user for given
for j = 1:lhssub.vobs
oo_.ols.(tag).Yhat = oo_.ols.(tag).Yhat + lhssub{j}(fp:lp);
end
ds = [ds oo_.ols.(tag).Yhat];
%% Calculate statistics
......@@ -219,7 +235,7 @@ keyboard
oo_.ols.(tag).R2 = 1 - SS_res/SS_tot;
% Adjusted R^2
oo_.ols.(tag).adjR2 = oo_.ols.(tag).R2 - (1 - oo_.ols.(tag).R2)*nvars/(oo_.ols.(tag).dof-1);
oo_.ols.(tag).adjR2 = oo_.ols.(tag).R2 - (1 - oo_.ols.(tag).R2)*(nvars-1)/(oo_.ols.(tag).dof);
% Durbin-Watson
ediff = oo_.ols.(tag).resid.data(2:nobs) - oo_.ols.(tag).resid.data(1:nobs-1);
......
......@@ -10,7 +10,7 @@ function lhssub = getRhsToSubFromLhs(ds, rhs, regex, splits)
% splits [cell array] strings to split out of equation on RHS
%
% OUTPUTS
% lhssub [dseries] data to subtract from LHS
% lhssub [dseries] summed data to subtract from LHS
%
% SPECIAL REQUIREMENTS
% none
......@@ -57,8 +57,7 @@ for j = 1:length(rhs_)
str = getStrMoveRight(rhsj);
if ~isempty(str)
try
lhssub = [lhssub eval(regexprep([minusstr str], regex, 'ds.$&'))];
lhssub.rename_(lhssub{lhssub.vobs}.name{:}, [minusstr str]);
lhssub = lhssub + eval(regexprep([minusstr str], regex, 'ds.$&'));
catch
if ~any(strcmp(M_.exo_names, str))
error(['getRhsToSubFromLhs: problem evaluating ' minusstr str]);
......@@ -68,4 +67,8 @@ for j = 1:length(rhs_)
end
end
end
if ~isempty(lhssub)
assert(lhssub.vobs == 1, 'error in getRhsToSubFromLhs');
lhssub.rename_(lhssub.name{:}, 'summed_rhs');
end
end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment