Page 2 of 2
Re: simulated moments
Posted:
Thu Jul 03, 2014 12:05 pm
by quiko
quiko wrote:I think I have not been clear enough.
Recalling that n is the number of variables and s is the number of iterations, in my first question I wanted to see how the variance changes for each iteration. So, the command: moments(:,s)=diag(oo._var) did the right job by providing as output a nXs matrix. What I exactly need now is to have the covariance, but I want it for each variable with respect to all the others AND for each iteration. The command: covars=triu(oo._var) does't do the job because I get a nX1 vector.
Maybe what I need is the first raw of (oo._var), which should be the covariance of the first variable with respect to all the others. Then I could repeat manually the second raw, the third, and so on. But I don't know how to get this first raw from (oo_.var) instead of its diagonal, how to get something like: covars(:,s)=first_raw(oo._var).
Would it be correct the following?: covars(:,s)=(oo_.var(1,:));
Thank you for your replies.
Re: simulated moments
Posted:
Fri Jul 04, 2014 8:37 am
by jpfeifer
Then you are looking for something like
- Code: Select all
temp=triu(oo_.var,1)
covars(:,s)=temp(temp~=0);
Note that the vectorization is in row major order, i.e. you get the covariance of 1 with 2 first, then 1 with 3, 2 with 3, 1 with 4, 2 with 4 etc.
Re: simulated moments
Posted:
Sat Dec 20, 2014 10:34 pm
by hlt215
Hi again,
A further follow-up question about this. Instead of one loop over a parameter, I now have an additional loop over another parameter. Thus, two different loops in the same simulation. So I have:
gammas = 0.3:0.1:1;
for s = 1:length(gammas);
gamma = gammas(s);
alphas = 0.3:01:1;
for z = 1:length(alphas);
alpha = alphas(z);
stoch_simul(hp_filter = 1600, order = 1, nograph);
end;
end;
Previously, I extracted the variance by doing:
moments(:,s)=(diag(oo_.var));
How should I change the above command to account also for the other loop? I tried to do like this:
moments(:,t)=(diag(oo_.var)); where t = s*z. But I would like to put my results into a matrix of dimension s*z in which each element is the variance evaluated at a the specific pair of (s,z).
Re: simulated moments
Posted:
Sun Dec 28, 2014 10:52 am
by jpfeifer
The variances are a vector (1 dimension). Now you want to store this vector along two additional dimensions. The result will be three dimensional. How can you store it in a two dimensional matrix? This would only be possible if the variance is a scalar.
Re: simulated moments
Posted:
Sun Dec 28, 2014 1:15 pm
by hlt215
Thanks. What about if I only look at one variable? For example, the command moments(:,t) gives me all variables in the rows. If I look only at one variable, should I be able to get the variance stored in a matrix of dimension (s,z)? That is, each element of the matrix to be the variance evaluated at a specific pair (s,z)?
I exactly need a three dimension matrix because I would like to make a 3D plot. (I want to see how the variance changes when both parameters change at the same time).
Re: simulated moments
Posted:
Wed Dec 31, 2014 3:51 pm
by jpfeifer
In that case, you need something like
- Code: Select all
moments(:,t)=(diag(oo_.var));
var_sz(s,z)=moments(x,t);
Re: simulated moments
Posted:
Wed Dec 31, 2014 4:33 pm
by hlt215
Sorry, what's x?
Re: simulated moments
Posted:
Wed Dec 31, 2014 6:22 pm
by jpfeifer
The index of the variable you want to look at.