multi dimensioal array

Use this forum to post Vensim related questions.
Post Reply
salman_psh
Junior Member
Posts: 14
Joined: Thu Jul 06, 2017 2:03 am
Vensim version: DSS

multi dimensioal array

Post by salman_psh »

Hi,

I am building a population level model with aging and population having attributes.

The data I have looks like this

Age # of Patients SBP (average) HbA1c (average) BMI (average) TotaltoHDL (average)[/b]
25 1 109.8082 10.2271 31.6328 4.2518
26 1 97.0217 7.2728 30.2394 4.1116
27 1 131.4675 6.3382 29.6187 4.0322
28 2 134.8824 7.4660 27.7229 3.4343
29 2 152.9983 9.3213 23.2516 6.3040

The aging model from age 25 to 29 is working fine. My problem come from adding the attributes(characteristics) to each individual person in each age cohort.
Literature suggests make a stock of each attribute and simulate, which is totally understandable, but my problem is in defining the initial population with these attributes.
Attachments
Test 2b.mdl
Model
(6.92 KiB) Downloaded 177 times
salman_psh
Junior Member
Posts: 14
Joined: Thu Jul 06, 2017 2:03 am
Vensim version: DSS

Re: multi dimensioal array

Post by salman_psh »

Ok I figured it out.

For example, set Age subscript for BMI. In equation editor add vale vertically followed by a , and last value no comma and hot enter.
Watch out for array dimension. You must enter same number of values for BMI as Age, other wise error will generated.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: multi dimensioal array

Post by tomfid »

Often the easiest way to enter multidimensional arrays of constants is to put them in a spreadsheet and reference that via GET XLS or GET DIRECT.

Another option is to paste them in as a TABBED ARRAY (this is in the subtype menu for constants in the equation editor).

You can also use a delimited syntax directly in a constant's expression, like:
1,2,3;
7,6,5;
4,8,9;
3,6,3;

Yet another option is to supply a default value in the equation, then list the actual values in a .cin file.

See also: http://vensim.com/documentation/22070.h ... sub=tabbed
salman_psh
Junior Member
Posts: 14
Joined: Thu Jul 06, 2017 2:03 am
Vensim version: DSS

Re: multi dimensioal array

Post by salman_psh »

Thanks Tom for your reply. It was quite helpful. I tried with GET DIRECT CONSTANTS. It dint't work :cry:
I added a subscript of SBP, but when I ran the model it gave me dimensional inconsistency.
For each age and gender it is mapping for each element of SBP group.
AGE24 MALE SBPAGE24
AGE24 MALE SBPAGE25

and so on.

Would it work if I map SBP onto age. I am trying this out now.

I am attaching the current model file and data file.

Please advice
Thanks
Attachments
data.xlsx
(20.65 KiB) Downloaded 168 times
Test 2e.mdl
(4.57 KiB) Downloaded 185 times
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: multi dimensioal array

Post by tomfid »

Try the sample models in the help system for some examples of various GET layouts.
salman_psh
Junior Member
Posts: 14
Joined: Thu Jul 06, 2017 2:03 am
Vensim version: DSS

Re: multi dimensioal array

Post by salman_psh »

I tried GET XLS data. But I am not been able to get what I want; for each age cohort, number of patients and their blood pressure.

I would really appreciate of there is some some vensim code for this.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: multi dimensioal array

Post by tomfid »

I think you're trying to treat the array dimensions like database columns. When you dimension something with [age,gender,sbp] you're creating a 43 x 2 x 42 matrix. I doubt you need that. Also, when you make a 2D GET XLS call, Vensim expects a matrix, but your spreadsheet supplies a list. Again, check the subscripted GET examples in the help system. These will be in c:\users\public\Vensim\models\functionexamples if you can't activate the links in the help.

You might take a look at the cohort model associated with the SHIFT IF TRUE function for an example: http://vensim.com/documentation/fn_shift_if_true.htm

Also, cohort modeling is easier in Ventity:
https://www.systemdynamics.org/assets/c ... /P1363.pdf
https://www.systemdynamics.org/assets/c ... /S1363.zip
salman_psh
Junior Member
Posts: 14
Joined: Thu Jul 06, 2017 2:03 am
Vensim version: DSS

Re: multi dimensioal array

Post by salman_psh »

Hi Tom,
Thanks once again for your reply. I feel quite embarrassed that despite your so much input I am not able to get what I require.
I tried GET XLS SUBSCRIPT its works.

Then I put that subscript in equation for stock and aging.
But as before, problem is from giving initial value for population stock.

Initial population [gender,age]. When I set SBP subscripts it becomes Initial population [sbp,gender,age] *Gender is actual number of patients of each <b>***</b>

In equation editor
Equation subscripts [Male,age] and values I enter are like one column for each entry of AGE array (total element of 43)
1,
2,
3,
.
.
To me it looks like here I am doing something wrong.
SBP MALE AGE
109 1 24
110 3 25
120 5 26

I need to have something like this.

May be I am think in C or mat lab and Vensim works differnetly :(

Please guide!
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: multi dimensioal array

Post by Administrator »

Can you upload the model you have? I'm not really following what you are describing.
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
salman_psh
Junior Member
Posts: 14
Joined: Thu Jul 06, 2017 2:03 am
Vensim version: DSS

Re: multi dimensioal array

Post by salman_psh »

The EXCEL file is the one I want to input as in BASELINE POPULATION in the model.
there are no births or deaths, population is fixed.

My aim is to have for each age cohort with number of patients (male and female) and their respective SBP in the BASELINE POPULATION.
Attachments
data - Copy.xlsx
(13.08 KiB) Downloaded 161 times
Test 2e.mdl
(4.08 KiB) Downloaded 180 times
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: multi dimensioal array

Post by tomfid »

"SBP" is an attribute of the patient (blood pressure?), right? In that case I think we don't want it to be an array dimension. I'll take another look.
salman_psh
Junior Member
Posts: 14
Joined: Thu Jul 06, 2017 2:03 am
Vensim version: DSS

Re: multi dimensioal array

Post by salman_psh »

yes, SBP is blood pressure. And it is an attribute of a patient. Each age cohort has different SBP. To me Array was the only option I could apply. Nevertheless,
I will be waiting for your guidelines.
Thank you
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: multi dimensioal array

Post by tomfid »

This version has the GET functions working.
Test 2f.mdl
(4.03 KiB) Downloaded 230 times
BP needs to be implemented as a coflow attribute, not as an extra dimension. You could essentially copy-paste the population structure and adapt it for the BP attribute.
salman_psh
Junior Member
Posts: 14
Joined: Thu Jul 06, 2017 2:03 am
Vensim version: DSS

Re: multi dimensioal array

Post by salman_psh »

Thanks once again.

I will implement BP as a co-flow structure. I see that you have corrected equations too.

You added recruitment inflow to model, I can understand the logic, but in my case the population doesn't change, it only ages. So, I made it equal to zero.
salman_psh
Junior Member
Posts: 14
Joined: Thu Jul 06, 2017 2:03 am
Vensim version: DSS

Re: multi dimensioal array

Post by salman_psh »

I replicated the structure for BP. For age 25 to 35 the BP attribute vale remain constant but for age 36 till 65 with each step of simulation the BP value changes.
My requirement is to keep these values constant for each age cohort for entire simulation run.
As there is no inflow or outflow exept aging.
I have attached the model. Please advise.
Thanks
Attachments
Test 2g.mdl
(5.83 KiB) Downloaded 181 times
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: multi dimensioal array

Post by Administrator »

The model does not simulate, it's missing the Excel file needed to run it.
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
salman_psh
Junior Member
Posts: 14
Joined: Thu Jul 06, 2017 2:03 am
Vensim version: DSS

Re: multi dimensioal array

Post by salman_psh »

Model behave a bit better now. I have made aging of BP equal to zero.
Attachments
dataTF.xlsx
(12.31 KiB) Downloaded 157 times
Test 2g1.mdl
(5.82 KiB) Downloaded 170 times
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: multi dimensioal array

Post by tomfid »

So the problem is that it misbehaves when you remove the *0 from SBP aging?

One suggestion: define units for the whole model. That might reveal an issue that's easy to overlook.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: multi dimensioal array

Post by tomfid »

... or, if you want SBP to be a static function of age, so that it doesn't move with the cohorts, the *0 might be the right thing to do. You could also eliminate the SBP flow dynamics easily, and treat it like an array or lookup.
salman_psh
Junior Member
Posts: 14
Joined: Thu Jul 06, 2017 2:03 am
Vensim version: DSS

Re: multi dimensioal array

Post by salman_psh »

Thanks for your feedback and suggestions.
Post Reply