Simulation outside of the range of the data

Use this forum to post Vensim related questions.
Post Reply
billh
Member
Posts: 45
Joined: Tue Jan 10, 2017 11:48 pm
Vensim version: DSS

Simulation outside of the range of the data

Post by billh »

In https://www.vensim.com/documentation/21170.htm, the manual says, "When the simulation is outside of the range of the data the closest value of the data will be used. This means that before 1938 the first value for atmospheric CFC 11 releases will be used and that in 1994 and beyond the last value will be used."

I'm creating a forecasting model, and, in one section, I care about three variables: the simulated value of a particular flow over the historical and forecast periods, the actual value in the historical period, and the actual value in the forecast period. The first exists over from INITIAL TIME to FINAL TIME, but the second only exists from INITIAL TIME to the start of the actual forecast, and the third from the start of the actual forecast until FINAL TIME. The first is simulated; the second and third are read using GET XLS DATA() and currently only used for a visual comparison with the simulated values in the historical and forecast periods. (At some time, I might use them to optimize other model parameters to make the distance between these get smaller.)

Normally, that works just fine: I can create a graph with the graph tool that shows all three, and they each appear in their own domains ("ranges" in the language of the manual).

However, I am reading the input data in metric units, and I am converting them to "customary" units for ease of interpretation by some users. When I do that, the quoted sentence applies, each of the data variables appears to have valid, constant (and erroneous) values over the entire domain, and the graph becomes confusing.

Is there a trick to make the above quote not apply--that is, to have the calculated variables retain the domain they had when read by GET XLS DATA() and be undefined elsewhere?
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Simulation outside of the range of the data

Post by tomfid »

I think you need two things:

1. For the data conversion, use a data equation rather than a regular equation. This preserves the "emptiness" of missing data. Something like:

distance M := distance in / in per M

2. For the forecast, use an IF THEN ELSE to set it to NA before it becomes active:

active forecast = IF THEN ELSE( is data, :NA:, whatever forecast is )

Then you can combine things:

operative value of x = IF THEN ELSE( is data, data, active forecast )

You can get the data timing automatically, via at least two methods:

a. Give the data the :RAW: keyword, then use an equation to check for :NA: values. This will let you detect missing points anywhere, including in the middle of the series, which you may not want.
b. Use INITIAL(GET DATA LAST TIME(data)) to discover the entpoint, then check IF THEN ELSE( time>last time, 0, 1) to set the "is data" flag.

We sometimes wrap the whole thing in a macro if there are several instances of this logic in a model.
billh
Member
Posts: 45
Joined: Tue Jan 10, 2017 11:48 pm
Vensim version: DSS

Re: Simulation outside of the range of the data

Post by billh »

Tom,

Thanks! The data equation idea seems to have done what I want. The customary forecast data for both the variables in question has the same domain as the metric forecast data, and the same is true of the historical data. The only combined data that spans both domains is the simulated result, and that has a domain that's the union of the other two domains, as it did previously.

I don't fully understand your second point, but it doesn't yet seem to be necessary.

The :RAW: and :NA: idea sounds good, except that the data has occasional dropouts, and I think you're right in that I'd want to avoid those.

I'll have to learn Vensim macros sometime, but, with only two equations, that doesn't seem to be necessary here.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Simulation outside of the range of the data

Post by tomfid »

The trouble with :RAW: data is that it's easy to forget that you've used the keyword, and then your model gets an occasional spurious :NA: that wrecks things.

When we use it, we often create a copy, like:

real data := GET XLS DATA( blabla )
raw data :RAW: := real data

That way it's harder to get mixed up. This trick works in macros, too.
Post Reply