code | R Documentation |
Contrast Code Factor for General Linear Model
code(object, ...)
## S3 method for class 'factor'
code(object, codingfun, verbose = TRUE, ...)
## S3 method for class 'data.table'
code(object, codingfun, vars = names(object), verbose = TRUE, ...)
contr.treatment.explicit(n)
code_control(n)
contr.diff(n)
code_diff(n)
code_diff_forward(n)
code_deviation(n)
code_deviation_first(n)
code_helmert(n)
code_helmert_forward(n)
object |
factor vector |
... |
used for s3 dispatch |
codingfun |
factor coding function
|
verbose |
TRUE or FALSE |
vars |
svars |
n |
character vector |
A General Linear Model contains:
* An Intercept Coefficient: expressing some form of sample average
* For each numeric variable: a slope coefficient
* For each k-leveled factor: (k-1) Contrast Coefficients.
The interpretation of (intercept and contrast) coefficients depends on the contrast coding function used.
Several contrast coding functions are available in 'stats' and 'codingMatrices'
But their (function and coefficient) namings are a bit confusing and unsystematic.
Instead, the functions below offer an intuitive interface (to the otherwise powerful stats/codingMatrices packages).
The names of these functions reflect the contrast coding used (treatment, backward, sum, or helmert contrasts).
They also reflect the intercept interpretation (either first factor's first level or grand mean).
They all produce intuitive coefficient names (e.g. 't1-t0' rather than just 't1').
They all have unit scaling (a coefficient of 1 means a backward of 1).
(explicitly coded) factor vector
# Coding functions
x <- factor(paste0('t', 0:3))
xlevels <- levels(x)
contr.treatment( xlevels)
contr.treatment.explicit(xlevels)
contr.diff( xlevels)
code_control( xlevels)
code_diff( xlevels)
code_diff_forward( xlevels)
code_deviation( xlevels)
code_deviation_first( xlevels)
code_helmert( xlevels)
code_helmert_forward( xlevels)
# Code
x %<>% code(contr.treatment)
x %<>% code(contr.treatment.explicit)
x %<>% code(contr.diff)
x %<>% code(code_control)
x %<>% code(code_diff)
x %<>% code(code_diff_forward)
x %<>% code(code_deviation)
x %<>% code(code_deviation_first)
x %<>% code(code_helmert)
x %<>% code(code_helmert_forward)
# Model
file <- system.file('extdata/atkin.metabolon.xlsx', package = 'autonomics')
object <- read_metabolon(file)
object %<>% fit_limma(codingfun = contr.treatment) # default
object %<>% fit_limma(codingfun = contr.treatment.explicit)
object %<>% fit_limma(codingfun = contr.diff)
object %<>% fit_limma(codingfun = code_control)
object %<>% fit_limma(codingfun = code_diff)
object %<>% fit_limma(codingfun = code_diff_forward)
object %<>% fit_limma(codingfun = code_deviation)
object %<>% fit_limma(codingfun = code_deviation_first)
object %<>% fit_limma(codingfun = code_helmert)
object %<>% fit_limma(codingfun = code_helmert_forward)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.