Building Custom ergm Terms with RStudio

RStudio is an integrated development environment (IDE) for R; it makes creating and modifying packages in R incredibly easy.

Prerequisites for building R packages

The core software development utilities required for R package development can be obtained by installing the Command Line Tools for XCode. You will need the Mac operating system OSX 10.7 (Lion) or higher to download Xcode directly from the Mac App Store. You can check your OSX by clicking the Apple icon and selecting "About this Mac".

You can:

  1. Download and install XCode from the Mac App Store:
  2. Within XCode go to Preferences : Downloads and install the Command Line Tools

Or alternatively (for a smaller download size):

  1. Register as an Apple Developer (free) here:
  2. Download the Command Line Tools for XCode appropriate for the version of OS X you are running from here:

Install Rstudio

Get the latest versions of R (requires R version > 3.0) and Rstudio.

Install packages

Get the latest versions of the required packages from CRAN:

network (>= 1.7-1), ergm (>= 3.1-0), statnet.common (>= 3.1-0)

(NB: Because CRAN has not updated its MacOS X binaries for R version 2.x, it is necessary to upgrade to R 3.0 for the following code to properly update all of the necessary packages.) Enter this into R or RStudio console:

install.packages(c('network', 'ergm', 'statnet.common')) # This will not work properly on MacOS X unless you have R 3.0 installed!

If you are prompted to install into a personal library, click OK.

You do not need to install ergm.userterms yet!

Get ergm.userterms source

Download the source code for ergm.userterms from CRAN. The file you need is the package source.

Please note that you do not at any point need to install the ergm.userterms package binaries using the install.packages command; indeed, doing so in the future may override any work you have put into building terms in your local copy.

After you download the source file, double-click on the downloaded ergm.userterms_3.1-0.tar.gz file to decompress it. You may delete the .tar.gz file.

No image "7zip_setup.png" attached to macpackage

New project

Open Rstudio.

Project menu → Create Project→ Existing Directory → Browse →

Navigate to where you saved the source code (the folder called "ergm.userterms", see picture below) → Select Folder → Create Project

The new project should be open and ready for coding. When doing so, the three files that you will need to open and edit can be found at:

Files pane → R → InitErgmTerm.user.R

Files pane → src → changestats.users.c

Files pane → src → changestats.users.h

Coding your own custom ERGM term

If you are following these instructions in preparation for a statnet workshop, you can close everything and stop here; we will pick up from this point in the workshop. If you are learning on your own, we recommend following along with the JSS paper as a tutorial. If doing the latter, you will not need to follow the instructions in Section A3 if you are using RStudio; instead, whenever you want to build your version of the ergm.userterms package, simply click on:

Build menu → Build & Reload

All done!

Last modified 6 years ago Last modified on 07/18/13 12:40:31

Attachments (2)

Download all attachments as: .zip