Orthogonal complement

For technical questions regarding estimation of single equations, systems, VARs, Factor analysis and State Space Models in EViews. General econometric questions and advice should go in the Econometric Discussions forum.

Moderators: EViews Gareth, EViews Moderator

olayenidynare
Posts: 6
Joined: Tue Mar 18, 2014 10:48 am

Orthogonal complement

Postby olayenidynare » Sun May 15, 2016 2:34 am

Please can somebody tell me how to obtain the orthogonal complement of A and B matrices of VECM? I'm aware this can be programmed but I can't get a handle on it. I tried to use SVD to obtain the null space following MATLAB null.m, yet SVD in Eviews does not seem to give the whole matrices needed.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Orthogonal complement

Postby EViews Glenn » Mon May 16, 2016 11:14 am

I'm a bit confused as to what you've done. Can you describe how you called the SVD?

olayenidynare
Posts: 6
Joined: Tue Mar 18, 2014 10:48 am

Re: Orthogonal complement

Postby olayenidynare » Mon May 16, 2016 11:38 pm

Thank you Glenn for your quick response.
The code I'm trying to replicate is this:

function Z = null(A,how)

[m,n] = size(A);
if (nargin > 1) && isequal(how,'r')

% Rational basis

[R,pivcol] = rref(A);
r = length(pivcol);
nopiv = 1:n;
nopiv(pivcol) = [];
Z = zeros(n,n-r,class(A));
if n > r
Z(nopiv,:) = eye(n-r,n-r,class(A));
if r > 0
Z(pivcol,:) = -R(1:r,nopiv);
end
end
else

% Orthonormal basis

[U,S,V] = svd(A,0);
if m > 1, s = diag(S);
elseif m == 1, s = S(1);
else s = 0;
end
tol = max(m,n) * max(s) * eps(class(A));
r = sum(s > tol);
Z = V(:,r+1:n);
end

I am particularly interested in the Orthonormal basis part of the code since I was able to replicate the rref and this is the Eviews version I came up with:

'input matrix A -- just an example
matrix(4,3) A
A.fill(b=r) 3,2,1,2,2,3,5,4,5,1,3,4
'code actually starts from here
!nrow=@rows(A)
!ncol=@columns(A)
matrix W
vector V
matrix U=@svd(A,V,W)
if !nrow>1 then
vector s=V
else if !nrow=1 then
vector s=V(1)
else
vector s=0
endif
endif
!ns=@rows(s)
vector(2) dims
dims(1)=!nrow
dims(2)=!ncol
!tol=@max(dims)*@max(s)*1.49e-8
vector(!ns) eps=!tol
!r=@sum(@egt(s,eps))
matrix z=@subextract(U,1,1,!ncol,!r+1)

'I get "out of range" error message, whereas using the the matlab code I was able to obtain the result.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Orthogonal complement

Postby EViews Glenn » Tue May 17, 2016 3:04 pm

What did Matlab give you for that result? There aren't any zeros in the diagonal which is why you are getting an error in EViews (since it's trying to go beyond the original matrix size).

Here's a cleaned up version which simplifies things a bit and tests for the dimensionality of the subspace.

Code: Select all

matrix(3,3) A A.fill 2,0,0,0,1,0,2,0,0 'code actually starts from here !nrow=@rows(A) !ncol=@columns(A) vector S matrix V matrix U=@svd(A,S,V) !ns=@rows(S) vector(2) dims dims(1)=!nrow dims(2)=!ncol !tol=@max(dims)*@max(s)*1.49e-8 vector(!ns) eps=!tol !r=@sum(@egt(s,eps)) if !r>0 then matrix column_basis = @subextract(u, 1, 1, !nrow, !r) endif if !r<!ns then matrix null_basis = @subextract(v,1,!r+1,!nrow, !ncol) endif

olayenidynare
Posts: 6
Joined: Tue Mar 18, 2014 10:48 am

Re: Orthogonal complement

Postby olayenidynare » Wed May 18, 2016 9:37 am

Thank you Glenn. I have reviewed your code. It seems to work fine for square matrix. For rectangular matrix, as in the example given below, they don't come close. I compare the following Matlab result with the one from Eviews and find that the orthogonal complement is the last two columns (in this example) of the matrix U, which are not reported in Eviews. Here is the example. Given matrix A=[3,2,1;2,2,3;5,4,5;1,3,4;3,1,6], we have the following:

[V,S,U]=svd(A')

V =

-0.5282 0.5529 0.6445
-0.4346 0.4760 -0.7645
-0.7295 -0.6839 -0.0111


S =

12.4482 0 0 0 0
0 3.1174 0 0 0
0 0 2.0795 0 0


U =

-0.2557 0.6180 0.1891 0.4442 0.5653
-0.3305 0.0019 -0.1316 -0.7841 0.5086
-0.6448 0.4005 0.0522 -0.1461 -0.6322
-0.3816 -0.2422 -0.8145 0.3533 0.0869
-0.5138 -0.6316 0.5299 0.2042 0.1204

The orthogonal complement is then given as
Aperp=null(A')

Aperp =

0.4442 0.5653
-0.7841 0.5086
-0.1461 -0.6322
0.3533 0.0869
0.2042 0.1204
These two columns are the last two columns of matrix U.

In Eviews, on the other hand, we have the following:

matrix(5,3) A
A.fill(b=r) 3,2,1,2,2,3,5,4,5,1,3,4,3,1,6
vector S
matrix V
matrix U=@svd(A,S,V)

V=
-0.528207 0.552860 0.644472
-0.434618 0.475999 -0.764547
-0.729455 -0.683938 -0.011143

S=diag(12.44820,3.117372,2.079515)

U=
-0.255725 0.618033 0.189072
-0.330491 0.001894 -0.131559
-0.644815 0.400531 0.052154
-0.381572 -0.242158 -0.814489
-0.513807 -0.631638 0.529936

The last two target columns are not reported, and that is the snag!

Thank you once again. I will like to have your view on this.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Orthogonal complement

Postby EViews Glenn » Wed May 18, 2016 10:17 am

Ah, I see what your issue is...

EViews is reporting the economy form for the SVD for the non-square decomposition. If you want the full set of matrices required to do the subspace decomposition in the non-square case, you'll need to compute the eigenvalues directly.

I'll look into adding the alternate form of the SVD decomposition in future versions.


Return to “Estimation”

Who is online

Users browsing this forum: No registered users and 2 guests