contr.slide | R Documentation |
Similiar to the base contrast functions (e.g., contr.sum
),
this coding scheme is known as 'sliding contrast coding' or 'backward difference coding'.
This factor coding scheme compares the mean of the dependent variable on one level to the mean
of the previous level. This function with return a matrix of contrasts that follow this scheme.
Evidently this is similar (if not identical) to the function contr.sdif
.
contr.slide(n, contrasts = TRUE, sparse = FALSE)
n |
A vector of levels for a factor, or the number of levels. |
contrasts |
A logical indicating whether contrasts should be computed. |
sparse |
A logical indicating if the result should be sparse (of class |
n<-1000 ys <- c(rnorm(n, mean = 0, sd = 50), rnorm(n, mean = 100, sd = 50), rnorm(n, mean = 100, sd = 50), rnorm(n, mean = 5, sd = 50)) dists <- c(rep("A",n), rep("B",n), rep("C",n), rep("D",n)) df <- data.frame( y<-ys, fac<-factor(dists) ) # Default coding summary(lm(y~fac,data=df)) contrasts(df$fac) <- contr.slide(4)/4 # With sliding contrast coding summary(lm(y~fac,data=df))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.