expandFactors: Expand factors to a set of contrasts

Description Usage Arguments Details Value Examples

View source: R/expandFactors.R

Description

Substitutes all factors in a data frame with the set of contrasts with which that factor is associated

Usage

1

Arguments

data

A data frame.

...

Additional arguments to be passed to model.matrix

Details

The expandFactors function replaces all of the factors in a data frame with the set of contrasts output by the contrasts function or model.matrix. It may be useful for teaching purposes when explaining relationship between ANOVA and regression.

Value

A data frame.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
grading <- data.frame( teacher = factor( c("Amy","Amy","Ben","Ben","Cat") ),
                       gender = factor( c("male","female","female","male","male") ),
                       grade = c(75,80,45,50,65) )

# expand factors using the default contrasts (usually treatment contrasts)
expandFactors( grading )

# specify the contrasts using the contrasts.arg argument to model.matrix
my.contrasts <- list( teacher = "contr.helmert", gender = "contr.treatment" )
expandFactors( grading, contrasts.arg = my.contrasts )

lsr documentation built on Dec. 11, 2021, 9:10 a.m.