Package 'neuromat'

Title: Create Model Matrices for Neuroimaging Analyses
Description: Neuroimaging software often requires the specification of model matrices to run analyses. These can be difficult to correctly. This package helps neuroscientists to create such This includes creating qdec-files for Freesurfer Linear Mixes Effects models.
Authors: Athanasia Mo Mowinckel [aut, cre]
Maintainer: Athanasia Mo Mowinckel <[email protected]>
License: MIT + file LICENSE
Version: 0.0.0.9000
Built: 2024-11-11 05:14:56 UTC
Source: https://github.com/capro-uio/neuromat

Help Index


Create a Freesurfer qdec

Description

Create a Freesurfer qdec from a model formula, utilising R's robust model formula syntax. The function also scales continuous variables, and can keep the original data in the output.

Usage

make_fs_qdec(data, formula, path = NULL, keep = FALSE)

Arguments

data

data.frame, list or environment containing the data. Neither matrix nor an array will be accepted.

formula

a model formula or terms object. For simple qdec file, with binary columns for all levels of a factor, make sure to include a formula with -1 to remove the intercept.

path

an option file path to write qdec to csv

keep

logical or vector of column names, to keep the original data in the output. Default is FALSE.

Details

The formula should in all likelihood also include the -1 to remove the intercept, as this will provide a matrix where all levels of factor variables have their own binary column. This is necessary to follow the steps from the Freesurfer documentation.

It is highly recommended to have the base-id's for Freesurfer in their own column, and request to have this remain in the qdec by using the id-column's name in the keep argument.

Value

data.frame with model matrix and scaled continuous variables.

Examples

cars <- mtcars
cars$cyl <- as.factor(cars$cyl)
cars$gear <- as.factor(cars$gear)

make_fs_qdec(cars, mpg ~ cyl + hp)

# Remove the intercept, necessary to follow
# steps from Freesurfer docs
make_fs_qdec(cars, mpg ~ -1 + cyl + hp)
make_fs_qdec(cars, mpg ~ -1 + cyl + hp + gear)

# Keep the original data also in the output
make_fs_qdec(cars, mpg ~ -1 + cyl + hp, keep = TRUE)

# Keep the original data of specific columns
# Use a character vector
make_fs_qdec(cars, mpg ~ -1 + cyl + hp, keep = c("mpg", "gear"))

Plot qdec matrix

Description

Visualise a Freesurfer qdec matrix as returned byt the make_fs_qdec function.

Usage

## S3 method for class 'qdec'
plot(x, col = hcl.colors(12, "viridis"), ...)

Arguments

x

a qdec object

col

a vector of colors to be used in the heatmap.

...

arguments to be passed to heatmap. scale, Rowv, Colv already have custom values that may not be overwritten for the sake of a better visualisation.

Value

a heatmap of the qdec matrix

Examples

cars <- mtcars
cars$cyl <- as.factor(cars$cyl)

qdec <- make_fs_qdec(cars, mpg ~ -1 + cyl + hp)
plot(qdec)

Freesurfer qdec constructor

Description

Creates a qdec matrix from a model formula.

Usage

qdec(data, formula)

Arguments

data

input data.frame

formula

a model formula or terms object. For simple qdec file, with binary columns for all levels of a factor, make sure to include a formula with -1 to remove the intercept.

Value

qdec with model matrix

Examples

cars <- mtcars
cars$cyl <- as.factor(cars$cyl)

qdec <- qdec(cars, mpg ~ cyl + hp)

Scale numeric variables in a data frame

Description

Scale numeric variables in a data frame

Usage

scale_num_data(data, vars)

Arguments

data

data.frame

vars

variables selected

Value

data.frame with scaled numeric variables


Scale a numeric vector

Description

Scale a numeric vector

Usage

scale_vec(x, ...)

Arguments

x

numeric vector to scale

...

additional arguments to be passed to scale

Value

scaled vector

Examples

scale_vec(1:20)