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

contr.cum

Contrast matrices


Description

Return a matrix of contrasts for factor coding.

Usage

contr.cum(n)
  contr.diff(n)
  contr.2nd(n)
  contr.orth(n)

Arguments

n

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

Details

These functions are used for creating contrast matrices for use in fitting regression models. The columns of the resulting matrices contain contrasts which can be used for coding a factor with n levels.

contr.cum gives a coding corresponding to successive differences between factor levels.

contr.diff gives a coding that correspond to the cumulative sum of the value for each level. This is not meaningful in a model where the intercept is included, therefore n columns ia always returned.

contr.2nd gives contrasts corresponding to 2nd order differences between factor levels. Returns a matrix with n-2 columns.

contr.orth gives a matrix with n-2 columns, which are mutually orthogonal and orthogonal to the matrix cbind(1,1:n)

Value

A matrix with n rows and k columns, with k=n for contr.diff k=n-1 for contr.cum k=n-2 for contr.2nd and contr.orth.

Author(s)

Bendix Carstensen

See Also

Examples

contr.cum(6)
contr.2nd(6)
contr.diff(6)
contr.orth(6)

Epi

Statistical Analysis in Epidemiology

v2.44
GPL-2
Authors
Bendix Carstensen [aut, cre], Martyn Plummer [aut], Esa Laara [ctb], Michael Hills [ctb]
Initial release
2021-02-28

We don't support your browser anymore

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