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 |
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.
make_fs_qdec(data, formula, path = NULL, keep = FALSE)
make_fs_qdec(data, formula, path = NULL, keep = FALSE)
data |
data.frame, list or environment containing the data. Neither matrix nor an array will be accepted. |
formula |
a model |
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 |
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.
data.frame with model matrix and scaled continuous variables.
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"))
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"))
Visualise a Freesurfer qdec matrix as returned
byt the make_fs_qdec
function.
## S3 method for class 'qdec' plot(x, col = hcl.colors(12, "viridis"), ...)
## S3 method for class 'qdec' plot(x, col = hcl.colors(12, "viridis"), ...)
x |
a qdec object |
col |
a vector of colors to be used in the heatmap. |
... |
arguments to be passed to |
a heatmap of the qdec matrix
cars <- mtcars cars$cyl <- as.factor(cars$cyl) qdec <- make_fs_qdec(cars, mpg ~ -1 + cyl + hp) plot(qdec)
cars <- mtcars cars$cyl <- as.factor(cars$cyl) qdec <- make_fs_qdec(cars, mpg ~ -1 + cyl + hp) plot(qdec)
Creates a qdec matrix from a model formula.
qdec(data, formula)
qdec(data, formula)
data |
input data.frame |
formula |
a model |
qdec with model matrix
cars <- mtcars cars$cyl <- as.factor(cars$cyl) qdec <- qdec(cars, mpg ~ cyl + hp)
cars <- mtcars cars$cyl <- as.factor(cars$cyl) qdec <- qdec(cars, mpg ~ cyl + hp)
Scale numeric variables in a data frame
scale_num_data(data, vars)
scale_num_data(data, vars)
data |
data.frame |
vars |
variables selected |
data.frame with scaled numeric variables
Scale a numeric vector
scale_vec(x, ...)
scale_vec(x, ...)
x |
numeric vector to scale |
... |
additional arguments to be passed to |
scaled vector
scale_vec(1:20)
scale_vec(1:20)