dummy: Dummy variables (experimental)

Description Usage Arguments Value Examples

View source: R/lmer.R

Description

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.

Usage

1
  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.

Value

A model.matrix with dummy variables as columns.

Examples

1
2
3
data(Orthodont,package="nlme")
lmer(distance ~ age + (age|Subject) +
     (0+dummy(Sex, "Female")|Subject), data = Orthodont)

Example output

Loading required package: Matrix
Linear mixed model fit by REML ['lmerMod']
Formula: distance ~ age + (age | Subject) + (0 + dummy(Sex, "Female") |  
    Subject)
   Data: Orthodont
REML criterion at convergence: 442.5444
Random effects:
 Groups    Name                 Std.Dev. Corr 
 Subject   (Intercept)          2.3439        
           age                  0.2264   -0.66
 Subject.1 dummy(Sex, "Female") 1.0521        
 Residual                       1.3100        
Number of obs: 108, groups:  Subject, 27
Fixed Effects:
(Intercept)          age  
    16.8643       0.6602  

lme4 documentation built on June 22, 2021, 9:07 a.m.