IRIS-Solutions-Team / IRIS-Toolbox

[IrisToolbox] for Macroeconomic Modeling
Other
92 stars 42 forks source link

prctile() function does not work anymore with 2020 IRIS version #288

Closed alaingalli closed 3 years ago

alaingalli commented 3 years ago

Hi there!

In older IRIS versions, it was possible to apply the prctile() function to IRIS timeseries. However, with more recent versions (2020) and Matlab 2020b, I am not able to so anymore. Both of the following commands return the input timeseries instead of of the percentile:

prctile(Series(qq(2020,2), [ 2 4 70 2 20 30 50]'),20) prctile(tseries(qq(2020,2), [ 2 4 70 2 20 30 50]'),20)

jaromir-benes commented 3 years ago

Hi

You are creating a time series with a single column of observations. Because by default, the percentiles are calculated in 2nd dimension, this obviously results in the same series being returned - in other words, in each row, the percentiles are found out of all numbers in that row. Because each row contains just one number, this is the one returned.

To see how the function works, try this example

x = Series(qq(2020,1), rand(8, 20)); prctile(x, 20)

Best Jaromir

On Dec 2, 2020, at 6:02 PM, alaingalli notifications@github.com wrote:

 Hi there!

In older IRIS versions, it was possible to apply the prctile() function to IRIS timeseries. However, with more recent versions (2020) and Matlab 2020b, I am not able to so anymore. Both of the following commands return the input timeseries instead of of the percentile:

prctile(Series(qq(2020,2), [ 2 4 70 2 20 30 50]'),20) prctile(tseries(qq(2020,2), [ 2 4 70 2 20 30 50]'),20)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

alaingalli commented 3 years ago

Hey Jaromir. On my opinion, the percentiles should be calculated by column and not by row. This also what what is done when prctile() is applied to a vector/matrix:

prctile(rand(30, 5),20) gives

ans = 0.0991 0.2203 0.1305 0.3996 0.3488

i.e. the 20 percentile of each column.

This was also the case in older IRIS versions:

prctile(tseries(qq(1990,1),rand(30, 5)),20) gave

ans = 0.2842 0.2051 0.2247 0.4272 0.0879

However, with the 2020 IRIS version, the same command now returns a time series, i.e. the 20th percentile by row:

tseries Object: 30-by-1 Class of Data: double

1990Q1:   0.17595
1990Q2:   0.21207
1990Q3:   0.28065
1990Q4:   0.32023
1991Q1:   0.42374
1991Q2:   0.21433
1991Q3:   0.29765
1991Q4:   0.42395
1992Q1:   0.09763
1992Q2:   0.23038
1992Q3:   0.14561
1992Q4:   0.11923
1993Q1:   0.12056
1993Q2:   0.27893
1993Q3:   0.37718
1993Q4:    0.0676
1994Q1:   0.10481
1994Q2:   0.54636
1994Q3:   0.40025
1994Q4:   0.15312
1995Q1:   0.10104
1995Q2:   0.24612
1995Q3:   0.18969
1995Q4:   0.36149
1996Q1:   0.29619
1996Q2:   0.48376
1996Q3:  0.088125
1996Q4:   0.14094
1997Q1:  0.057366
1997Q2:   0.30494
jaromir-benes commented 3 years ago

Hi

First of all, you have full control along which dimension to calculate the percentiles. Use an extra input argument to specify that, for instance

x = Series(qq(2020,1), rand(10,10,10)) prctile(x, 20) % 20th percentile along 2nd dimension (among numbers in rows) - returns a 10 by 1 by 10 series prctile(x, 20, 1) % 20th percentile along 1st dim - returns a 1 by 10 by 10 array prctile(x, 20, 3) % 20th percentile along 3nd dimension - returns a 10 by 10 by 1 series

Second, it's really questionable what the default behavior should be. The way I myself use this function the most frequently (by far) is, for instance, the following: I draw a large number of parameters (from their distribution) and create a model with multiple parameter sets, plus I draw a large number of columns for shocks, and then run a simulation, producing an output databank where each variable is a time series with a large number of columns (each column corresponding to simulating a model with a particular set of parameters and a particular set of shocks).

Then, I want to visualize the empirical distribution for the evolution of the model variables - mean, median, percentiles, etc. For that, I need the prctile function to work along 2nd dimension.

Best, Jaromir

On Thu, Dec 3, 2020 at 8:58 AM alaingalli notifications@github.com wrote:

Hey Jaromir. On my opinion, the percentiles should be calculated by column and not by row. This also what what is done when prctile() is applied to a vector/matrix:

prctile(rand(30, 5),20) gives

ans = 0.0991 0.2203 0.1305 0.3996 0.3488

i.e. the 20 percentile of each column.

This was also the case in older IRIS versions:

prctile(tseries(qq(1990,1),rand(30, 5)),20) gave

ans = 0.2842 0.2051 0.2247 0.4272 0.0879

However, with the 2020 IRIS version, the same command now returns a time series, i.e. the 20th percentile by row:

tseries Object: 30-by-1 Class of Data: double

1990Q1: 0.17595 1990Q2: 0.21207 1990Q3: 0.28065 1990Q4: 0.32023 1991Q1: 0.42374 1991Q2: 0.21433 1991Q3: 0.29765 1991Q4: 0.42395 1992Q1: 0.09763 1992Q2: 0.23038 1992Q3: 0.14561 1992Q4: 0.11923 1993Q1: 0.12056 1993Q2: 0.27893 1993Q3: 0.37718 1993Q4: 0.0676 1994Q1: 0.10481 1994Q2: 0.54636 1994Q3: 0.40025 1994Q4: 0.15312 1995Q1: 0.10104 1995Q2: 0.24612 1995Q3: 0.18969 1995Q4: 0.36149 1996Q1: 0.29619 1996Q2: 0.48376 1996Q3: 0.088125 1996Q4: 0.14094 1997Q1: 0.057366 1997Q2: 0.30494

— 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/288#issuecomment-737732600, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGCVKKSUTNS75EWODVROVRLSS5AJFANCNFSM4UKYSVIA .

alaingalli commented 3 years ago

Thanks for your feedback Jaromir! We now adjusted all our codes and use the prctile() function using the extra input argument so that it continues to work with timeseries like before.

I fully understand your point and it makes sense what you say. It's just that I/we got used to the behaviour that buit-in matlab functions that are applicable to IRIS tseries/Series objects usually work with the same defaults/syntax when applied to time series instead of vectors/matrices.

Best, Alain