# XY Comparison

When you display a standard (non XY) graph of a variable, V, it plots the values of V up the vertical (y) axis against an index of V along the horizontal (x) axis. If V has more than one dimension, you can choose which index to plot horizontally from the Horizontal Axis menu. In contrast, with XY comparison you can plot V against another variable, U, along the horizontal (x) axis, over a Common Index of V and U. You can also plot one slice of V against another slice over a Comparison Index. (See Scatter plots to use XY comparison for scatter plots.)

## XY comparison sources dialog

This dialog lets you set options for XY comparison and extends or adds menus to the XY graph described below.

To open the dialog: Click the XY button in top-right corner of Result window (graph or table). You must be in edit or arrow mode, so it is not available in Analytica editions or models confined to browse mode.

Use comparison index: Check this box if you want to compare one slice of the variable against another slice, slices selected from the comparison index. The graph shows the Comparison Index menu from which you can select the index you want. The Vertical Axis and Horizontal Axis menus then offer slices from the comparison index so that you can choose which two slices to plot against each other.

Use another variable: Check this box if you would like to compare the base variable by plotting it against one or more other variables (or simple expressions). When you check it, the following items appear:

Add: Click this button to open the Object Finder dialog to select a variable against which to plot the base variable. You can also use the Object Finder dialog to select a function or operation from one of the relevant libraries. You can add up to five items.

Remove: Select a item from the list of other variables, and click this button to remove it from the list of variables for comparison.

An XY comparison graph adds a Common Index and, sometimes, a Comparison Index to the usual graphing roles menus on a graph or table.

Comparison index: This menu lists the indexes of the base variable. The Horizontal Axis and Vertical Axis menus each let you choose a slice from the selected comparison index to plot against each other. It appears on the graph when Use comparison index is checked in the XY comparison sources dialog.

Common index: This defines the correspondence among the variables or slices to be plotted against each other. Each value of the common index identifies a data point on the graph, with vertical (X) and horizontal (Y) values from the variables or slices you have selected for those graphing roles. For a scatter plot, the common index should be Iteration (Run). It appears on the graph when one or both checkboxes on the XY comparison sources dialog are selected.

If Use another variable is checked in the XY comparison sources dialog, Common Index is an index in common to the base variable and other variable(s). If the variables have more than one index in common, Common Index is a menu from which you can choose the index you want.

If Use comparison index is checked in the XY comparison sources dialog, Common Index shows the index(es) of the base variable not selected for Comparison Index. Common Index is a menu if the variable has more than two indexes — leaving more than one for Common Index.

## Example: Plot one variable against another

For example, suppose you have an index and two variables:

Index Degrees := Sequence(0, 360, 5)
Variable V := Sin(Degrees)
Variable U := Cos(Degrees)

For a standard graph of V against its index, Degrees, select V from the diagram and click the Result button (Control+r). Repeat with U to display the graph for U against Degrees.

For these graphs, we selected the symbol plus line line style from Graph setup to show the data points for each value of Degrees.

With XY Comparison, you can graph U against V, instead of against its index Degrees:

1. Change to edit mode. In the Graph window for U, click the XY button in the top-right corner (above) to open the XY Comparison sources dialog.
2. Select the checkbox Use another variable.
3. Click the Add button to open the 'Object Finder dialog.
4. Select the variable V, and click OK. You can now see V listed in the XY comparison sources dialog.
5. Click OK.

The graph of U now plots the values of U on the vertical (y) axis against corresponding values of V on the horizontal (x) axis. By “corresponding” we mean for each value of Degrees, in the Common Index. If U and V had more than one index in common, it would show a menu from which you could select the index you want.

## Example: Compare variables using comparison index

You can also use XY comparison to compare one slice of a variable against another slice of the same variable. This is especially useful when you combine several variables as a list. Let’s add a third variable to U and V defined above:

Variable W := Sin(2*Degrees)

The parameter 2*Degrees creates a sine curve with twice the frequency. Here is an easy way to create a list to compare several variables.

1. Select the three nodes for the variables to compare, U, V, and W, and click Result (Control+r).
2. When it prompts “Do you want to compare more than one result?” click OK. It creates a new variable Compare1, and shows the standard (not XY) graph comparing U, V, and W against index Degrees.
3. Make sure you are in edit mode. In the graph window for Compare1, click the XY button in the top-right corner to open the XY comparison sources dialog.
4. Select the checkbox Use comparison index and click OK.

This sideways figure 8 results because W is a sine wave with twice the frequency of V. You can select other pairs of variables to compare, from U, V, and W, from the Vertical and Horizontal Axis menus — for example, changing to W against V puts the figure 8 the right way up.

You can also select Degrees from the Horizontal Axis menu to revert to a standard (non XY) graph of the selected variable against Degrees.