suppressPackageStartupMessages(library(neuroim2)) ##suppressPackageStartupMessages(library(devtools)) library(rMVPA)
To generate a dataset we use the gen_sample_dataset
function. We are creating a 4-dimensional neuroimaging dataset, with 6-by-6-by-6 spatial dimensions and 80 observations in the 4th dimension. These 80 observations are divided into 4 blocks, each consisting of 20 trials.
To run RSA with an external model matrix, we need to create and rsa_design
object. First we generate a sample dataset with 80 trials as follows.
dataset <- gen_sample_dataset(D=c(20,20,8), nobs = 80, blocks=4)
Now we create a external dissimilarity matrix with the same number of trials as our fMRI dataset. Then we create an rsa_design
object and an rsa_model
object. Finally, we run a searchlight analysis with a 4mm radius using a pearson correlation as a metric to compare the similarity between the external model matrix (Dmat) and
Dmat <- dist(matrix(rnorm(80*100), 80, 100)) rsades <- rsa_design(~ Dmat, list(Dmat=Dmat), block_var=factor(dataset$design$block_var)) ## use 'matrix' instead of 'dist' Dmat2 <- as.matrix(Dmat) rsades2 <- rsa_design(~ Dmat2, list(Dmat=Dmat2), block_var=factor(dataset$design$block_var)) dset <- mvpa_dataset(dataset$dataset$train_data, mask=dataset$dataset$mask) ### if we had a file called "betas.nii.gz" and associated mask, "mask.nii.gz" we would do as follows: ### traindat <- neuroim2::read_vector("betas.nii.gz") ### mask <- neuroim2::read_vector("mask.nii.gz") ## dset <- mvpa_dataset(traindat, mask=mask) rsamod <- rsa_model(dset, rsades) result <- run_searchlight(rsamod, radius=4, method="standard",regtype="pearson") rsamod2 <- rsa_model(dset, rsades2) result2 <- run_searchlight(rsamod2, radius=4, method="standard",regtype="pearson") range(result$Dmat) range(result2$Dmat)
The return object result
contains a list of NeuroVol
objects, one for each model matrix. Here, since there is only one external model matrix, Dmat
there is only one element in the returned list.
result ### we can save the result to disk, as follows: ## write_vol(result$Dmat, "RSA_Dmat.nii.gz")
Let's rerun using a Spearman correlation instead of pearson correlation to compare brain vs model matrices.
result <- run_searchlight(rsamod, radius=4, method="standard",regtype="spearman") range(result$Dmat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.