Exclude :NA: in VMIN or VMAX

Use this forum to post Vensim related questions.
Post Reply
oOLauraOo
Member
Posts: 41
Joined: Wed Mar 22, 2017 5:05 pm
Vensim version: PRO

Exclude :NA: in VMIN or VMAX

Post by oOLauraOo »

Hi,

How can I exclude :NA: from the solutions when using VMIN(x[i!]) ?

Example :

TRB[Building 1,scenario 1] = 3
TRB[Building 1, scenario 2] = 2
TRB[Building 1, scenario 3] = :NA:

VMIN(TRB[Building 1, scenarios!]) = :NA: <== How can I make it "2", the "next" min value, and not taking :NA: into account ?

Thanks
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Exclude :NA: in VMIN or VMAX

Post by Administrator »

All you can really do is something like this.

For VMIN
MIN TRB[building 1] = VMIN ( IF THEN ELSE ( TRB[Building 1, scenarios!] = :NA: , 999999 , TRB[Building 1, scenarios!] ) )

for VMAX
MAX TRB[building 1] = VMAX ( IF THEN ELSE ( TRB[Building 1, scenarios!] = :NA: , -999999 , TRB[Building 1, scenarios!] ) )
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: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Exclude :NA: in VMIN or VMAX

Post by tomfid »

It's a little cumbersome, but you could do something like the following:

TRB is Defined[building,scenario] = INITIAL( IF THEN ELSE( TRB[building,scenario] = :NA:, 0, 1) ) ~ dmnl
Min TRB = VMIN( TRB[building!,scenario!] * TRB is defined[building!,scenario!] )

Multiplying NA by 0 should suppress it. VECTOR SELECT would be a little cleaner here, but also slightly more complicated to set up.
oOLauraOo
Member
Posts: 41
Joined: Wed Mar 22, 2017 5:05 pm
Vensim version: PRO

Re: Exclude :NA: in VMIN or VMAX

Post by oOLauraOo »

Thank you for answering so fast !

Multiplying :NA: by 0 didn't work, it made 0 instead of suppressing the value...
I will try with the "999999" and have a look on VECTOR SELECT, and I'll let you know if I manage to make it work.

Thanks
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Exclude :NA: in VMIN or VMAX

Post by tomfid »

VECTOR SELECT is the cleanest solution, because it avoids processing the NAs altogether, and can't get into trouble with "magic" numbers like 999 or 0 (oops).
oOLauraOo
Member
Posts: 41
Joined: Wed Mar 22, 2017 5:05 pm
Vensim version: PRO

Re: Exclude :NA: in VMIN or VMAX

Post by oOLauraOo »

Yes, VECTOR SELECT seems to be an appropriate way, but this function makes me crazy and I don't really know how to put it in my case, I need to deepen my reading of the documentation... Especially as I have the same problem with VECTOR RANK, that takes :NA: as 0 and keeps :NA: values as the best ones ! I definitely need to reorder the values, excluding :NA: ... I guess VECTOR SELECT will be an appropriate solution to do this too ?

This leads me to another question, concerning VECTOR REORDER.

buildings : (B1-B15)
renovation scenarios : (scenario1-scenario3)
sortscenario : (sort1-sort3) -> renovation scenarios
SORT ORDER[sortscenario]=VECTOR SORT ORDER(TRB[buildings,renovation scenarios],1)
sorted TRB[sortscenario]=vVECTOR REORDER(TRB[buildings,renovation scenarios], SORT ORDER[sortscenario])

So the computation only works on the last subscrip [renovation scenarios], and the results are reordered "per building". I obtain something like this :
[B1,scenario1]
[B1,scenario2]
[B1,scenario3]
[B2,scenario2]
[B2,scenario1]
[B2,scenario3] ...

What I would expect would be a ranking over [buildings] AND [renovation scenarios], such as :

[B5,scenario2]
[B3,scenario1]
[B1,scenario2]
[B1,scenario3]
[B2,scenario1] ...

I don't know if this is very clear... I would like to rank the TRB[building,renovation scenarios] "over all", excluding :NA: values.

I tryed many things with the ELM MAP function but could not manage to do this at the end. Should I create another mapping sorting the buildings ? I don't know anymore !

Thanks a lot for your time !
Laura
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Exclude :NA: in VMIN or VMAX

Post by tomfid »

There are good examples in the Help system. See:
C:\Users\Public\Vensim\Models\FunctionExamples
oOLauraOo
Member
Posts: 41
Joined: Wed Mar 22, 2017 5:05 pm
Vensim version: PRO

Re: Exclude :NA: in VMIN or VMAX

Post by oOLauraOo »

Hi,
I'm sorry, I still can't manage to do what I want. I did not find examples treating several subscripts at a time. I tried many things, but I guess I miss something and I don't know what.
I tried to map the two subscripts [buildings] (15 elements) and [renovation scenarios] (3 elemnts) to the same [sort projects] such as :

[sort projects] = (sort1-sort45)->buildings,renovation scenarios

But an error message appears saying the [buildings] subscripts elements number doesn't match [sort projects] elements number ; the same for [renovation scenarios].

Can you please help me with that, by sending me examples with two (or more) subscripts, or explaining me what I'm doing wrong ?
Thanks a lot,

Laura
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Exclude :NA: in VMIN or VMAX

Post by tomfid »

This mapping doesn't work, because you're mapping 45 elements to 18 elements. The map statement following the -> is a list, not a combinatorial matrix. So you have:

sort projects = {45 elements} -> {15+3 elements}

You could use VECTOR ELM MAP or an index matrix as an alternative, when you need to map in multidimensions.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Exclude :NA: in VMIN or VMAX

Post by tomfid »

Something like this:
mappingOptions1.mdl
(2.17 KiB) Downloaded 250 times
Post Reply