rsa_model: Construct an RSA (Representational Similarity Analysis) model

View source: R/rsa_model.R

rsa_modelR Documentation

Construct an RSA (Representational Similarity Analysis) model

Description

This 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_design created by rsa_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 to NULL (no constraints).

semipartial

Logical indicating whether to compute semi-partial correlations in the "lm" case (only if nneg is not used). Defaults to FALSE.

Value

An object of class "rsa_model" (and "list"), containing:

  • dataset : the input dataset

  • design : the RSA design

  • distmethod : the distance method used

  • regtype : the regression type

  • nneg : a named list of constrained variables, if any

  • semipartial: 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)

# 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")

# 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)

# Train the model
fit_params <- train_model(rsa_mod_sp, mvpa_data$train_data)
# 'fit_params' = named vector of semi-partial correlations for each predictor


bbuchsbaum/rMVPA documentation built on June 10, 2025, 8:23 p.m.