View on GitHub


R package for Connectome-Wide Association Studies

Download this project as a .zip file Download this project as a tar.gz file

Connectir is an R package principally for conducting Connectome-Wide Association Studies (CWAS) using Multivariate-Distance Matrix Regression (MDMR). CWAS with MDMR attempts to find regions of the brain with functional connectivity patterns that are significantly associated with a phenotype. For instance, if you have two groups (ADHD and Controls) and each subject has a resting-state fMRI scan, then CWAS-MDMR would find brain regions whose connectivity patterns significantly differentiate the two groups. Additional post-hoc analyses such as seed-based correlation analyses would be needed to discern the specific connections and direction of any group difference between ADHD and Controls with CWAS-MDMR.

Please contact me if you have any questions.

Table of Contents

  1. How to install the connectir package and associated command-line scripts.
  2. How to run a vanilla CWAS analysis; details can be found on the wiki.
  3. Links to publications, posters, and talks


Quick Approach

  1. Install R) and optionally Rstudio.
  2. Install the relevant packages within R including connectir using my script connectir_install.R.

Details and Troubleshooting

Parallel Matrix Algebra Operations

There are two ways to parallelize the analyses. One approach is to divide your workflow into smaller chunks and run those separately (like separate processes). This comes with the R packages installed with connectir_install.R. Another approach is to run each matrix algebra operation (e.g., dot product) in parallel, which we go into detail in this section. Below I detail different linear algebra libraries and linking them to R. Note this section is still under development.

Intel MKL

If you have Windows, Ubuntu, or RedHat/Centos, you can install Revolution R. This is a version of R compiled with Intel MKL by the company Revolution Analytics available free for academic use. You can get it from here.

Another option is to compile and install R linked with Intel MKL on your own. Here is a good and quick tutorial.


You can also install R via my own script that links R with a parallel matrix algebra library called openblas. This script is in the Rinstall repo and is called

Another option for linux is to download repositories. A good/quick tutorial can be found here.

Installing Connectir and Other R Packages

After R is setup, there are several packages within R that need to be installed. To do this, please run connectir_install.R. After downloading (or copying and pasting) this script to your machine, you can run it with Rscript connectir_install.R. On certain linux systems, you need to ensure you have libcurl and libxml installed.

This script is also a work in progress, please contact me if you have trouble.


Here we give a vanilla run of CWAS-MDMR and further details can be found on the wiki. I also go through these steps in our recent resting-state conference poster (2014).

Subject Distances

connectir_subdist.R \

-i functional_path_list.txt \

--automask1 \

--brainmask1 standard_grey_matter.nii.gz \

--bg standard_brain_4mm.nii.gz \

--memlimit 20 -c 3 -t 4 \


Multivariate Distance Matrix Regression (MDMR)

For the options that are the same as before (--memlimit, -c, -t), I will not repeat the description here.

connectir_mdmr.R \

-i subject_distances_outdir \

--formula FSIQ + Age + Sex + meanFD \

--model model_evs.csv \

--factors2perm FSIQ \

--memlimit 8 -c 3 -t 4 \

--save-perms --ignoreprocerror \