Units Check whack-a-mole

Use this forum to post Vensim related questions.
Post Reply
sjgenco
Member
Posts: 25
Joined: Mon Sep 26, 2022 10:52 pm
Vensim version: PLE

Units Check whack-a-mole

Post by sjgenco »

I recently took on the task of converting an interesting model written in InsightMaker to VensimPLE. After various fits and starts, I succeeded in getting the Vensim model to exactly replicate all the equations, parameters, and output in the InsightMaker model. But now I'm dealing with some pesky unit errors that don't seem to affect the results, but when I try to fix one, it just pops up another one somewhere else.

The easiest way to communicate this seemed to be to send you the model, which I've attached. If you run it as is, I think it will generate 5 unit errors (when selecting Units Check). Three of these involve LOG or EXP functions, which Vensim insists must have dimensionless units. Here's one example:

Code: Select all

Error in units for the following equation:
logHumans  = 
        LOG ( population 
                  + 1, 
             10) 
logHumans  --> people
population  --> people

Analysis of units error:
Argument 1 of function LOG must be dimensionless
Here I'm just trying to take the log of my population output variable. Population is in units people, but the error tells me the argument in a LOG function must be dimensionless. If I change population and logHumans to units=dmnl, this error goes away, but population now causes errors in other equations.

Here's another example:

Code: Select all

Error in units for the following equation:
ccH  = 
        c 
             * pH 
             * ( 1
                  - EXP ( d 
                            * Knowledge ) ) 
             * ccE 
ccH  --> people/gha
c  --> people/gha
pH  --> Dmnl
d  --> Dmnl
Knowledge  --> 1/years
ccE  --> people/gha

Analysis of units error:
Argument 1 of function EXP must be dimensionless
d 
     * Knowledge 
Has Units: Dimensionless/Year
d is a dimensionless constant, but Knowledge in the model is in units 1/years. But I can't get rid of this "EXP must be dimensionless" unit error without making Knowledge dimensionless, which it is not.

The other type of error has to do with mismatches in the INTEG function for stocks. For example:

Code: Select all

Error in units for the following equation:
Knowledge  = 
        INTEG( Learning 
                  - Obsolescence , 
             Ko ) 
Knowledge  --> 1/years
Learning  --> 1/years
Obsolescence  --> 1/years
Ko  --> 1/years

Analysis of units error:
Units mismatch in INTEG
Learning 
     - Obsolescence 
Has Units: Dimensionless
Ko 
Has Units: Dimensionless/Year
Here I'm told I've got a unit mismatch. Knowledge is a stock, but it's a stock of yearly "amounts" of Knowledge, which is in units 1/years. It looks like the INTEG of Learning - Obsolescence, which defines Knowledge, must have units dmnl, but both variables are flows with units per year (1/years). How do I make the INTEG dimensionless when the included variables all have defined units?

Is there some general approach on how to deal with these sorts of unit errors? I find the documentation on Units Check to be pretty sparse.

Thank you!

FYI/BTW the InsightMaker model is here: https://insightmaker.com/insight/14FIlH ... 9/World4-5
An earlier version of Bystroff's model is described in this PLOS paper: https://journals.plos.org/plosone/artic ... ne.0247214
Attachments
bystroff.mdl
(34.98 KiB) Downloaded 94 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Units Check whack-a-mole

Post by tomfid »

The Log(Pop) error can be handled by defining something like

unit pop == 1 ~ person

and then normalizing

logpop = log( pop/unit pop + 1 )

The other two errors seem like a unit problem with knowledge. Flows always have units of their associated stock, divided by the time unit. Therefore if learning and obsolescence are in 1/yr, knowledge must be dimensionless. This would also reconcile the problem with Exp( d*Knowledge ), which only works with dmnl d if knowledge is also dmnl.
sjgenco
Member
Posts: 25
Joined: Mon Sep 26, 2022 10:52 pm
Vensim version: PLE

Re: Units Check whack-a-mole

Post by sjgenco »

Knowledge and Ignorance are key stocks in the model. Their "unit" is actually a little obscure in the InsightMaker model and the 2021 paper. Both basically represent the amount of technology in the system. "Knowledge" is the amount of useful technology and "Ignorance" is the amount of obsolete or damaging knowledge (like knowledge of fossil fuels or nuclear weapons). Ecosphere and Humansphere are much more explicit as stocks. They are measured in global hectares (gha). But, per your suggestion re "Knowledge", it looks like given the kinds or equations in the model (LOGs and EXPs, mainly), I have to make all these stocks dimensionless. Then, to fix other unit errors, I kept having to change constants to dmnl, even though some of them also represent real units, like initial rates (1/time) or stock levels (in gha or "knowledge"). Every unit check error that showed up in Units Check seemed to be fixable only by changing one variable and then another to dmnl. Eventually, I ended up with pretty much everything dmnl.

I'm still left with 4 stubborn unit errors, all of which are quite similar:

Code: Select all

***********************************************
Error in units for the following equation:
Ecosphere  = 
        INTEG( Rewilding 
                  - Domestication , 
             Eo ) 
Ecosphere  --> Dmnl
Rewilding  --> Dmnl
Domestication  --> Dmnl
Eo  --> Dmnl

Analysis of units error:
Units mismatch in INTEG
Rewilding 
     - Domestication 
Has Units: Year
Eo 
Has Units: Dimensionless

***********************************************
Error in units for the following equation:
Humansphere  = 
        INTEG( Domestication 
                  - Rewilding , 
             Ho ) 
Humansphere  --> Dmnl
Domestication  --> Dmnl
Rewilding  --> Dmnl
Ho  --> Dmnl

Analysis of units error:
Units mismatch in INTEG
Domestication 
     - Rewilding 
Has Units: Year
Ho 
Has Units: Dimensionless

***********************************************
Error in units for the following equation:
Ignorance  = 
        INTEG( Obsolescence 
                  - Learning , 
             Io ) 
Ignorance  --> Dmnl
Obsolescence  --> Dmnl
Learning  --> Dmnl
Io  --> Dmnl

Analysis of units error:
Units mismatch in INTEG
Obsolescence 
     - Learning 
Has Units: Year
Io 
Has Units: Dimensionless

***********************************************
Error in units for the following equation:
Knowledge  = 
        INTEG( Learning 
                  - Obsolescence , 
             Ko ) 
Knowledge  --> Dmnl
Learning  --> Dmnl
Obsolescence  --> Dmnl
Ko  --> Dmnl

Analysis of units error:
Units mismatch in INTEG
(I don't know why the last one fails to include the "Has Units" bit at the end)

If Rewilding, Domestication, Learning, and Obsolescence are all defined as unit=dmnl, why do each of these integrations end up with unit=Year?
And more immediately, how can I fix these units to fix these errors?
Thanks once more.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Units Check whack-a-mole

Post by tomfid »

A stock equation is the integral of a flow over time, so the stock unit has the flow unit * time unit.

This is easier to see if you write the discrete update that happens with Euler integration:

stock(t+dt) = stock(t) + dt*(inflows-outflows)

were t=time, dt=TIME STEP in Vensim. This has units:

stockstuff = stockstuff + timestuff*(stockstuff/timestuff)

My guess is that humansphere should be dmnl, and domestication and rewilding should have units of 1/year (dmnl/year). If this doesn't flow naturally from the equations, my guess is that the parameters that describe rewilding (etc.) have an unstated implicit rate constant or time constant (i.e. something with units of year or fraction/year).

Does the original in insightmaker have units defined & checked?
sjgenco
Member
Posts: 25
Joined: Mon Sep 26, 2022 10:52 pm
Vensim version: PLE

Re: Units Check whack-a-mole

Post by sjgenco »

Thanks Tom, for your patience in helping me work thru this. I was able to use your suggestion to get down to 2 unit errors. I did make Knowledge and Ignorance dimensionless, and Learning and Obsolescence 1/Year, and that got rid of some of the EXP and LOG errors. I was also able to put the Environment stocks and flows into more realistic units. The stocks are in units of area (global hectares, gha) and the flows are in units gha/Year. I was able to eliminate some other errors by adjusting units on some less important variables. I didn't quite understand your earlier point about logpop so I just left all those variables dimensionless. They are only for output anyway, so that just felt like cluttering up the model for no good reason.

That left me with two unit errors. The first:

Code: Select all

Error in units for the following equation:
g0  = 
        ( Io 
             + LN ( 2) 
                  / t ) 
             * ( 1
                  - EXP ( u 
                            * pE ) ) 
g0  --> 1/Year
Io  --> Dmnl
t  --> Year
u  --> Dmnl
pE  --> Dmnl

Analysis of units error:
Units mismatch
Io 
Has Units: Dimensionless
LN ( 2) 
     / t 
Has Units: Dimensionless/Year
[g0] is the initial growth rate for Domestication. This rate gets multiplied by other factors (that increase or dampen the growth rate) under different conditions. The problem here appears to be easily fixable by changing [t] (which is indeed a variable representing a number of years) to unit dmnl. But this just triggers a unit error elsewhere in the equation. Here's what that unit error would be if [t] were set to unit dmnl:

Code: Select all

Error in units for the following equation:
g0  = 
        ( Io 
             + LN ( 2) 
                  / t ) 
             * ( 1
                  - EXP ( u 
                            * pE ) ) 
g0  --> 1/Year
Io  --> Dmnl
t  --> Dmnl
u  --> Dmnl
pE  --> Dmnl

Analysis of units error:
Right hand and left hand units do not match
g0 
Has Units: Dimensionless/Year
( Io 
     + LN ( 2) 
          / t ) 
     * ( 1
          - EXP ( u 
                    * pE ) ) 
Has Units: Dimensionless
So that's the whack-a-mole problem again. I decided to accept the error with keeping [t] as unit Year, since that's its actual unit. (This is the only equation in which [t] appears.)

The second unit error is trickier:

Code: Select all

Error in units for the following equation:
Rewilding  = 
        Ignorance 
             * Humansphere 
Rewilding  --> gha/Year
Ignorance  --> Dmnl
Humansphere  --> gha

Analysis of units error:
Right hand and left hand units do not match
This, I believe, might actually be reflecting some conceptual issues with the model. Rewilding, in correct units of gha/Year, is how Ecosphere grows with increased Ignorance. Ignorance grows as Knowledge shrinks (due to changes in Obsolescence and Learning flows). But I don't see any way to reconcile the units for this equation, with Rewilding coming from the Environment flows (with gha-unit stocks) and Ignorance coming from the Technology flows (with dimensionless stocks). I don't think I can fix it without causing a bunch of other unit errors elsewhere in the model. Believe me, I've tried.

Interestingly, regarding your last question, all the variables in the InsightMaker model as set to units "Unitless", although their actual units are described in the comments included with each variable's equation. So I suspect I'm not the first to run into unit problems with this model.

So that's where I'm at with this thing. I've attached the latest version of the model if anybody wants to take a look.
Attachments
bystroff_v2.mdl
(34.85 KiB) Downloaded 96 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Units Check whack-a-mole

Post by tomfid »

I'll take a look in greater depth Monday, but I tend to agree that these errors reflect some conceptual issues with the model. I find the rewilding equation extremely weird. I'd probably fix the units by adding an explicit parameter, with value 1, to make clear that there's an implicit conversion going on.

Unfortunately I've run into this kind of thing before in widely-used models that were allegedly peer reviewed. https://metasd.com/2010/03/fuzzy-vision/
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: Units Check whack-a-mole

Post by LAUJJL »

Hi
It might be better to use the strict unit testing. If you use the strict unit testing two more errors will appear in both models. But I do not think that these errors have anything to do with your problem.
JJ
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Units Check whack-a-mole

Post by tomfid »

After a closer look, my conclusion is that the model is kind of bonkers. Normally units prevent conceptual errors like mixing up stocks and flows, but in this case I think the general difficulty in defining units is a big red flag in itself. It means that the model is rather far from an operational description of how things work.
sjgenco
Member
Posts: 25
Joined: Mon Sep 26, 2022 10:52 pm
Vensim version: PLE

Re: Units Check whack-a-mole

Post by sjgenco »

Yes, I think it's the Ignorance stock that's particularly problematic. It's defined as Obsolescence-Learning, and both of those are rates/year, so it has to be a stock of rates, which gets very weird very quickly. I can conceptualize Knowledge as a "thing" that can be acquired or depleted, but Ignorance doesn't seem to be a stock of anything, just a measure of the sum of Knowledge depletion and Knowledge acquisition in a given year. If there's more depletion than acquisition, Ignorance goes up, but it goes up in the same amount as Knowledge goes down, so basically it's not a different "thing". Probably a better logic would be to have one stock, Knowledge, and two flows, Knowledge-in (increasing Knowledge=Learning) and Knowledge-out (decreasing Knowledge=Obsolescence). Then the effects of Knowledge on Environment can be modeled more realistically in terms of Rewilding and Domestication, which are basically moving global hectares from the Humansphere to Ecosphere and back again, based on whether Knowledge is being gained or lost, which determines humans' ability to maintain a carrying capacity, which determines how much population the system can tolerate.

Appreciate the tip on Ventity, by the way. It looks like if I got the "public research" version of Pro (that fits what I do), it would not include the Ventity subscription. Is that correct? Also, I'm not a big fan of subscriptions and try to avoid them. Will there ever be a full-purchase option for Ventity, and if so, what might that price be? Thanks!
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Units Check whack-a-mole

Post by tomfid »

Ventity licensing will be changing to look more like Vensim. In the meantime, we'll include a license with a Pub Rsch Vensim Pro license (email us at info at ventity.biz if it doesn't happen automatically).
Post Reply