Questions tagged [contrasts]

In linear models and particularly in ANOVA, a contrast is a linear combination of parameters with coefficients summing up to zero. It is used to test the corresponding null hypothesis. Contrasts are especially often used with categorical predictors (factors) to make comparisons among the groups (categories). [See also tag 'categorical-encoding']

365 questions
66
votes
4 answers

What is a contrast matrix?

What exactly is contrast matrix (a term, pertaining to an analysis with categorical predictors) and how exactly is contrast matrix specified? I.e. what are columns, what are rows, what are the constraints on that matrix and what does number in…
27
votes
7 answers

How does one do a Type-III SS ANOVA in R with contrast codes?

Please provide R code which allows one to conduct a between-subjects ANOVA with -3, -1, 1, 3 contrasts. I understand there is a debate regarding the appropriate Sum of Squares (SS) type for such an analysis. However, as the default type of SS used…
russellpierce
  • 17,079
  • 16
  • 67
  • 98
27
votes
2 answers

Interpretation of betas when there are multiple categorical variables

I understand the concept that $\hat\beta_0$ is the mean for when the categorical variable is equal to 0 (or is the reference group), giving the end interpretation that the regression coefficient is the difference in mean of the two categories. Even…
26
votes
3 answers

Post hoc test after ANOVA with repeated measures using R

I have performed a repeated measures ANOVA in R, as follows: aov_velocity = aov(Velocity ~ Material + Error(Subject/(Material)), data=scrd) summary(aov_velocity) What syntax in R can be used to perform a post hoc test after an ANOVA with repeated…
L_T
  • 1,463
  • 7
  • 20
  • 25
24
votes
2 answers

Polynomial contrasts for regression

I cannot understand the usage of polynomial contrasts in regression fitting. In particular, I am referring to an encoding used by R in order to express an interval variable (ordinal variable with equally spaced levels), described at this page. In…
Pippo
  • 587
  • 1
  • 6
  • 14
15
votes
1 answer

How to setup and interpret ANOVA contrasts with the car package in R?

Let's say I have a simple 2x2 factorial experiment that I want to do ANOVA on. Like this, for example: d <- data.frame(a=factor(sample(c('a1','a2'), 100, rep=T)), b=factor(sample(c('b1','b2'), 100, rep=T))); d$y <-…
f1r3br4nd
  • 2,084
  • 18
  • 31
14
votes
1 answer

What are the different types of codings available for categorical variables (in R) and when would you use them?

If you fit a linear model or a mixed model there are different types of codings available to transform a categorical or nominal varibale into a number of variables for which paramaters are estimated, such as dummy conding (the R default) and effects…
13
votes
1 answer

Testing certain contrasts: Is this provably a hard problem, or not?

I posted this to mathoverflow and no one's answering: Scheffé's method for identifying statistically significant contrasts is widely known. A contrast among the means $\mu_i$, $i=1,\ldots,r$ of $r$ populations is a linear combination $\sum_{i=1}^r…
Michael Hardy
  • 7,094
  • 1
  • 20
  • 38
12
votes
1 answer

Computation of polynomial contrast variables

Please give me idea how to efficiently recode a categorical variable (factor) into the set of orthogonal polynomial contrast variables. For many types of contrast variables (e.g. deviation, simple, Helmert, etc.) the pass is: Compose the contrast…
ttnphns
  • 51,648
  • 40
  • 253
  • 462
12
votes
2 answers

How to specify specific contrasts for repeated measures ANOVA using car?

I am trying to run a repeated measures Anova in R followed by some specific contrasts on that dataset. I think the correct approach would be to use Anova() from the car package. Lets illustrate my question with the example taken from ?Anova using…
Henrik
  • 13,314
  • 9
  • 63
  • 123
11
votes
1 answer

How to perform a 4 by 4 mixed ANOVA with between- and within-subjects contrasts using R?

Beginner user of R here struggling with a repeated measures ANOVA. I have a dataset that consists of one between subjects factor with 4 levels (coded in a single variable called 'groups'), and one within subjects factor with 4 levels (coded in four…
aquadhere
  • 113
  • 1
  • 5
10
votes
1 answer

How to specify a contrast matrix (in R) for the difference between one level and an average of the others?

I have a regression model that looks like this: $$Y = \beta_0+\beta_1X_1 + \beta_2X_2 + \beta_3X_3 +\beta_{12}X_1X_2+\beta_{13}X_1X_3+\beta_{123}X_1X_2X_3$$ ...or in R notation: y ~ x1 + x2 + x3 + x1:x2 + x1:x3 + x1:x2:x3 Let's say $X_1$ and $X_2$…
f1r3br4nd
  • 2,084
  • 18
  • 31
10
votes
2 answers

How to interpret these custom contrasts?

I am doing a one way ANOVA (per species) with custom contrasts. [,1] [,2] [,3] [,4] 0.5 -1 0 0 0 5 1 -1 0 0 12.5 0 1 -1 0 25 0 0 1 -1 50 0 0 0 1 where I compare intensity 0.5…
Roman Luštrik
  • 3,338
  • 3
  • 31
  • 39
10
votes
4 answers

How to apply coefficient term for factors and interactive terms in a linear equation?

Using R, I have fitted a linear model for a single response variable from a mix of continuous and discrete predictors. This is uber-basic, but I'm having trouble grasping how a coefficient for a discrete factor works. Concept: Obviously, the…
Trees4theForest
  • 625
  • 2
  • 6
  • 11
10
votes
1 answer

How to set custom contrasts with lmer in R

I am using lmer in R to check the effect of condition (cond) on some result. Here are some made up data, where s is the subject identifier and a, b and c are conditions. library("tidyr") library("dplyr") set.seed(123) temp <- data.frame(s =…
M4RT1NK4
  • 203
  • 1
  • 2
  • 5
1
2 3
24 25