contrasts: Contrast functions for penalized regression

Penalized regression contrastsR Documentation

Contrast functions for penalized regression

Description

Contrast functions for factors that are appropriate for penalized regression.

Usage


contr.none(n, contrasts)

contr.diff(n, contrasts = TRUE)

Arguments

n

A vector of levels for a factor, or the number of levels.

contrasts

A logical indicating whether contrasts should be computed. This argument is ignored in contr.none.

Details

These functions are used for creating contrast matrices for use in fitting penalized analysis of variance and regression models. The columns of the resulting matrices contain contrasts which can be used for coding a factor with n levels. The returned value contains the computed contrasts.

contr.none returns an identity matrix except when the number of levels is 2, in which case it returns a single contrast. contr.none ensures that all levels of an unordered factor are treated symmetrically in a penalized regression model.

contr.diff returns a lower triangular matrix of ones if contrasts=FALSE and the same matrix without its first column if contrasts=TRUE. This makes sure that penalization is done on the difference between successive levels of an ordered factor. It is not appropriate for unordered factors.

Value

contr.diff returns a matrix with n rows and k columns, with k=n-1 if contrasts is TRUE and k=n if contrasts is FALSE.

contr.none returns a matrix with n rows and n columns, except when n=2 when it returns a matrix with 2 rows and one column.

Author(s)

Jelle Goeman: j.j.goeman@lumc.nl

See Also

penalized, contr.treatment, contr.poly, contr.helmert, contr.SAS, contr.sum.

Examples


# Three levels
levels <- LETTERS[1:3]
contr.none(levels)
contr.diff(levels)

# Two levels
levels <- LETTERS[1:2]
contr.none(levels)

penalized documentation built on April 23, 2022, 5:05 p.m.