units for %

Use this forum to post Vensim related questions.
Post Reply
sya_ouniversity
Junior Member
Posts: 5
Joined: Mon Oct 21, 2024 12:07 pm
Vensim version: PLE

units for %

Post by sya_ouniversity »

Hi,
In my model I use a lot of 'share' or 'percentage' as variables, for example, the share of sewer load that runs through the seperated sewer, or the share of electric vehicles. However, Vensim does not seem to accept % as a unit. And therefore I have a lot of missing unit errors. Does anyone have any tips on how to overcome this?

Thank you!
Administrator
Super Administrator
Posts: 4701
Joined: Wed Mar 05, 2003 3:10 am

Re: units for %

Post by Administrator »

Use DMNL (dimensionless).
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3889
Joined: Wed May 24, 2006 4:54 am

Re: units for %

Post by tomfid »

I use "fraction" if it's a share (0-1) and "percent" if it's really %, 0-100. I usually define a constant, like "hundred percent = 100 ~ percent" for converting between the two.
Travis
Senior Member
Posts: 172
Joined: Tue Jul 15, 2008 8:42 pm

Re: units for %

Post by Travis »

I do something similar to Tom, including a constant model variable for conversion so the units pass the unit check.

To draw out something Tom eluded to, please name your model's variables appropriately. If the value is 0-1, then it should be "Fraction of Population that Loves Pizza". If is a 0-100, then "Percentage of Population that Loves Pizza". This is important so that others that look at your diagrams and try to use your model can make sense of it. I've used models that mix and match, or name valuables "Percentage of..." for values from 0-1, and I find that very confusing.
LAUJJL
Senior Member
Posts: 1460
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: units for %

Post by LAUJJL »

In this thread, there is a question of units. Are these strict or non-strict unit tests?

JJ
Travis
Senior Member
Posts: 172
Joined: Tue Jul 15, 2008 8:42 pm

Re: units for %

Post by Travis »

I’m not sure I follow your question but I think “strict” is the answer. “Percent” is a unit like “dollar” and Vensim applies normal units checking.
LAUJJL
Senior Member
Posts: 1460
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: units for %

Post by LAUJJL »

If you click on model settings and units, on the top of the window you can check use stict testing. i just wanted to know if you use strict testing or not.

JJ
Travis
Senior Member
Posts: 172
Joined: Tue Jul 15, 2008 8:42 pm

Re: units for %

Post by Travis »

Oh, I didn't know about the setting. A quick spot check of my models shows that 'strict' is off, which I assume is the default.
sya_ouniversity
Junior Member
Posts: 5
Joined: Mon Oct 21, 2024 12:07 pm
Vensim version: PLE

Re: units for %

Post by sya_ouniversity »

Thank you all for the good advice! I like the idea of making a constant to refer to percentages.
I also didn't know about the strict unit setting. For me 'strict was also off.
LAUJJL
Senior Member
Posts: 1460
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: units for %

Post by LAUJJL »

Hi

Not many Vensim users are familiar with this strict testing feature.

For example, if you add 5 to a variable and that variable has a dimension, e.g. people/year, Vensim assumes that 5 has a dimension equal to that of the variable, unless the strict test is on, in which case there is a unit error report.
The problem is that some unreported unit errors can hide a calculation error in an equation.

For example, in the world3 model joint, if you do the test in off mode, Vensim does not declare any errors. If you put the test on on, Vensim declares 9 errors, 3 of which are in the maturation of the aging population chain.

However, there is an error in the equation on maturation. If we simulate an epidemic in the cohort of children that causes half of the children to die in 6 months, by setting the mortality per year to 1. We notice that during the 6 months of the epidemic, no child passes into the next cohort, which is false. By studying the maturation equation closely, it is easy to understand where the error comes from.
I am attaching the corrected worldmodel3_corrected of the 3 maturation errors.

I also attach the worldmodel3_epidemic model which simulates an epidemic in the year 2020 for 6 months with the result file epidemic.vdfx.
See the thread viewtopic.php?t=7859
in same forum;

Best.

JJ
Attachments
wrld3-03_corrected.mdl
(150.51 KiB) Downloaded 71 times
wrld3-03_epidemic.mdl
(149.46 KiB) Downloaded 71 times
wrld3-03.mdl
(149.08 KiB) Downloaded 67 times
LAUJJL
Senior Member
Posts: 1460
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: units for %

Post by LAUJJL »

the epidemic.vdfx file
Attachments
epidemic.vdfx
(594.54 KiB) Downloaded 69 times
LAUJJL
Senior Member
Posts: 1460
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: units for %

Post by LAUJJL »

Hi

I notice that the attached files are regularly downloaded.

Unfortunately, this does not seem to awaken the slightest reaction from readers. What did they understand? Does this leave them indifferent? Are they afraid to make a remark? I would like to see a few remarks.

I also want to point out that I don't bite, especially across the ocean, at least not yet!

Yours truly.

JJ
Administrator
Super Administrator
Posts: 4701
Joined: Wed Mar 05, 2003 3:10 am

Re: units for %

Post by Administrator »

They might be downloaded by search bots.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3889
Joined: Wed May 24, 2006 4:54 am

Re: units for %

Post by tomfid »

Also it was Thanksgiving holiday in the US.
tomfid
Administrator
Posts: 3889
Joined: Wed May 24, 2006 4:54 am

Re: units for %

Post by tomfid »

This is a very interesting discovery. The equations in question are:

Code: Select all

maturation 14 to 15  = 
        ( ( Population 0 To 14 ) ) 
             * ( 1
                  - mortality 0 to 14 ) 
             / 15
Units: Person/year
The fractional rate at which people aged 0-14 mature into the 
        next age cohort (MAT1#5).

**************************************************************
mortality 0 to 14=
    IF THEN ELSE(Time = 2020 * one year, 1 / one year, mortality 0 to 14 table
 ( life expectancy/one year ) )
Units: 1/year
The fractional mortality rate for people aged 0-14 (M1#4).

**************************************************************
(The second is the one modified for the pulse mortality test.)

In the 'maturation 14 to 15' equation, the obvious issue is that '15' is a hidden dimensioned parameter. One might argue that this instance is 'safe' because 15 years is definitionally the residence time of people in the 0 to 15 cohort - but I would still avoid this usage, and make the 15 yrs a named parameter, like "child cohort duration", with a corresponding name change to the stock. If nothing else, this would make the structure easier to reuse.

The sneaky bit here, revealed by JJ's test, is that the '1' in the term (1 - mortality 0 to 14) is not a benign dimensionless number, as we often assume in constructions like 1/(1+a*x). This 1 actually represents the maximum feasible stock outflow rate, in fraction/year, implying that a mortality rate of 1/yr, as in the test input, would consume the entire outflow, leaving no children alive to mature into the next cohort. This is incorrect, because the maximum feasible outflow rate is 1/TIME STEP, and TIME STEP = 0.5, so that 1 should really be 2 ~ frac/year. This is why maturation wrongly goes to 0 in JJ's experiment, where some children remain to age into the next cohort.

In addition, this construction means that the origin of units in the equation are incorrect - the '15' has to be assumed to be dimensionless for this to work. If we assign correct units to the inputs, we have a problem:

Code: Select all

maturation 14 to 15  =              ~ people/year/year
        ( ( Population 0 To 14 ) )          ~ people
             * ( 1 - mortality 0 to 14 )            ~ fraction/year
             / 15             ~ 1/year 
Obviously the left side of this equation, maturation, cannot be people/year/year.

JJ's correction is:

Code: Select all

maturation 14 to 15=
    ( ( Population 0 To 14 ) ) 
                 * ( 1 - (mortality 0 to 14 * TIME STEP)) 
                 / size of the 0 to 14 population
In this case, the '1' represents the maximum fraction of the population that can flow out in a time step, so it really is dimensionless. (mortality 0 to 14 * TIME STEP) represents the fractional outflow from mortality within the time step, so it too is properly dimensionless (1/year * year). You could also write this term as:

Code: Select all

( 1/TIME STEP - mortality 0 to 14 ) / (1/TIME STEP)
In this case you can see that the term is reducing maturation by the fraction of cohort residents who don't make it to the next age group. 1/TIME STEP represents the maximum feasible outflow, i.e. 2/year if TIME STEP = 0.5 year. In this form, it's easy to see that this term approaches 1 (no effect) in the continuous time limit as TIME STEP approaches 0.
tomfid
Administrator
Posts: 3889
Joined: Wed May 24, 2006 4:54 am

Re: units for %

Post by tomfid »

Good catch BTW. I've copied to my blog (with credit): https://metasd.com/2024/12/case-strict-unit-testing/
Post Reply