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

contr.sdif

Successive Differences Contrast Coding


Description

A coding for factors based on successive differences.

Usage

contr.sdif(n, contrasts = TRUE, sparse = FALSE)

Arguments

n

The number of levels required.

contrasts

logical: Should there be n - 1 columns orthogonal to the mean (the default) or n columns spanning the space?

sparse

logical. If true and the result would be sparse (only true for contrasts = FALSE), return a sparse matrix.

Details

The contrast coefficients are chosen so that the coded coefficients in a one-way layout are the differences between the means of the second and first levels, the third and second levels, and so on. This makes most sense for ordered factors, but does not assume that the levels are equally spaced.

Value

If contrasts is TRUE, a matrix with n rows and n - 1 columns, and the n by n identity matrix if contrasts is FALSE.

References

Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth Edition, Springer.

See Also

Examples

(A <- contr.sdif(6))
zapsmall(ginv(A))

MASS

Support Functions and Datasets for Venables and Ripley's MASS

v7.3-54
GPL-2 | GPL-3
Authors
Brian Ripley [aut, cre, cph], Bill Venables [ctb], Douglas M. Bates [ctb], Kurt Hornik [trl] (partial port ca 1998), Albrecht Gebhardt [trl] (partial port ca 1998), David Firth [ctb]
Initial release
2021-04-17

We don't support your browser anymore

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