Estimating a regression model using matlab

2 views (last 30 days)
Dear all,
I have this regression model
g=randn(1000,1); error=randn(1000,1);
g(2:end)=k1+ k2*(g(1:end-1)-k1) + error(2:end)*k3 ;
k1, k2 are intercept and slope parameters respectively and k3 is the standard deviation
Also the following restrictions must be satisfied: |k2|<1 and k3>0.
Is there a way to estimate such a model, given that 'error' and 'g' are known?
Thanks in advance

Accepted Answer

Jeff Miller
Jeff Miller on 27 May 2019
g=randn(1000,1); error=randn(1000,1);
% Model: g(2:end)=k1+ k2*(g(1:end-1)-k1) + error(2:end)*k3 ;
y = g(2:end);
x1 = g(1:end-1);
x2 = error(2:end);
b = regress(y,[ones(size(x1)), x1, x2]);
k3 = b(3);
k2 = b(2);
k1 = b(1) / (1 - k2);
  2 Comments
ektor
ektor on 27 May 2019
This approach does not satisfy the restrictions
Jeff Miller
Jeff Miller on 27 May 2019
Sorry, I missed the restrictions.
Maybe with fminsearch. The error function would look something like this:
function sse = myErrFunc(x) % x is a vector of 3 reals
% Convert real x's to k's satisfying constraints
k1 = x(1);
k2 = x(2)^2/(1+x(2)^2); % abs(k2)<1
if x(2)<0
k2 = -k2;
end
k3 = x(3)^2; % k3 must be positive
global y, x, error % trim these in advance so they only contain 1:end-1 or 2:end
predicted = k1 + k2*(g-k1) + error*k3;
sse = sum((y-predicted).^2);
end

Sign in to comment.

More Answers (0)

Categories

Find more on Modeling in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!