Tutorial: Dynamic system model



Release:

4.6  •  5.0  •  5.1  •  5.2  •  5.3  •  5.4  •  6.0  •  6.1  •  6.2  •  6.3  •  6.4  •  6.5


Dynamic models are models of systems that evolve over time. They often model flows of material, people, or money, with feedback loops. This section shows you how to:

  • Use the Dynamic() function and the system variable Time
  • Customize the appearance of variable nodes
  • Organize a model using modules
  • Make duplicates of nodes and modules
  • Create aliases of variable nodes
  • Compare the results of two variables directly

This chapter assumes you already know how to:

Using the Time index

In this model you will set up a dynamic system to model a predator/prey relationship. The populations of foxes and hares will be set up as state variables: one-dimensional arrays indexed by Time.

Start by opening a new model and titling it Foxes and Hares Tutorial. Create a general variable titled Hare population.

Using either the Attribute window or the Object window, place the cursor in the definition field and choose Table from the Expression popup menu. The Indexes window will appear.

Notice that Time is listed as one of the indexes in the left hand window. You did not have to define this index before using it. Time is a system index in Analytica that is always available to you. Note that it is distinguished by the system variable icon (Chapter 7.1-updated.png). Although it is a system variable, the values of Time can be edited just like any other index.


Chapter 7.01-5.4.png


1. Create a new general variable titled Hare population.
2. Open the Attribute pane (or Object window), select Definition in the attribute popup window then select Table in the Expression popup menu.

Select the Time index and click the transfer button (Chapter 7.1-updated.png) to select it as an active index in the right-hand window. Click OK to exit the Indexes window.


Chapter 7.02-5.4.png


3. Select Time in the indexes dialog box'.


Chapter 7.03-5.4.png


1. Click the transfer button to move Time to the Selected indexes window.

Analytica will show an edit table for the Hare population variable. Notice that the default index values for Time are 0,1, and 2. You will need to have more than just three time points in your dynamic simulation.

Chapter 7.04-5.4.png

Go to the Definition menu and select Edit time. Click the Expression popup menu and select Sequence. Analytica will prompt to make sure you want to change the Time index to a Sequence. Click OK.

Chapter 7.05-5.4.png


1. Select Edit Time from the Definition menu.
2. Select Sequence from the Expression popup menu (just above the Definition field.

Press OK when asked to replace the current definition with a sequence.

Edit the sequence by keeping 0 for the start value and entering 10 for the end value. Click OK to exit the Object Finder dialog.

Chapter 7.06-5.4.png


3. Select sequence to span from 0 to 10
3. Select sequence to span from 0 to 10

If the edit table for Hare population is not already open select the Hare population node and click on the Result button (Chapter 4.54-updated.png). Notice that our time index now goes from 0 to 10. We will leave the values of the Hare population zero the moment.

Chapter 7.08-5.4.png

Setting up the Hare sub-model

Create three new general variables titled Initial hare population, Hare fertility, and Hare births. Draw influence arrows as follows:

  • from Hare fertility to Hare births
  • from Initial hare population to Hare population
  • from Hare population to Hare births

Define Initial hare population as 500. Change its Identifier to Hare_zero.

Define Hare fertility as 60%. We will take this to mean that the number of newborn hares will be equal to 60% of the total population during the previous time period!

Define Hare births as Hare_population*Hare_fertility. This is the total number of births during a time period.

Chapter 7.09-5.4.png


Create, define and draw influence arrows to 3 new variables as instructed above.
Create, define and draw influence arrows to 3 new variables as instructed above.
Create, define and draw influence arrows to 3 new variables as instructed above.


Using the Dynamic() function

Now we consider how the hare population will develop over time. The hare population will be influenced by the number of hare births, which will be influenced by the hare population during the previous period. Ultimately the value of Hare population depends on the value of itself during the previous time period. We can address this situation using the Dynamic function.

Using either the Attribute window or the Object window, open the Definition field of the Hare population variable. Click on the Expression popup menu and select Chapter 5.6-updated.png.

Delete the existing table expression and replace it with the following:

Chapter 7.10-updated.png

The Dynamic() function can be entered directly as an expression or accessed as a built-in function (by selecting Other... in the Expression popup menu). It is listed under the Special library heading.

Note that the Dynamic function automatically incorporates the Time system variable. It was not necessary to initially define our variable as a table indexed by Time, although this step was included in the first section of this chapter to illustrate the Time index.

Select the Hare population node and click the Result button (Chapter 4.54-updated.png).


Chapter 7.11-6.0.png

This is a simple exponential growth curve. It represents a rapidly multiplying population of immortal hares with no natural predators and an unlimited food supply. You will need to introduce a limiting factor to avoid this buried-in-bunnies scenario.

Completing the Hare sub-model

Quickly before it’s too late, create four new general variables as follows:

Chapter 7.12-updated.png

Finally you need to change the definition of Hare population as follows:

Dynamic(hare_zero, self[time -1] + hare_births[time - 1]- hare_deaths[time - 1])


Chapter 7.13-6.0.png

Now we have accounted for mortality and limited food supply by introducing a crowding factor. When the crowding factor is equal to one, the hare population has reached the carrying capacity for the habitat. At this point the death rate will be equal to the birth rate.

Select the Hare population node and click the Result button (Chapter 4.54-updated.png), then switch to the graph result view.


Chapter 7.14-6.0.png


Press the Graph icon to display the result graph


Chapter 7.14.2-6.0.png


Introducing a crowding factor limits the population to the carrying capacity

Using the color palette

In order to make an influence diagram easy to understand it is often useful to color code nodes according to function. The color palette is used for this purpose. You can access it in two ways:

  • Right-click the node and select Show/hide color palette from the context menu
  • Go to the Diagram menu and select Show/hide color palette

In the color palette you can select from standard colors or click Other... to select from the entire 24-bit RGB color space.


Chapter 7.15-6.0.png
Tip

The node style and diagram style windows are also useful for customizing the appearance of your diagram. They can be accessed in the same manner as the color palette.

Creating a module

Modules are an important feature of Analytica. They allow you to place a collection of nodes inside a single object, a module, which has the appearance of a single node. In this way, the top level of your diagram can be a simplified view showing influence arrows between modules. Each module can be opened as its own diagram window to show detailed interactions of the variables inside. Modules can even be placed within modules to create a nested hierarchy of detail.


Tip

If you have several diagram windows open at once you can click the Diagram window button (Chapter 4.18-updated.png) to return to the top level diagram at any time.

Creating a new module is just like creating a variable node. Drag the Module node from the node palette to the diagram window. A module looks similar to a node but it has a thick border around it and displays the title in bold print. Whereas double-clicking a variable node will open an Object window, double-clicking a module will open a new diagram window. Attributes for the module can be entered using the Attribute window at the bottom of the diagram. Your new module will have the following attributes:

  • Title: Hare module
  • Identifier: Hare_module
  • Description: A dynamic sub-model of the hare population

To populate your new module, start by making a multiple selection of all the nodes except for the module itself.

Reminder: To make a multiple selection hold down the Control or Shift keys, or drag a rectangular frame around the nodes you want to select.


Chapter 7.17-6.0.png


1. Create a new module by dragging the Module icon down to the diagram space.
2. Make a multiple selection of all variable nodes by dragging diagonally across the space. (Make sure that the module is not also selected).
2. Make a multiple selection of all variable nodes by dragging diagonally across the space. (Make sure that the module is not also selected).
3. Drag one of the selected nodes to the module and release).

Your top level diagram should now contain just the module by itself. Double-click the module to see the variables in a separate window.


Chapter 7.18-6.0.png


4. Double-click on the module to open a new diagram window.


Tip

If a single diagram window takes up the entire workspace press the maximize/un-maximize toggle (Chapter 7.19-6.0.png) near the upper right corner of the window.

Duplicating a module

Now you will make a similar sub-model for the fox population. Since the basic structure will be similar to the hare sub-model, you can save time by duplicating it automatically.

Select the hare module in the top level diagram window. Select Duplicate nodes from the Edit menu. A duplicate module will appear.

Edit the Title and Identifier of the duplicate to read Fox module

Edit the Description attribute to read A dynamic sub-model of the Fox population


Chapter 7.20-6.0.png


1. After selecting the Hare module, go to the edit menu and select Duplicate nodes.
2. Retitle the duplicate as Fox module.

Double-click the Fox module to open its diagram window. (Or click on the Module's Diagram window Hover Icon DiagramWindowHoverIcon.png).

The diagram appears to be identical to the original but you will notice some important differences in the Identifiers. Open the Attribute window and check the identifier for the Hare population node. Notice it has been changed to Hare_population1. Analytica has appended the 1 to ensure that the identity of the new variable is distinct from the original. Different variables are allowed to have identical titles but they must always have different identifiers

Identifiers in functional expressions are modified accordingly. This ensures that the duplicate variables belong to a self-contained group that does not interfere with the original variables.

Drag one of the selected nodes to the module and release.

Chapter 7.21-updated.png

Completing the Fox sub-model

Edit the titles and identifiers in the fox module as follows: (These edits mostly involve substituting the word Fox for Hare.)

Chapter 7.22-updated.png

Change the definition of input variables as follows:

  • Initial Fox population: 120
  • Fox fertility rate: 35%
  • Fox carrying capacity: 200

The fox population is now a self-contained sub-model. Select the Fox population variable and click on the Result button (Chapter 4.54-updated.png). Or you can hover over the node and click on the result hover icon.


Chapter 7.23-6.0.png


Due to a lower fertility rate, the fox population approaches it's carrying capacity more slowly than the hare population.

Creating aliases

Although it is useful to organize a model with modular structure, accessing variables inside modules can be less convenient than having them all in the same window. To address this problem Analytica allows you make an alias of a variable and place it anywhere you wish. The alias provides local access to the variable but it is merely a representation, not a duplicate, of the original node.

In this case it will be convenient to access the Hare population and Fox population nodes on the parent diagram without having to open the modules.

Click the Diagram button (Diagrambutton5.4.png) to open the top level diagram. Open the Fox module and arrange the windows so that both are visible.

Select the Fox population variable. Go to the Object window and select Make alias. The alias looks similar to the original node but the title will be shown in italics. Drag the Fox population alias to the parent diagram.


Chapter 7.24-6.0.png


1. Arrange windows so that the Fox module diagram and it's parent diagram are both visible.
2. Select the Fox population variable and select make alias from the Object menu.
3. Drag the Fox population alias to the parent diagram window.
Note that alias nodes always show titles in italics.

Repeat the same procedure to create a Hare population alias on the top diagram.


Chapter 7.25-6.0.png


4. Create an alias for the Hare population variable in the same manner.
Influence arrows are automatically drawn.
Influence arrows are automatically drawn.

Drawing influence arrows across modules

Now you are ready to introduce predatory interaction! Create a new general variable titled Predations. This will represent the number of hares eaten by foxes in a given time period. The predation level is assumed to be proportional to the product of fox and hare populations.

Draw influence arrows from the Hare population alias to Predations, and from the Fox population alias to Predations. Enter the following expression to define the new variable: Hare_population*Fox_population / 600'


Chapter 7.26-updated.png


1. Create a new general variable titled predations.
2. Draw influence arrows from the Hare population and Fox population aliases to the Predations variable.
2. Draw influence arrows from the Hare population and Fox population aliases to the Predations variable.
3. Define Predations as Hare_population * Fox_population/600


Unfortunately for the hares, each predation will count as a death for their team. Open the Hare module and arrange windows so that the Hare module diagram and its parent diagram are both visible. Draw an influence arrow from Predations to Hare deaths.


Chapter 7.27-updated.png


4. Open the Hare module and arrange window so that the Hare module diagram and it's parent diagram are both visible.
5. Draw an influence arrow from the Predations variable to the Hare deaths variable.

Re-define Hare deaths as: Hare_population*Hare_ndr + Predations


Chapter 7.28-updated.png


6. Edit definition of Hare deaths to read Hare_population * Ndr + Predations.

If you look closely at the Hare population and Hare deaths nodes you will notice small arrowheads on the margins. These indicate influence relationships with other nodes outside the module.


Chapter 7.29-updated.png


Arrowheads indicate influences directed outside the module.
Arrowheads indicate influences directed outside the module.

Predations are a food source for fox population and have a positive effect on their numbers. This can be modeled by making the Fox carrying capacity proportional to the Predations variable.

Re-define Fox carrying capacity as: Predations*1.6


Chapter 7.30-updated.png


7. Re-define Fox carrying capacity directly by typing Predations * 1.6 into the Definition field.
Tip

Analytica will allow you to use a variable in an expression before drawing its influence arrow. The variable will not be listed in the Inputs popup menu so you must type the exact identity correctly. Influence arrows will automatically be drawn after you finish editing the expression.

Viewing multiple results simultaneously

Your model is now complete. Click the Diagram button (Diagrambutton5.4.png) to open the top diagram. As you already know, you can view the results of the fox and hare populations separately by selecting either one of the population aliases and clicking the Results button (Chapter 4.54-updated.png). But there is an easy way to combine both variables on the same graph. Select both alias nodes simultaneously (holding down the Control or Shift keys while selecting). Now when you click the Results button a dialog box will appear asking if you want to add a node to your model with this comparison. Click Yes and Analytica adds a new node to the diagram with the comparison, and display its result window. A comparison node is essentially a list variable with the variables to be compared as elements of the list.

The default title in this case will be Compare1.


Chapter 7.31-updated.png


1. Select the Hare population and Fox population aliases simultaneously.
2. Show the result by clicking the result button in the tools palette or the result hover icon (Chapter 4.54-updated.png
3. Press Yes to confirm you want to add a node to the module with the comparison.


Chapter 7.31-2.png


A new comparison node is generated and its result window shown.

The result window for Compare1 will contain information from both of the selected nodes. Switch to the Graph result, and choose Time as the horizontal axis in the Result window of Compare1. You can now see the result of the predatory interaction.


Chapter 7.32-updated.png


1. Click the Graph result icon.
2. Set time as the horizontal axis
The graph shows results for Fox and Hare populations simultaneously.

Foxes and Hares Act III

How does the Fox/Hare drama end? You can extend the simulation by simply adding more values to the Time index.

Go to the Definition menu and select Edit time. Extend the sequence to go from 0 to 100, and click the green check button to accept the new definition.


Chapter 7.33-updated.png


1. Select Edit time from the definition menu.
2. Edit the definition to set 100 as the end step.
3. Click the green check to accept the definition.

Select the Compare1 node and click the Results button (Chapter 4.54-updated.png) again.


Chapter 7.34-updated.png


4. Show the result of the Compare1 node again
The populations eventually settle down to a new equilibrium

Now you can experiment by changing input values to see how they impact the result.

If you would like to see a more complete Foxes and Hares example, open Foxes and Hares.ana in the Tutorial Models folder.

Summary

In this chapter you have:

  • Used the Dynamic() function to model a feedback loop in a dynamic system.
  • Edited the system variable Time which is used as an index in the Dynamic() function
  • Customized the appearance of nodes using the Color palette
  • Grouped nodes into Modules
  • Used the Duplicate command to create a new module with similar structure to the original
  • Created aliases for convenient access to nodes contained within modules
  • Established influence relationships between modes in different diagram windows
  • Created a comparison node to view the results of two variables simultaneously.

See Also


Comments


You are not allowed to post comments.