Skip to content

Running mincLmer on Niagara

Gabriel A. Devenyi edited this page Aug 10, 2023 · 4 revisions

Set up

First, after loading to Niagara, load the appropriate modules (or add them to the bash script to submit to the Niagara cluster later on)

 > module load cobralab

R script

Install the necessary packages

#!/usr/bin/env Rscript
library(lme4)
library(lmerTest)
library(RMINC)
library(tidyverse)

Load your input csv file (file containing the variables in your lmer)

# set working directory 
setwd("/path/to/your/working/directory")

# load data 
data<-read_csv("minclmer_input_file.csv")

Run your mincLmer model (see https://rdrr.io/github/Mouse-Imaging-Centre/RMINC/man/mincLmer.html for more info on the specific arguments)

In order to parallelize your jobs on the Niagara cluster, you will have to include the following in your model: parallel=c("snowfall", 80). The number you choose corresponds to the number of processors to use in the parallelization. Notice that when you submit a job to the Niagara cluster, you have access to 80 processors per node, so you can set the number of cpus to use to minimally 80.

An example of mincLmer model should look something like this:

# run in parallel with multiple processors on the niagara node
model <- mincLmer(filename + time + (1|subject_id), 
            data=data, 
            mask="mask.mnc",
            parallel=c("local", 80))

# estimate degrees of freedom
model <- mincLmerEstimateDF(model)

# correct for multiple comparisons using the False Discovery Rate
qvals <- mincFDR(model)

thresholds = attr(mincFDR(model), "thresholds")
print(thresholds)

save(file = "mincLmer_model_and_FDR.Rdata")

If you have to run your model multiple times, I suggest you check the efficiency of your code once it's done running on the cluster by doing seff <niagara_job_id> and check the CPU and Memory efficiency so that you can increase the number of processors to be used by R.

Submit to the Niagara cluster

Once your R script is done, you should now have a bash script to submit it to the Niagara cluster:

#!/bin/bash
module load cobralab

Rscript name_of_your_mincLmer_script.R

And run it (change the time accordingly):

qbatch -N mincLmer -w 1:00:00 run_minclmer.sh
Clone this wiki locally