1
votes

I have to calculate:

gamma=(I-K*A^-1)*OLS;

where I is the identity matrix, K and A are diagonal matrices of the same size, and OLS is the ordinary least squares estimate of the parameters.

I do this in Matlab using:

gamma=(I-A\K)*OLS;

However I then have to calculate:

gamma2=(I-K^2*A-2)*OLS;

I calculate this in Matlab using:

gamma2=(I+A\K)*(I-A\K)*OLS;

Is this correct?

Also I just want to calculate the variance of the OLS parameters:

The formula is simple enough:

Var(B)=sigma^2*(Delta)^-1;

Where sigma is a constant and Delta is a diagonal matrix containing the eigenvalues.

I tried doing this by:

Var_B=Delta\sigma^2;

But it comes back saying matrix dimensions must agree?

Please can you tell me how to calculate Var(B) in Matlab, as well as confirming whether or not my other calculations are correct.

1

1 Answers

1
votes

In general, matrix multiplication does not commute, which makes A^2 - B^2 not equal to (A+B)*(A-B). However your case is special, because you have an identity matrix in the equation. So your method for finding gamma2 is valid.

'Var_B=Delta\sigma^2' is not a valid mldivide expression. See the documentation. Try Var_B=sigma^2*inv(Delta). The function inv returns a matrix inverse. Although this function can also be applied in your expression to find gamma or gamma2, the use of the operator \ is more recommended for better accuracy and faster computation.