Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

expandFactors

Expand factors to a set of contrasts


Description

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

Usage

expandFactors( data, ... )

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.

Warning

This package is under development, and has been released only due to teaching constraints. Until this notice disappears from the help files, you should assume that everything in the package is subject to change. Backwards compatibility is NOT guaranteed. Functions may be deleted in future versions and new syntax may be inconsistent with earlier versions. For the moment at least, this package should be treated with extreme caution.

Author(s)

Daniel Navarro

See Also

Examples

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

Companion to "Learning Statistics with R"

v0.5
GPL-3
Authors
Daniel Navarro
Initial release
2015-03-01

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.