IRIS-Solutions-Team / IRIS-Toolbox

[IrisToolbox] for Macroeconomic Modeling
Other
90 stars 41 forks source link

shock decomposition grouping error #308

Open nfaqs opened 2 years ago

nfaqs commented 2 years ago

I am attempting to run the following code

g = grouping(m_kf,'Shocks');

where m_kf is the result of a Kalman filter applied to the IRIS model object m, which in turn had been solved and had its steady state computed, i.e.

m = model('model\model.model','linear=',true,'assign',p);
m = solve(m);
m = sstate(m);
...
[m_kf,g,v,delta,pe] = filter(m,dd,sdate:edate);

where the ellipsis above stands for all the other relevant things such as defining dd, etc. The above code runs without issue, but when I attempt to run the line mentioned above g = grouping(m_kf,'Shocks'); I get the following error:

Undefined function 'access' for input arguments of type 'model'.

Error in model/prepareGrouping (line 30)
g.IsLog = access(this, "is-log");

Error in grouping (line 137)
            this = prepareGrouping(m_kf, this, type, opt);

Does anyone know what might be causing this error? I inherited this code so it presumably ran at some point, but I haven't not been able to get it to run by using old versions of IRIS.

Thanks in advance for any insight you can add.

jaromir-benes commented 2 years ago

Hi

The model object is a legacy object included in Iris only for basic backward compatibility reasons.

Please switch to the standard Model object (capitalized).

m = Model.fromFile('model\model.model','linear', true, 'assign', p);

or in new Matlab versions you can use the following syntax for options:

m = Model.fromFile('model\model.model', linear=true, assign=p);

Best

Jaromir

On Mon, Dec 6, 2021 at 9:03 PM nfaqs @.***> wrote:

I am attempting to run the following code

g = grouping(m_kf,'Shocks');

where m_kf is the result of a Kalman filter applied to the IRIS model object m, which in turn had been solved and had its steady state computed, i.e.

m = model('model\model.model','linear=',true,'assign',p); m = solve(m); m = sstate(m); ... [m_kf,g,v,delta,pe] = filter(m,dd,sdate:edate);

where the ellipsis above stands for all the other relevant things such as defining dd, etc. The above code runs without issue, but when I attempt to run the line mentioned above g = grouping(m_kf,'Shocks'); I get the following error:

Undefined function 'access' for input arguments of type 'model'.

Error in model/prepareGrouping (line 30) g.IsLog = access(this, "is-log");

Error in grouping (line 137) this = prepareGrouping(m, this, type, opt);

Error in report_filter (line 451) g = grouping(m,'Shocks');

Does anyone know what might be causing this error? I inherited this code so it presumably ran at some point, but I haven't not been able to get it to run by using old versions of IRIS.

Thanks in advance for any insight you can add.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/IRIS-Solutions-Team/IRIS-Toolbox/issues/308, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGCVKKV7ZXRCSYV4TLLF7EDUPUJK3ANCNFSM5JPP2LWA .

nfaqs commented 2 years ago

Thanks for the quick reply. I implemented this change and it seems to have fixed that problem! But now I get the following error, which is actually based on the line immediately preceding the call to grouping(m_kf,'Shocks');,

decomp.simulate_db = simulate(m,db.mean,start_date:end_date+13,'contributions',true,'anticipate',false,'deviation', false, 'plan',
simplan);

The error message is:

Not enough input arguments.

Error in plan/isempty (line 3)
switch query

Error in Model/simulate>locallyValidatePlanOption (line 692)
    if isempty(x) || isequal(x, true) || isequal(x, false) || isa(x, 'Plan')

Error in Model/simulate

Error in report_filter (line 448)
decomp.simulate_db = simulate(m,db.mean,start_date:end_date+13,'contributions',true,'anticipate',false,'deviation', false, 'plan',
simplan);

Note that where it says m it should say m_kf to be consistent with my notation from above (it says m because in my code this is in turn called in another user-defined function).

It is apparently complaining about the simulation plan. It is previously defined as follows

simplan = plan(m,start_date:end_date+23);

db.mean.RS_RW         = dd.OBS_RS_RW;
db.mean.RR_RW_BAR     = dd.OBS_RR_RW_BAR;
db.mean.L_CPI_RW      = dd.OBS_L_CPI_RW;
db.mean.L_GDP_RW_GAP  = dd.OBS_L_GDP_RW_GAP;

simplan = exogenize(simplan,{'L_CPI_RW'},start_date:end_date+7);
simplan = exogenize(simplan,{'RS_RW'},start_date:end_date+7);
simplan = exogenize(simplan,{'L_GDP_RW_GAP'},start_date:end_date+7);
simplan = exogenize(simplan,{'RR_RW_BAR'},start_date:end_date+7);

simplan = endogenize(simplan,{'SHK_DLA_CPI_RW'},start_date:end_date+7);
simplan = endogenize(simplan,{'SHK_RS_RW'},start_date:end_date+7);
simplan = endogenize(simplan,{'SHK_L_GDP_RW_GAP'},start_date:end_date+7);
simplan = endogenize(simplan,{'SHK_RR_RW_BAR'},start_date:end_date+7);

% Defining world food and oil prices -- GPM (from database)
 db.mean.DLA_WFOOD = dd.OBS_DLA_WFOOD;
 db.mean.DLA_WOIL  = dd.OBS_DLA_WOIL; 

simplan = exogenize(simplan,{'DLA_WFOOD'},start_date:end_date+7);
simplan = exogenize(simplan,{'DLA_WOIL'},start_date:end_date+7);

simplan = endogenize(simplan,{'SHK_DLA_WFOOD'},start_date:end_date+7);
simplan = endogenize(simplan,{'SHK_DLA_WOIL'},start_date:end_date+7);

where dd is the database of observables. I am defining a simulation plan analogously elsewhere (when I do forecasts) and it seems to work, so I'm not sure what it is going wrong here.

If you see anything that might be the culprit it would be greatly appreciated.

jaromir-benes commented 2 years ago

Hi

There is also a new a Plan object to work with the new Model - mind the capitalization.

Create

simplan = Plan.forModel(m, range); simplan = exogenize(simplan, periods, ["variable1", "variable2"]); simplan = exndogenize(simplan, periods, ["shock1", "shock2"]);

Etc.

Ill send you a link to a basic tutorial with in the morning (night here now).

Best J

On Mon, Dec 6, 2021, 9:28 PM nfaqs @.***> wrote:

Thanks for the quick reply. I implemented this change and now I get the following error, which is actually based on the line immediately preceding the call to grouping(m_kf,'Shocks');,

decomp.simulate_db = simulate(m,db.mean,start_date:end_date+13,'contributions',true,'anticipate',false,'deviation', false, 'plan', simplan);

The error message is:

Not enough input arguments.

Error in plan/isempty (line 3) switch query

Error in Model/simulate>locallyValidatePlanOption (line 692) if isempty(x) || isequal(x, true) || isequal(x, false) || isa(x, 'Plan')

Error in Model/simulate

Error in report_filter (line 448) decomp.simulate_db = simulate(m,db.mean,start_date:end_date+13,'contributions',true,'anticipate',false,'deviation', false, 'plan', simplan);

Note that where it says m it should say m_kf to be consistent with my notation from above (it says m because in my code this is in turn called in another user-defined function).

For reference, the full sequence of commands that appear to be problematic is

% Simulate contributions decomp.simulate_db = Model.simulate(m,db.mean,start_date:end_date+13,'contributions',true,'anticipate',false,'deviation', false, 'plan', simplan);

%Create groups for shock decomposition g = grouping(m,'Shocks'); for j = 1:length(decomp.shock_decomp_shocks) g = addgroup(g, decomp.shock_decomp_groups{j}, decomp.shock_decomp_shocks{j}); end decomp.shock_contrib_db = eval(g,decomp.simulate_db);

Thank you again for your help.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/IRIS-Solutions-Team/IRIS-Toolbox/issues/308#issuecomment-987181197, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGCVKKXWW5HOLNTEWRMTQGLUPUMGHANCNFSM5JPP2LWA .

nfaqs commented 2 years ago

Fantastic, thank you! It seems to have fixed that problem. There are now some other problems, e.g. it says I can't use anticipate and plan options in the same simulate command, and when I remove that, that contributions option cannot be used in a plan with exogenized variables.

Since these are clearly fundamental issues with the syntax of the function, I will take a look at the tutorial first and let you know if I can't figure it out. Thanks again!

jaromir-benes commented 2 years ago

Hi - when using a Plan, the anticipation status is set when creating the plan

p = Plan.forModel(m, range, "anticipate", true/false)

true by default

When running a contributions simulation, first run the simulate command with a plan, and then resimulate thevresults using the calculated shocks, activating the contributions option

J

On Mon, Dec 6, 2021, 10:14 PM nfaqs @.***> wrote:

Fantastic, thank you! It seems to have fixed that problem. There are now some other problems, e.g. it says I can't use anticipate and plan options in the same simulate command, and when I remove that, that contributions option cannot be used in a plan with exogenized variables.

Since these are clearly fundamental issues with the syntax of the function, I will take a look at the tutorial first and let you know if I can't figure it out. Thanks again!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/IRIS-Solutions-Team/IRIS-Toolbox/issues/308#issuecomment-987221585, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGCVKKSJCEJGWKQROIOLOIDUPURUPANCNFSM5JPP2LWA .

nfaqs commented 2 years ago

Great, thanks. The code seems to run now. Thank you so much for your amazingly fast and helpful replies! I look forward to the tutorial you send tomorrow.

jaromir-benes commented 2 years ago

Check out this link - the shock decomposition example is in run15_filterHistData - based on a kalman filter, but the idea is the same. Best, Jaromir

On Mon, Dec 6, 2021 at 10:46 PM nfaqs @.***> wrote:

Great, thanks. The code seems to run now. Thank you so much for your amazingly fast and helpful replies! I look forward to the tutorial you send tomorrow.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/IRIS-Solutions-Team/IRIS-Toolbox/issues/308#issuecomment-987262637, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGCVKKQS7R3L3AL5NNMQEGLUPUVM3ANCNFSM5JPP2LWA .

nfaqs commented 2 years ago

Hi Jaromir,

I'm not sure the link made it through. Is this one of the tutorials on the Iris homepage?

jaromir-benes commented 2 years ago

This is the link:

https://github.com/IRIS-Solutions-Team/Tutorial-Simple-SPBC-Model

nfaqs commented 2 years ago

Thanks!


From: Jaromír Beneš @.> Sent: Tuesday, December 7, 2021 3:07:17 PM To: IRIS-Solutions-Team/IRIS-Toolbox @.> Cc: Fernandez-Arias, Nicolas @.>; Author @.> Subject: Re: [IRIS-Solutions-Team/IRIS-Toolbox] shock decomposition grouping error (Issue #308)

[External email – Caution]

This is the link:

https://github.com/IRIS-Solutions-Team/Tutorial-Simple-SPBC-Modelhttps://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FIRIS-Solutions-Team%2FTutorial-Simple-SPBC-Model&data=04%7C01%7Cnfernandez-arias%40imf.org%7Cc254b164cf0343ef9dcd08d9b9bd2ba9%7C8085fa43302e45bdb171a6648c3b6be7%7C0%7C0%7C637745044392268895%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=WJHiSvXKdzJlO9txVUzy8%2F8UgY6TCBNt8Q9G7O0%2FUvM%3D&reserved=0

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FIRIS-Solutions-Team%2FIRIS-Toolbox%2Fissues%2F308%23issuecomment-988229482&data=04%7C01%7Cnfernandez-arias%40imf.org%7Cc254b164cf0343ef9dcd08d9b9bd2ba9%7C8085fa43302e45bdb171a6648c3b6be7%7C0%7C0%7C637745044392268895%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=dp3TxCeQ1%2BJZFApkcv%2F%2BpewNi9EHXxUjqNJgBnmM9sk%3D&reserved=0, or unsubscribehttps://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAWZYZNEN4RKLONMXAN2OOYTUPZSPLANCNFSM5JPP2LWA&data=04%7C01%7Cnfernandez-arias%40imf.org%7Cc254b164cf0343ef9dcd08d9b9bd2ba9%7C8085fa43302e45bdb171a6648c3b6be7%7C0%7C0%7C637745044392268895%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=wIGhr0Qze%2BRhyGxH9WHeAVdxKThDYl75eReHBEpCvuQ%3D&reserved=0. Triage notifications on the go with GitHub Mobile for iOShttps://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fapps.apple.com%2Fapp%2Fapple-store%2Fid1477376905%3Fct%3Dnotification-email%26mt%3D8%26pt%3D524675&data=04%7C01%7Cnfernandez-arias%40imf.org%7Cc254b164cf0343ef9dcd08d9b9bd2ba9%7C8085fa43302e45bdb171a6648c3b6be7%7C0%7C0%7C637745044392268895%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=0pSvkXvHvHkamH%2BcTDVLBDUCl3zdINyX3FrSH%2F8kTPs%3D&reserved=0 or Androidhttps://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.github.android%26referrer%3Dutm_campaign%253Dnotification-email%2526utm_medium%253Demail%2526utm_source%253Dgithub&data=04%7C01%7Cnfernandez-arias%40imf.org%7Cc254b164cf0343ef9dcd08d9b9bd2ba9%7C8085fa43302e45bdb171a6648c3b6be7%7C0%7C0%7C637745044392268895%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=C%2BexX0C1OqW1ioCXkSGCTif1PZWx0e3Ic8uMrqkTxeo%3D&reserved=0.