simulated moments

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Re: simulated moments

Postby quiko » Thu Jul 03, 2014 12:05 pm

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.
quiko
 
Posts: 17
Joined: Sat Mar 29, 2014 11:06 pm

Re: simulated moments

Postby jpfeifer » Fri Jul 04, 2014 8:37 am

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: simulated moments

Postby hlt215 » Sat Dec 20, 2014 10:34 pm

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).
hlt215
 
Posts: 14
Joined: Mon Sep 15, 2014 11:54 am

Re: simulated moments

Postby jpfeifer » Sun Dec 28, 2014 10:52 am

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: simulated moments

Postby hlt215 » Sun Dec 28, 2014 1:15 pm

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).
hlt215
 
Posts: 14
Joined: Mon Sep 15, 2014 11:54 am

Re: simulated moments

Postby jpfeifer » Wed Dec 31, 2014 3:51 pm

In that case, you need something like
Code: Select all
moments(:,t)=(diag(oo_.var));
var_sz(s,z)=moments(x,t);
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: simulated moments

Postby hlt215 » Wed Dec 31, 2014 4:33 pm

Sorry, what's x?
hlt215
 
Posts: 14
Joined: Mon Sep 15, 2014 11:54 am

Re: simulated moments

Postby jpfeifer » Wed Dec 31, 2014 6:22 pm

The index of the variable you want to look at.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Previous

Return to Dynare help

Who is online

Users browsing this forum: No registered users and 11 guests