model_matrix: Compute possibly sparse model matrix

View source: R/modelmatrix.R

model_matrixR Documentation

Compute possibly sparse model matrix

Description

Compute possibly sparse model matrix

Usage

model_matrix(
  formula,
  data = NULL,
  contrasts.arg = NULL,
  drop.unused.levels = FALSE,
  sparse = NULL,
  drop0 = TRUE,
  catsep = "",
  by = NULL,
  tabM = FALSE,
  enclos = .GlobalEnv
)

Arguments

formula

model formula.

data

data frame containing all variables used in formula. These variables should not contain missing values. An error is raised in case any of them does.

contrasts.arg

specification of contrasts for factor variables. Currently supported are "contr.none" (no contrasts applied), "contr.treatment" (first level removed) and "contr.SAS" (last level removed). Alternatively, a named list specifying a single level per factor variable can be passed.

drop.unused.levels

whether empty levels of individual factor variables should be removed.

sparse

if TRUE a sparse matrix of class dgCMatrix is returned. This can be efficient for large datasets and a model containing categorical variables with many categories. If sparse=NULL, the default, whether a sparse or dense model matrix is returned is based on a simple heuristic.

drop0

whether to drop any remaining explicit zeros in resulting sparse matrix.

catsep

separator for concatenating factor variable names and level names. By default it is the empty string, reproducing the labels of model.matrix.

by

a vector by which to aggregate the result.

tabM

if TRUE return a list of tabMatrix objects.

enclos

enclosure to look for objects not found in data.

Value

Design matrix X, either an ordinary matrix or a sparse dgCMatrix.


mcmcsae documentation built on Oct. 11, 2023, 1:06 a.m.