GLM design {brainGraph}R Documentation

Create a design matrix for linear model analysis

Description

brainGraph_GLM_design takes a data.table of covariates and returns a design matrix to be used in linear model analysis.

Usage

brainGraph_GLM_design(covars, coding = c("dummy", "effects",
  "cell.means"), factorize = TRUE, binarize = NULL, int = NULL,
  mean.center = FALSE, center.how = c("all", "within-groups"),
  center.by = getOption("bg.group"))

Arguments

covars

A data.table of covariates

coding

Character string indicating how factor variables will be coded. Default: 'dummy'

factorize

Logical indicating whether to convert character columns into factor. Default: TRUE

binarize

Character vector specifying the column name(s) of the covariate(s) to be converted from type factor to numeric. Default: NULL

int

Character vector specifying the column name(s) of the covariate(s) to test for an interaction. Default: NULL

mean.center

Logical indicating whether to mean center non-factor variables. Default: FALSE

center.how

Character string indicating whether to use the grand mean or groupwise means. Default: 'all'

center.by

Character string indicating which grouping variable to use for calculating means (if applicable). Default: 'Group'

Details

There are three different ways to code factors: dummy, effects, or cell-means (chosen by the argument coding). Effects coding is sometimes referred to as deviation coding. Dummy coding is the default when calling lm. To understand the difference between these, see Chapter 8 of the User Guide.

Value

A numeric matrix. Rownames are subject ID's and column names are the variable names. There will be additional attributes recording the coding, factorize, and mean.center function arguments. There will also be attributes for binarize and int if they are not NULL, and center.how and center.by if mean.center=TRUE.

Character variables

The default behavior is to convert all character columns (excluding the Study ID column and any that you list in the binarize argument) to factor variables. To change this, set factorize=FALSE. So, if your covariates include multiple character columns, but you want to convert Scanner to binary instead of a factor, you may still specify binarize='Scanner' and get the expected result. binarize will convert the given factor variable(s) into numeric variable(s), which is performed before centering (if applicable).

Centering

The argument mean.center will mean-center (i.e., subtract the mean of from each variable) any non-factor variables (including any dummy/indicator covariates). This is done after “factorizing” and “binarizing”. If center.how='all', then the “grand mean” will be used; otherwise, the groupwise means will be used. The grouping variable is determined by center.by and is by default 'Group'.

Interactions

int specifies which variables should interact with one another. This argument accepts both numeric/continuous (e.g., Age) and factor variables (e.g., Sex). All interaction combinations will be generated: if you supply 3 variables, all two-way and the single three-way interaction will be generated. This variable must have at least two elements; it is otherwise ignored. It is generally recommended that centering be performed when including interaction terms.

Author(s)

Christopher G. Watson, cgwatson@bu.edu

See Also

Other GLM functions: GLM fits, GLM, mtpc

Examples

## Not run: 
# Recreate design matrix when "outcome == measure"
DT <- res.glm$DT.Xy[region == levels(region)[1L],
                    !c('region', res.glm$outcome),
                    with=FALSE]
X <- do.call(brainGraph_GLM_design, c(list(covars=DT),
                                      attributes(res.glm$X)[-c(1L, 2L)]))
all.equal(X, res.glm$X)

## End(Not run)

[Package brainGraph version 3.1.0 Index]