dummy function

Dummy variables (experimental)

Dummy variables (experimental)

Largely a wrapper for model.matrix that accepts a factor, f, and returns a dummy matrix with nlevels(f)-1 columns (the first column is dropped by default). Useful whenever one wishes to avoid the behaviour of model.matrix of always returning an nlevels(f)-column matrix, either by the addition of an intercept column, or by keeping one column for all levels.

dummy(f, levelsToKeep)

Arguments

  • f: An object coercible to factor.
  • levelsToKeep: An optional character vector giving the subset of levels(f) to be converted to dummy variables.

Returns

A model.matrix with dummy variables as columns.

Examples

data(Orthodont,package="nlme") lmer(distance ~ age + (age|Subject) + (0+dummy(Sex, "Female")|Subject), data = Orthodont)
  • Maintainer: Ben Bolker
  • License: GPL (>= 2)
  • Last published: 2025-03-26