# Tutorial: Create a model

Release: 4.6  •  5.0  •  5.1  •  5.2  •  5.3  •  5.4  •  6.0  •  6.1  •  6.2  •  6.3

This chapter shows you how to:

• Create a new model
• Create new variable nodes and enter attributes
• Move and delete variable nodes
• Draw influence arrows to define dependencies between variables
• Define variables as explicit values, functions and lists
• Invoke a built-in function to define a variable
• Do a simple Parametric Analysis

This chapter shows you how to create a new Analytica model.

In the process of building a model to analyze the costs of owning and operating an automobile, you will create variables, define dependencies, add documentary text, and compute results.

If Analytica is not open, start it by double-clicking its icon. If Analytica is already open with an active model go to the File menu, select New Model.

## Creating a new model

When you start up a new Analytica session, it shows the Intro screen. Click on Blank Model to start a new model.

Click Blank Model to start a new model.

The blank model initially shows an Object window for an untitled model. Behind the Object window you will see an empty Diagram window.

First you should enter a Title for your model:

1. Click in the Title attribute field (to the right of Title). Type in Car cost model and press Alt- enter. In the space just above the Title you entered, you will see that the Identifier field automatically changes to Car_cost_model.
2. Press Tab to go to the Description attribute and type in: A demonstration model to show how to calculate the cost of running a car
Tip
If this is not a first-time entry for Title information, a dialog box will appear to confirm an automatic change to the Identifier.

The Identifier field is automatically filled in to match the first 20 characters of the Title. You can also change this manually if desired.

1.  Tab to, or click in, the Title field (to the right of the label Title) and type Car cost model.

2.  Tab to the Description field (to the right of the label Description) to enter description information.

3.  Author and creation date are filled in automatically. You can also edit the Author if desired. Analytica automatically updates Last Saved and File info.

Tip
You can either press the Tab key or use the mouse to move between fields.

5.  Click the Diagram button to display the model's Diagram window.

## Editing a diagram

In most of the three previous chapters you were in the browse mode, with the browse tool highlighted in the tool palette. In browse mode you can view an existing model without changing its structure. When you create a new model the edit tool is selected by default. You use the edit tool to create or change a model.

Be sure to note which tool is selected throughout the remainder of this tutorial.

When the edit tool is selected, a menu of icons is displayed in the node palette. These icons represent the different node types and allow you to add nodes to the diagram.

## Creating variable nodes

In this chapter you will create variables in the Car Cost model.

Each variable is represented in the influence diagram as a shape that depicts the Class of Variable. These shapes are generally referred to as nodes. Select the node shape based on what you know about the variable. If you are not sure what kind of variable to use, choose a General variable .

See Tutorial: Recognizing influence diagrams for a description of the node shapes.

1.  Choose the edit tool.

2. Drag the Variable Node icon to a position in the influence diagram.

A new Variable Node appears in the diagram at the location where you release the mouse button.
Tip
As you build a model, you should select descriptive titles for your variables. Descriptive variable titles remind you of the model’s logic and help to inform others about how the model operates.

3. Type Fuel Cost for the variable title.

Press Alt+Enter or click any other location in the diagram to accept the title.
Tip
Fuel Cost is filled with a diagonal line pattern around its text, indicating that it does not yet have a valid definition.

Repeat Steps 1 and 2 four times to create four more variables that affect fuel cost. Title these variables as follows:

• Fuel Price (price per gallon of gasoline)
• Annual miles (number of miles driven each year)
• Mpg (miles per gallon of gasoline)
• Age (driver’s age)

4.  Drag the Variable Node icon to a position on the diagram.

Title text wraps to fit within the node as you type. You can manually create a new line in a title by pressing the Enter key at the desired break point(s). You can also expand the size of the node by dragging one of the corner handles.

5. Type Fuel and press the Space key.

Type Price and press Alt+Enter to indicate that you are finished.

6. Repeat Steps 3 and 4 to create three more variables, as shown.

Title the variables Annual Miles, Mpg, and Age.

Analytica automatically saves each change you make to a backup file. If your computer (or Analytica) should terminate unexpectedly, it will offer to recover your changes the next time you start Analytica. Even so, it’s a good idea to save your changes periodically.

1. Select Save from the File menu (or press Control-s). The first time you try to save a model, it shows a Save As dialog, offering to save the model in the My Documents folder using the model Title as the default file name. You can select another folder and modify the file name.
2. Click Save or press Enter to save the model in the selected folder.

1.  Select Save As from the File menu.

2.  Type the new file name here.

## Deleting a variable

Sometimes you might want to delete a variable that you previously created.

In this example you realize that the driver’s age is not relevant to your understanding of the Fuel Cost variable. Therefore, you will delete the Age variable.

1. Select the Age node if it is not already selected.

Handles surround the node to indicate that it is selected.

2.  Select Clear from the Edit menu, or press the Delete key.

Handles⠀

Handles⠀

Analytica asks you to confirm that you want to delete.

3.  Click OK to confirm that you want to delete the selected object.
Tip
You can select multiple nodes by holding down the Control or Shift keys, or by placing the cursor in a blank area and dragging diagonally to draw a rectangular frame across the nodes you want to select.

## Moving nodes

When you create a model you should try to structure the layout to make the influence diagram easy to understand. As you refine your model, however, you will undoubtedly want to group nodes in different ways to achieve this goal.

In this case we anticipate that Fuel Cost will be derived from the other three variables. Therefore we want to place it apart.

Moving nodes is a simple matter of dragging them to the desired position. Try moving the nodes into the new configuration below.

Draw the nodes to the new configuration.
Tip
You can undo or redo a drag operation by selecting Undo/Redo from the Edit menu, or by typing the keyboard shortcut, Control+Z.

## Editing variable titles

The name displayed inside each variable node is referred to as a Title. In this example you will expand the title Mpg to Miles per gallon:

1.  Select the Mpg node.

2.  Click again inside the node's title to select its text for editing.
Tip

Pause briefly between the click to select the node and the click to select the text within it. If you complete two single-clicks too quickly, Analytica interprets your actions as a double-click and opens an Object window.

If you accidentally open the Object window, return to the Diagram window by clicking the Diagram button .

3. Type Miles per gallon and press Alt+Enter.

The new title is displayed.

3. Type Miles per gallon and press Alt+Enter.

The new title is displayed.

When you change the title of a node, Analytica asks you if you want the Identifier to be automatically changed as well.

4.  Click No to close this dialog box and keep the identifier as Mpg.

Tip

You can change this behavior, to either turn off automatic updating of the identifier or to make it fully automatic, so that you are not asked. See Preferences dialog in the Analytica User Guide for details.

## Drawing arrows between nodes

One of Analytica’s most powerful features is its ability to show relationships between variables in the influence diagram. Influence arrows are used to specify the dependencies between variables.

Because the Miles per gallon variable influences the Fuel Cost variable, you will draw an arrow connecting the two nodes.

1.  Position the cursor over Miles per gallon until the hover icons appear. Mouse down on the icon.

2.  Drag from the Miles per gallon node to the Fuel Cost node.

3.  Release the mouse button when Fuel Cost is highlighted. The two nodes are now connected by an arrow, indicating that Miles per gallon affects Fuel Cost.

If the nodes are not connected by an arrow, repeat Steps #1 through #3.

## Deleting an arrow

Occasionally, you might need to delete an arrow because of an earlier mistake or a change in your understanding of the model. This section shows you how to delete the arrow that connects Miles per gallon to Fuel Cost.

First, make sure you have the edit tool selected.

1.  Make sure the edit tool is selected.

2.  Select the arrow by clicking on it. Handles appear when the arrow is selected.

3.  Press the Delete key to delete the arrow. The arrow disappears.

Handles⠀

Handles⠀

## Connecting multiple arrows

When one variable is influenced by several other variables, you can draw multiple arrows at once. This example shows you how to connect the three variables contributing to the Fuel Cost variable.

First make sure the edit tool is selected.

1. Select Annual miles, Miles per gallon, and Fuel Price nodes simultaneously.

(Hold down Control or Shift while selecting or drag diagonally across the group.)

2. Hover over any of the selected nodes until the hover icons appear. Start dragging from the icon.

Release the mouse button when the Fuel Cost node is highlighted.

Three arrows now point to the Fuel Cost node.

3. Deselect all of the nodes by clicking in any location in the diagram that is not on a node.

## Bending arrows

As your diagrams become more complex, you may sometimes need to bend your arrows around nodes for clarity. Bent arrows can be either curved or crisp. Bent arrows contain way points, which define where the arrow changes directions. . You can insert or remove way points to alter the number of segments in an arrow, and drag the way points to route the arrow as you like.

When you first select an arrow without a bend, two handles appear near the midpoint -- one is a circle, the other is a square. Drag the circle to create a curved arrow initially, or drag the square to create a crisp bend. As you drag it, you introduce the first way point.

1. Select the arrow, then drag the square handle

2. Release the drag here

3. Repeat for the second arrow

And we have two arrows with crisp bends:

4. Right click on the arrow

To remove the bends, right-click on the arrow and select Remove all way points.

5. Repeat to remove bend in this arrow

## Entering attributes into the Object window

Each variable (or other Object) has an Object window that lets you see and edit its Attributes - including its Identifier, Title, Units, Description and Definition.

In this section we will use the Object window to enter attributes for the Annual Miles variable.

1. Click the Object window hover icon to open its Object window.
Tip

You can also open a variable’s Object window by double-clicking the node using the browse or arrow tools. If you are using the browse tool, you will not be able to enter or change documentation.

Identifier⠀

Title⠀

The identifier in the Object window shown above is Annual_miles. Analytica assigns the identifier when the title is created. It uses the first 20 characters of the title except for spaces or punctuation, which are replaced by underscores ( _ ). Analytica does not differentiate between uppercase and lowercase letters in identifiers.

You can directly edit both the identifier and the title.

First, you will change the variable’s identifier to a short abbreviation so that it can easily be used later in the definitions of other variables. You will then document the variable more fully.

2. Select the contents of the Identifier field.

3. Type Mpy and press Alt+Enter.

4. Click the Units field. Type miles/year and press Alt+Enter.
Tip

Analytica uses the information from the Units field to label graphs or tables that use the Miles per year variable; Analytica does not use it in any mathematical computations.

5. Select the contents of the Title field and press the Delete key to erase Annual miles.

6. Type Miles per year and press Alt+Enter.
Tip

When you change the title of a node, Analytica asks you if you want it to automatically change the identifier to match the new title.

7. Click No to keep the Identifier as Mpy.

8. Click in the Description field, type Average miles driven per year., and press Alt+Enter.

## Defining a variable as an explicit value

Analytica uses a wide range of variable types. In this section we simply enter an explicit value for the variable. Functional expressions and lists are described later in this chapter. Other variable types are addressed in later chapters.

For variables as functional expressions see Defining a variable as a function of other variables.

For variables as lists see Defining a variable as a list.

For variable as tables see Tutorial: Arrays.

For a demonstration of built-in functions see Defining a variable using a built-in function.

First let’s define Miles per year as 12,000.

1.  Click in the Definition field to center a mathematical expression for the variable; type 12K.

A warning icon indicates that this variable's definition has not yet been accepted.
Tip

Numerical suffixes like μ and K are used extensively throughout Analytica. A quick reference for these suffixes is given in Number formats.

2.  Click the check button or press Alt+Enter to accept the new definition.

The warning icon disappears because the variable now has valid definition.

If you want to cancel what you entered, click the cancel button.

Whenever another variable’s definition includes the identifier (Mpy) of Miles per year, this defined value, 12K, is used as its value.

Miles per year is no longer filled with a diagonal line pattern around its title, as shown in the figure below. The clear node indicates that Miles per year now has a valid definition.

## Defining a variable as a function of other variables

When one variable is dependent upon another variable, you must provide an expression that describes the relationship between the variables. Influence arrows connecting other nodes to Fuel Cost show the direction of this dependency.

In this section, you will enter a definition for Fuel Cost in terms of the values of Miles per year, Miles per gallon, and Fuel Price.

1.  Enter the variable's units as $/year, and description as Annual cost of fuel. 1. Enter the variable's units as$/year, and description as Annual cost of fuel.

2.  Click in the Definition field to enter a mathematical expression.

Because Fuel Cost is equal to Fuel Price times miles driven, divided by miles per gallon, you will enter the following expression into the Definition field:

Fuel_Price*Mpy/Mpg

An asterisk (*) represents multiplication; a slash (/) represents division.

3.  From the Inputs popup menu select the name of the variable that you want to add, in this case, Fuel Price. Fuel_Price appears in the Definition field.

4.  Type an asterisk (*).

Based on the definition you just entered, the value of Fuel Cost is calculated by multiplying the values of Fuel Price and Miles per year, and then dividing the result by the value of Miles per gallon.

5.  Select Miles per year from the Inputs popup menu.

6.  Type a slash (/).

7.  Select Miles per gallon from the Inputs popup menu.

8.  Press Alt+Enter or click the check button to accept the definition. The Definition field should look like this (spaces between terms and operators are optional).

Note that Fuel Cost is no longer diagonally shaded, indicating that it has a valid definition.

## Entering attributes using the Attribute panel

Sometimes you may find it more convenient to view or edit attributes of a variable in the Attribute panel as part of the Diagram view instead of using a separate Object window.

In this section, you will enter data for the Fuel Price variable in the Attribute panel.

1.  Select the Fuel Price node.

2.  Click the arrow icon to display the Attribute panel.

The Attribute panel appears below the diagram. You can use this view to enter or edit data for the currently selected variable in the influence diagram.

3.  Click on the Attribute popup menu and select Description.

4.  Enter the description as shown, then press Alt-Enter.

5.  Select Units from the Attribute popup menu.

6.  Type US Dollars, then press Alt+Enter.

Now that you have entered attributes for the Fuel Price variable, you will enter its definition in the Attribute panel.

In this example we will assume that Fuel Price has a fixed value of \$3 per gallon.

Select Definition from the Attribute dropdown menu and enter 3.

1.  Select Definition from the Attribute popup menu.

The warning icon is there to remind you that the variable is not yet defined.

Enter 3 in the Attribute field. The Fuel Price variable is now defined as an explicit value.

Note that Fuel Price is no longer diagonally shaded, indicating that it has a valid definition.

## Defining a variable as a list

In this section you will enter attributes for the Miles per gallon variable and define it as a sequence of numbers. You will use this sequence later to perform a Parametric analysis to show how the Fuel Cost is affected by Miles per gallon.

Using the Attribute panel, enter Average number of miles per gallon for the description and miles/gallon for the units.

1.  Choose Description from the Attribute popup menu and enter: Average number of miles per gallon.

2.  Choose Units from the popup menu and enter: miles/gallon

Now that you have entered attributes for the Miles per gallon variable, you will define it as a sequence of integers between 20 and 50, by increments of 10.

Select Definition from the Attribute dropdown menu. You will notice a second popup menu appears to the right. This is the Expression popup menu. Open the Expression popup menu and select list.

1.  Select Definition from the Attribute popup menu.

2.  Choose list from the Expression popup menu.

3.  Type 20 in the first cell and press Enter.

Analytica automatically sets the next value using the default increment of 1.

4.  Change the second cell to 30 and press Enter.

Analytica automatically sets the next value using the increment of 10 (the same as between the previous 2 values).

5.  Simply press Enter one more time to complete the sequence.

Although the auto-fill feature makes it convenient to enter a simple linear sequence, you are free to edit the values as you please.

Now you will use the Expression view to see the variable’s definition in a different form. The Expression view shows the full syntax of the definition regardless of the type of variable.

6.  Select Expression from the Expression popup menu.

As an alternative to the list view, a list variable can be entered directly using square brackets as shown:

## Viewing results in the Result window

Now that you have entered attributes and definitions for all variables it is time to see the result. The Results button calculates values for all selected variables.

Select the Fuel Cost node and click the Results button .

1.  Select the Fuel Cost variable.

2.  Click the Results button.

The Result window appears. Icons in the upper left corner of the Result window control the view mode. Tabular form is the default.

The Result window appears in tabular form when the Table icon is selected.
Tip

The default view for the Results window can be changed. See the Preferences dialog in the Analytica User Guide for details.

Click the graph button to view the results in graph view.

The Result window appears in graph mode when the Graph icon is selected.

## Defining a variable using a built-in function

Analytica offers a wide array of built-in functions to simplify the process of defining variables. In this example we will take advantage of the Sequence function to re-define the Miles per gallon variable.

Let’s suppose you want to change the sequence such that the interval between Miles per gallon values is 5 instead of 10.

Select the Miles per gallon variable. Make sure that the Attribute window is open and Definition is selected.

Next, open the Expression popup menu and select Other at the bottom of the list. This opens the Object finder where you will find a large collection of built-in functions. Analytica will prompt to confirm that you want to replace the current definition of the variable. Click OK.

1.  Select Other from the Expression popup menu.

2.  Confirm that you are replacing the current definition by clicking OK.

The Sequence function is contained in the Array library, under Creating lists. Choose Creating Lists'" under the Array library from the Library popup menu.

Scroll down the list and select Sequence.

Enter 20 for the start value, 50 for the end value, and 5 for the step. (Leave the strict field blank.) Click OK.

3.  Select — Creating lists under Array from the Library popup menu.

4.  Scroll down and choose the Sequence function.

5.  Enter start value 20, end value 50 and step value 5.

6.  Click OK to finish.

The new definition is displayed in the Attribute panel.

Select the Fuel Cost variable and click the Results button . The result shows improved precision with the smaller Miles per gallon intervals.

7.  Select Fuel Cost and click the Results button .

8.  Toggle between table and graph views.

9.  Toggle between table and graph views.

## Expression Assist

As you type textual expressions into definitions, Expression Assist provides continual context sensitive identifier completion and help on functions and their parameters. Next you will erase and re-enter the definition for miles per gallons, typing it textually this time rather than using the Object Finder, in order to acquaint you with Expression Assist.

On the diagram, select Miles per gallon and press the Object Window button on the tool bar.

1.  Highlight the existing definition and press the Delete key.

Now you are ready to begin typing the definition anew. Press the ’S’ character and notice the identifier completion popup showing a list of identifiers starting with ’S’. Continue with the ’e’ character, and identifiers beginning with "Se" display:

Now, to save typing, press down-arrow three times to select Sequence and press Tab. The function name is inserted into the definition, saving you keystrokes. Now a popup shows you the parameters of the Sequence function and its description. The parameter that you are currently typing appears in bold, with optional parameter in italics.

2.  Finish typing: Sequence(20,50,5)

3.  As you type, watch the bolding progress.

4.  Press the green check.

After you have created part or all of a model, you should save it. Select Save from the File menu (or press control-s). Because you previously saved your model, it is saved with the original name. You can quit Analytica by choosing exit from the File menu or closing the Analytica window.

## Summary

In this chapter you have:

• Started a new model
• Created new variables
• Entered attributes for variables in two different ways: using the Objects window and the Attributes window
• Re-arranged variable nodes to improve the appearance of your influence diagram
• Drawn arrows to establish relationships between variables
• Defined variables as explicit values, functions and lists
• Used a built-in function to define a variable
• Displayed the result of a simple parametric analysis

In the next chapter, you will extend the Car Cost model to include tables of data.