Skip to content

Commit

Permalink
fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattansb committed Aug 23, 2023
1 parent 6f80fe7 commit 7c86d71
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
41 changes: 21 additions & 20 deletions R/contrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,35 @@
#' @inheritParams stats::contr.sum
#'
#' @details
#' In effects coding, unlike treatment/dummy coding ([stats::contr.treatment()]), each
#' contrast sums to 0. In regressions models, this results in an intercept that
#' represents the (unweighted) average of the group means. In ANOVA settings,
#' this also guarantees that lower order effects represent _main_ effects (and
#' not _simple_ or _conditional_ effects, as is the case when using R's default
#' [stats::contr.treatment()]).
#' In effects coding, unlike treatment/dummy coding
#' ([stats::contr.treatment()]), each contrast sums to 0. In regressions models,
#' this results in an intercept that represents the (unweighted) average of the
#' group means. In ANOVA settings, this also guarantees that lower order effects
#' represent _main_ effects (and not _simple_ or _conditional_ effects, as is
#' the case when using R's default [stats::contr.treatment()]).
#' \cr\cr
#' Deviation coding (`contr.deviation`) is a type of effects coding.
#' With deviation coding, the coefficients for factor variables are interpreted
#' as the difference of each factor level from the base level
#' (this is the same interpretation as with treatment/dummy coding).
#' For example, for a factor `group` with levels "A", "B", and "C", with `contr.devation`,
#' the intercept represents the overall mean (average of the group means for the 3 groups),
#' Deviation coding (`contr.deviation`) is a type of effects coding. With
#' deviation coding, the coefficients for factor variables are interpreted as
#' the difference of each factor level from the base level (this is the same
#' interpretation as with treatment/dummy coding). For example, for a factor
#' `group` with levels "A", "B", and "C", with `contr.devation`, the intercept
#' represents the overall mean (average of the group means for the 3 groups),
#' and the coefficients `groupB` and `groupC` represent the differences between
#' the A group mean and the B and C group means, respectively.
#' \cr\cr
#' Sum coding ([stats::contr.sum()]) is another type of effects coding.
#' With sum coding, the coefficients for factor variables are interpreted
#' as the difference of each factor level from **the grand (across-groups) mean**.
#' For example, for a factor `group` with levels "A", "B", and "C", with `contr.sum`,
#' the intercept represents the overall mean (average of the group means for the 3 groups),
#' and the coefficients `group1` and `group2` represent the differences the
#' Sum coding ([stats::contr.sum()]) is another type of effects coding. With sum
#' coding, the coefficients for factor variables are interpreted as the
#' difference of each factor level from **the grand (across-groups) mean**. For
#' example, for a factor `group` with levels "A", "B", and "C", with
#' `contr.sum`, the intercept represents the overall mean (average of the group
#' means for the 3 groups), and the coefficients `group1` and `group2` represent
#' the differences the
#' **A** and **B** group means from the overall mean, respectively.
#'
#' @seealso [stats::contr.sum()]
#'
#' @examples
#' \dontrun{
#' if (FALSE) {
#' data("mtcars")
#'
#' mtcars <- data_modify(mtcars, cyl = factor(cyl))
Expand Down Expand Up @@ -62,7 +63,7 @@
#' #> 8 -1.000 0.000 1.000 # 3rd level - 1st level
#'
#' ## With Interactions -----------------------------------------
#' mtcars <- data_modify(mtcars, am = factor(am))
#' mtcars <- data_modify(mtcars, am = C(am, contr = contr.deviation))
#' mtcars <- data_arrange(mtcars, select = c("cyl", "am"))
#'
#' mm <- unique(model.matrix(~ cyl * am, data = mtcars))
Expand Down
41 changes: 21 additions & 20 deletions man/contr.deviation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7c86d71

Please sign in to comment.