Tutorial: Dynamic system model

This chapter 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
  • View the results of two variables simultaneously

Before starting this chapter you should know how to perform the following actions which will no longer be described in detail:

Create a new model; Open an existing model; Save; Save As... (See Tutorial: Open a model to browse)

Create and define new variables; Enter attributes in Attribute or Object windows; Draw influence arrows between nodes. (See Tutorial: Create a model)

You should also be familiar with Array variables and Index variables. (See Tutorial: Arrays)

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.

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.3-updated.png

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.4-updated.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.5-updated.png

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.6-updated.png

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.8-updated.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.9-updated.png

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-updated.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-updated.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)

Chapter 7.14-updated.png

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-updated.png

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.


If you have several diagram windows open at once you can click the Diagram window button (Chapter 7.16-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-updated.png

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-updated.png

If a single diagram window takes up the entire workspace press the maximize/un-maximize toggle (Chapter 7.19-updated.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-updated.png

Double-click the Fox module to open its diagram window.

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).

Chapter 7.23-updated.png

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 (Chapter 7.16-updated.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-updated.png

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

Chapter 7.25-updated.png

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

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

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

Chapter 7.28-updated.png

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

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

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 (Chapter 7.16-updated.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 compare more than one result. Click OK. Analytica will automatically create a comparison node. 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

The result window for Compare1 will contain information from both of the selected nodes. 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

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. Click OK to exit the Object Finder dialog.

Chapter 7.33-updated.png

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

Chapter 7.34-updated.png

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.


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


You are not allowed to post comments.