Starting out with the R Sensitivity Package

The R Sensitivity Package contains sampling and analysis methods for Sobol sensitivity analysis, the Fourier amplitude sensitivity test (FAST) and Method of Morris. This post will show you how to set up this package on a Linux system and run a simple example of Sobol sampling. (Note that there are also GUIs available to run R on Windows and Mac — but this will help you run on the clusters, so it’s more scalable).

This assumes that you already have R installed. If you need more info about how to do this (it’s free!) you may want to start with this guide before proceeding.

First, go to the directory where you want to install the package. You may want to create a new directory for this specific purpose. If you’re on the clusters, type: module load R, which will, of course, load R into your current session. On other Linux systems, R might be available without loading a module.

Download the package source to this directory like so:


Now you can install the package:

R CMD INSTALL -l . sensitivity_1.5.tar.gz

Notice a few things about this command. Usually when you start R, it will open an interactive session similar to Matlab’s command window. By calling R CMD, we tell it to run in command-line mode. The -l flag tells the INSTALL command where to put the new library. For lack of a better idea, I’m installing to the current directory. More advanced users might want to install this to /usr/local or somewhere like that. Finally, notice that you don’t have to untar the package in order to install it.

If this works properly, it will create a new directory inside your current one, named “sensitivity”. This is the name by which you should refer to the library when invoking it in an R script. Let’s look at an example of using the library (courtesy of Dave Hadka). Create a file called createSamples.R. Open it in a text editor and write the following:

X1<-data.frame(matrix(runif(8*n), nrow=n))
X2<-data.frame(matrix(runif(8*n), nrow=n))
sa<-sobol2002(model=NULL, X1, X2, nboot=10)
write(t(sa$X), file="test.samples", 8)

First, the library is loaded. If you’re operating in a different directory, you will need to replace “sensitivity” with “/path/to/sensitivity” as necessary. The most important function here is sobol2002, which accepts as arguments a model, two matrices of random samples, and the number of bootstrap resamples. Here, we only want to perform sampling, so the model is NULL. The last line will write the 8 columns of parameter samples to a file called test.samples.

In order to run this script from the command line, just do the following:

R CMD BATCH sampler.R

…and then check to make sure test.samples contains your samples.

In general, we will probably not want to run our models through R. We will just create samples like this and then run the file test.samples (or something else) through our actual simulations. After that, we’ll come back to this R library and give it our model output to perform analysis (to be continued in a forthcoming post).


Building the PSUADE diagnostics library on Linux

The PSUADE library contains a suite of methods for sensitivity analysis, uncertainty analysis, and response surface methods. It was created by Charles Tong and Lawrence Livermore National Lab and is freely available for download at:

This post will describe how to build the library in a Linux environment. The process is already described in the user documentation included with the package, but I will try to add some more detail.

First, untar the package and run the script install_psuade (if you copied to the cluster, you may need to chmod +x first). You will be prompted with the following message:

****************** Read this important information first **********************
* Multivariate Adaptive Regression Splines (MARS) is currently not installed.
To install MARS, first exit install_psuade, search and download mars35_fort.f,
mars36_fort.f or mars36_fort.c, put it in the External/MARS directory, and run
install_psuade again.
* The TPROS library is currently not installed. If you would like to use the
TPROS Gaussian process response surface tool, you will need to download
the TPROS library (if needed, send us email on details of how to install.)
Now exit install_psuade or press ENTER to continue

The MARS and TPROS libraries are optional. It seems like they may only be needed for the response surface tools, which we aren’t planning to use at the moment. Press enter to ignore this warning and continue the build without these optional libraries.

Next, you’ll be presented with a short list of options:

Verify the following and make changes as needed :
a. Platform = LINUX
l. MPI Build = no
m. User provides simulator function = no
z. This setting is good, move on.
Enter the item (a – m) to change or z to quit:

You can modify the options as needed by pressing the relevant key, followed by enter. (That’s a lowercase “L” for the MPI option). For right now, I opted not to use the MPI build. I originally changed the “user provides simulator function” option, because I suspect that’s how we will use the library. But then when I ran make, I got the following error:

Makefile:16: *** Recursive variable `CXXFLAGS’ references itself (eventually). Stop.
make[1]: Leaving directory `/gpfs/work/j/jdh33/PSUADE/Src/Main’
make: *** [main] Error 2

Martha was able to get it to work without changing that option, so that’s what we’ll go with for now. I’m still not clear on what the option even means, so we may need to re-build later if necessary.

The install_psuade script should finish running. Stay in the same directory and run make. It will look like it’s working for a while, and hopefully you won’t get any errors.

Now you can follow the example shown in the short manual. cd to Examples/Bungee and compile the example file, simulator:

cc -o simulator simulator.c -lm

Take a look at the configuration file This breaks the options into three main parts: the sampling, application, and analysis (which is similar to how we have been running Sobol’s method). We’re still working on figuring out what all these options actually mean. For now, you can run the problem like this, passing in the configuration file as a command line option:


All of the input and output data will be stored in the file psuadeData.

More details to come as we figure out how to use different methods and how to extend the output format to accomodate larger-scale runs.


MOEAframework on Windows

A lot of the posts on this blog cover MOEAframework used on Unix machines and high performance computing clusters.  However you can also easily use it on Windows!  Here are some steps to get started:

At, you need the “Java Development Kit” in addition to the regular Java already installed on your machine.

Next, follow the instructions here: to set up environment variables for your Windows machine. Make sure to add the JAVA_HOME and CLASSPATH environment variables and then add the JAVA_HOME string to the PATH as instructed.

Then, restart your computer

Open a command prompt (type cmd in the “run” window or search box on Windows 7/8).  Navigate to the directory in the command prompt that contains your MOEAframework example files.  The MOEAFramework-1.15-Executable.jar file should be in that directory along with  To compile the command is:

javac -classpath MOEAFramework-1.15-Executable.jar

Then to run it, you type:

java -classpath MOEAFramework-1.15-Executable.jar Example1

That’s it!  You should see some output in the command window that signifies that everything worked.  You can also use the MOEAframework GUI in Windows by double clicking the MOEAframework executable.

As always let us know if you have questions/comments below.