USGS - science for a changing world

Upper Midwest Environmental Sciences Center

Decision Support Systems

Adjacency For WinBUGS Tool

The Adjacency For WinBUGS Tool is a customization of ArcMap. The tool iteratively processes each polygon within a selected layer and creates a text file of polygonal adjacency where each polygon is identified by a unique Adj_ID value. The output of this tool is used in WinBUGS (MRC Biostatistics Unit Cambridge) by the car.normal, car.l1, and conditional autoregressive distributions.

 “We have been working with a class of models called hierarchical spatial count models ( These models are fitted with Markov chain Monte Carlo methods in WinBUGS. To accommodate the potential for spatial correlation between the responses, we employ a spatial conditional autoregressive component (spatial CAR). This spatial CAR requires an adjacency matrix, i.e., a matrix relating one areal unit to a collection of neighboring areal units. A requirement of this matrix is symmetry. GeoBUGS within the WinBUGS software can facilitate this adjacency matrix creation, but we find it much more convenient to conduct all of our mapping operations in ArcGIS. As such, a tool that facilitates the creation of the adjacency matrix for use in WinBUGS is most useful.”  
Dr. Wayne Thogmartin

To install:

  1. Save the file: to your local hard drive
  2. Extract contents
  3. Double click AdjacencyForWinBUGS.esriAddIn file
  4. Open ArcMap 10
  5. Click on the Customize menu and the Customize Mode… item
  6. On the Customize dialog click the Commands tab
  7. Scroll down and click on Fox Tools in the Categories list
  8. Drag the Adjacency For WinBUGS button to a toolbar on the ArcMap 10 interface
Figure 1. The Adjacency For WinBUGS dialog.

Figure 1. The Adjacency For WinBUGS dialog.

To use:

  1. Click the AdjacencyForWinBUGS button to open the Adjacency For WinBUGS dialog (Figure 1).
  2. Choose an editable polygon shapefile.
  3. Click the Browse button and identify the output directory.
  4. Click OK button.
  5. Program execution:
    1. The folder specified by the user in the Output Directory textbox is created.
      1. The folder’s name will have the following structure:  User identified directory + Layer Name + _Adjacency_ + Iterative Number.
      2. Characters within the new folder’s name that are problematic to ArcMap will be replaced with underscore characters.
      3. Problematic characters include ~`!”@#$%^&*()+=[]{}:;,.’<>?/\ and blank spaces.
    2. The field Adj_ID is deleted if it already exists in the specified polygon theme.
    3. The field Adj_ID is added to the selected polygon theme. Each polygon is then number sequentially as they occur in the polygon theme. Polygons are indentified by this value in the output files.
    4. Polygons are iteratively processed
    5. The program creates four comma delimited text files in the newly created folder, Raw.txt, Adj.txt, Num.txt, and SumNumNeigh.txt (Figure 2). The values within Raw.txt, Adj.txt, and Num.txt are synchronized with the order of input polygons (i.e. the first line of each file refers to the input polygon Adj_ID = 1, the second line refers to input polygon Adj_ID = 2, etc).
      1. Raw.txt: each line in the output file contains a list of numbers. The first number in the list is the Adj_ID of the input polygon; all subsequent numbers in the list are the Adj_ID values of polygons adjacent to the input polygon. Only the input polygon’s Adj_ID will be listed if it has no adjacent neighbors.
      2. Adj.txt: is identical to the Raw.txt file with one exception, the leading Adj_ID value of the input polygon is omitted.  If the input polygon does not have any adjacent neighbors, then a blank line is entered.
      3. Num.txt: contains the number of neighbors for each input polygon.
      4. SumNumNeigh.txt: the sum of values contained in the Num.txt.

Figure 2. An example of a polygon input layer and its resulting output file.

Figure 2. An example of a polygon input layer and its resulting output file.

Impact of UMESC Science

Bayesian computation is becoming an increasingly important means of statistical analysis of data. These methods are well-suited to modeling complex data, including spatial data, and software such as WinBUGS and R exist to facilitate these calculations. Unfortunately, these complex spatial data require careful preparation for proper analysis. The Adjacency Tool facilitates this analysis by easily formatting spatial data in ArcGIS, the globally predominant geographic information system. Tools such as the Adjacency Tool help bridge the information gap between statistical software and geographic information systems.

Point of contact: Tim Fox


Locations of visitors to this page

Accessibility FOIA Privacy Policies and Notices

Take Pride in America logo logo U.S. Department of the Interior | U.S. Geological Survey

Page Contact Information: Contacting the Upper Midwest Environmental Sciences Center
Page Last Modified: April 16, 2012