Construct an RSA (Representational Similarity Analysis) model
rsa_model.RdThis function creates an RSA model object by taking an MVPA (Multi-Variate Pattern Analysis) dataset and an RSA design.
Usage
rsa_model(
dataset,
design,
distmethod = "spearman",
regtype = "pearson",
check_collinearity = TRUE,
nneg = NULL,
semipartial = FALSE
)Arguments
- dataset
An instance of an
mvpa_dataset.- design
An instance of an
rsa_designcreated byrsa_design().- distmethod
A character string specifying the method used to compute distances between observations. One of:
"pearson"or"spearman"(defaults to "spearman").- regtype
A character string specifying the analysis method. One of:
"pearson","spearman","lm", or"rfit"(defaults to "pearson").- check_collinearity
Logical indicating whether to check for collinearity in the design matrix. Only applies when
regtype="lm". Default is TRUE.- nneg
A named list of variables (predictors) for which non-negative regression coefficients should be enforced (only if
regtype="lm"). Defaults toNULL(no constraints).- semipartial
Logical indicating whether to compute semi-partial correlations in the
"lm"case (only ifnnegis not used). Defaults toFALSE.
Value
An object of class "rsa_model" (and "list"), containing:
dataset: the input datasetdesign: the RSA designdistmethod: the distance method usedregtype: the regression typenneg: a named list of constrained variables, if anysemipartial: whether to compute semi-partial correlations
Examples
# Create a random MVPA dataset
data <- matrix(rnorm(100 * 100), 100, 100)
labels <- factor(rep(1:2, each = 50))
mvpa_data <- mvpa_dataset(data, labels)
#> Error: train_data does not inherit from class NeuroVec
# Create an RSA design with two distance matrices
dismat1 <- dist(data)
dismat2 <- dist(matrix(rnorm(100*100), 100, 100))
rdes <- rsa_design(~ dismat1 + dismat2, list(dismat1=dismat1, dismat2=dismat2))
# Create an RSA model with standard 'lm' (returns t-values):
rsa_mod <- rsa_model(mvpa_data, rdes, regtype="lm")
#> Error: object 'mvpa_data' not found
# Create an RSA model enforcing non-negativity for dismat2 only:
# Requires the 'glmnet' package to be installed
# rsa_mod_nneg <- rsa_model(mvpa_data, rdes, regtype="lm",
# nneg = list(dismat2 = TRUE))
# Create an RSA model using 'lm' but returning semi-partial correlations:
rsa_mod_sp <- rsa_model(mvpa_data, rdes, regtype="lm",
semipartial = TRUE)
#> Error: object 'mvpa_data' not found
# Train the model
fit_params <- train_model(rsa_mod_sp, mvpa_data$train_data)
#> Error: object 'rsa_mod_sp' not found
# 'fit_params' = named vector of semi-partial correlations for each predictor