60
Contrast Coding Or: One of These Levels is Not Like the Others Scott Fraundorf (and Tuan Lam) MLM Reading Group – 03.10.11

Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrast CodingOr: One of These Levels is

Not Like the Others

Scott Fraundorf (and Tuan Lam)MLM Reading Group – 03.10.11

Page 2: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Administrivia

● 3/10 (TODAY): Contrast coding overview● 4/7: Simple vs main effects● 4/21: Principal components analysis● 1st week of May: Harald Baayen visit

Page 3: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Outline

● Why use contrast coding?● Example contrasts● Contrast estimates● Contrasts in R● Multiple comparisons● How does it work?● Other kinds of coding● Interactions

Page 4: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Why Use Contrast Coding?

● Scott's example study:

● Examining recall memory for spoken discourse as a function of:

● Location of disfluencies (categorical variable)● Prior story knowledge (continuous variable)

=LOCATION OF DISFLUENCY

SUBJECT ITEM

+ ++PRIOR

KNOWLEDGE

Page 5: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Why Use Contrast Coding?● Regression equation: Predicts values

● Could use this to predict whether or not something will be remembered

● But in cognitive psych:● Often interested in the effect of specific levels● Test which ones differ significantly

=LOCATION OF DISFLUENCY

SUBJECT ITEM

+ ++PRIOR

KNOWLEDGE

Page 6: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Outline

● Why use contrast coding?● Example contrasts● Contrast estimates● Contrasts in R● Multiple comparisons● How does it work?● Other kinds of coding● Interactions

Page 7: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrast Coding

● Example: Fluent vs. disfluencies in typical locations vs. in atypical locations

● Which ones differ significantly?

Typical Atypical Fluent0.4

0.45

0.5

0.55

0.6

0.65

0.7

0.75

0.8%

of s

tory

rec

alle

d

Page 8: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrast Coding● Contrasts: Test differences between

specific levels– Same as a planned comparison in an ANOVA

– Also analogous to a post-hoc test

● Planned comparisons vs post-hoc tests– If we are deciding tests post-hoc, greater chance

of capitalizing on chance / spurious effect

– Contrasts are set before you fit the model, but it would be possible to go back and change the contrasts afterwards

– We are basically on the honor system here—no way to prove the comparison was planned ahead of time

Page 9: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrasts!

● Contrasts like weighted sums of means– In multiple regression / MLM context, also

subject to other variables in the model

● Using your scale to test what's different

Page 10: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Typical Atypical Fluent

0.4

0.45

0.5

0.55

0.6

0.65

0.7

0.75

0.8

% o

f sto

ry r

ecal

led

Contrast CodingIt looks like the Fluentstories might not be

remembered as well.

Let's use a contrast totest this.

Page 11: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrasts

TYPICAL ATYPICAL FLUENT

Question 1: Do disfluencies affect recall?

Page 12: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrasts

Contrast weights are assigned

.33 .33 -.66

One side positive.One side negative.

This determines whichlevels are being

compared (+ versus -)

Doesn't really matterwhich side you choose

as the + side. It justaffects the sign of the

result, but notmagnitude or statistical

significanceTYPICAL ATYPICAL FLUENT

Page 13: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrasts

Contrast weights are assigned

.33 .33 -.66

One side positive.One side negative.

Codes add up to zero.

Also nice to have theabsolute values of the+ code and the – code

sum to 1.(We'll see why later.)

abs(.33) + abs(-.66) = 1

TYPICAL ATYPICAL FLUENT

Page 14: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrasts

Can conceptualize the comparison as:Contrast 1: .33(Typical) + .33 (Typical) - .66(Fluent)(holding other variables constant)

.33 .33 -.66

One side positive.One side negative.

Codes add up to zero.

Does contrast differsignificantly from zero?

If so, difference betweenlevels is significant.

TYPICAL ATYPICAL FLUENT

Page 15: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrasts

Contrast 1: .33(Typical) + .33 (Typical) - .66(Fluent)

.33 .33

-.66

*

TYPICAL ATYPICAL

FLUENT

Page 16: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Typical Atypical Fluent0.4

0.45

0.5

0.55

0.6

0.65

0.7

0.75

0.8

Contrast Coding

*%

of s

tory

rec

alle

d

Our first contrast revealsthat fluent stories areremembered worse.

Now let's look atTypical vs Atypical

We always have j – 1 contrasts, where j = the # of levels of the factorSo, here 2 contrasts needed to fully describe

Page 17: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrasts

TYPICAL ATYPICAL

Question 2: Does location of disfluencies matter?

Page 18: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrasts

Contrast 2: .50(Typical) - .50(Atypical) + 0(Rest)

.50 -.50

One side positive.One side negative.

Codes add up to zero.

Sum of absolute valuesof codes is 1.

FLUENT(zeroed

out here!)

0TYPICAL ATYPICAL

Page 19: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Typical Atypical Fluent0.4

0.45

0.5

0.55

0.6

0.65

0.7

0.75

0.8

Contrast Coding

*%

of s

tory

rec

alle

d

n.s.

Page 20: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

One Important Point!● Choice of contrasts doesn't affect total

variance accounted for by variable● Only about differences between levels● Can divide this up in multiple different ways

and still account for same total variance

LOCATION IN STORY

Page 21: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Outline

● Why use contrast coding?● Example contrasts● Contrast estimates● Contrasts in R● Multiple comparisons● How does it work?● Other kinds of coding● Interactions

Page 22: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Why -.5 and .5?● Why [-.5 .5] instead of [-1 1]?● Doesn't affect significance test● Does affect β weight (estimate)

– Std error is also scaled accordingly

FILLER LOCATION:[-1 1]

FILLERLOCATION:[-.5 .5]

Page 23: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrast Estimates

ATYPICAL LOCATION

TYPICAL LOCATION

.5

-.5

CONTRAST CODE

}1

Beta weight (estimate) represents the effect of a 1-unit change in the contrast, holding everything else constant

In this case, a 1-unit change in contrast IS the difference between the levels' codes

Thus, the contrast correctly represents .04825 as the difference between the conditions

Page 24: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrast Estimates

ATYPICAL LOCATION

TYPICAL LOCATION

1

-1

CONTRAST CODE

}2

Here, the total difference between the levels' codes is 2

So, a 1-unit change in the contrast is only HALF the difference between the levels' codes

Thus, the estimate of the contrast is .024 … only half the difference between the conditions

Page 25: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrast Estimates

ATYPICAL LOCATION

TYPICAL LOCATION

.5

-.5

CONTRAST CODE

}1

ATYPICAL LOCATION

TYPICAL LOCATION

1

-1

CONTRAST CODE

1 unit change in contrast IS the difference between levels (.04825 in this case)

1 unit change in contrast IS only half the difference between levels

}2

Beta weight (estimate) represents the effect of a 1-unit change in the contrast

Page 26: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

So Why -.5 and .5?● Better tell you about difference in means!

– The actual difference between conditions is .048

– It would be perfectly correct to describe .024 as half the difference between levels and you could even put a CI around it … it's just less intuitive for your readers

FILLER LOCATION:[-1 1]

FILLERLOCATION:[-.5 .5]

Page 27: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

So Why -.5 and .5?● Better tell you about difference in means!

– The actual difference between conditions is .048

– It would be perfectly correct to describe .024 as half the difference between levels and you could even put a CI around it … it's just less intuitive for your readers

● Both contrasts would account for the same amount of variance

● This is just another case of deciding the scale of a variable

– Akin to measuring temperature in C versus F … both account for the same variance, but the numbers are on different scales

Page 28: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Imbalanced Designs

● You may have an unequal number of observations per cell– e.g. some data lost,

or responses notcodable

● Correct for thisin your contrast codes if you want things centered– Ask Tuan or Scott

about how to do this :)

Page 29: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Outline

● Why use contrast coding?● Example contrasts● Contrast estimates● Contrasts in R● Multiple comparisons● How does it work?● Other kinds of coding● Interactions

Page 30: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrasts in R● To check what the current contrasts are:

– contrasts(YourDataFrame$VariableName)

● To set the contrasts:– contrasts(YourDataFrame$VariableName) =

cbind(c(.33,.33,-.66),c(.50,-.50,0))

● Each c(xx,yy,zz) is the weights for one of the contrasts you want to run

● e.g. (.33, .33, -.66) is one contrast

● After setting contrasts, run lmer model to get the results of the contrasts

Page 31: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrasts in R

● Should have j – 1 contrasts, where k = # of levels of the factor

● If using a subset of data, some levels of the factor may no longer be present

– e.g. you dropped a condition

– But, R still “remembers” that these levels exist and will get mad you didn't specify enough contrasts

– Fix this by reconverting to a factor:● YourDataFrame$Variable =

factor(YourDataFrame$Variable)

Page 32: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Another R Tip

● To see the mean of each level of an I.V.:– tapply(YourDataFrame$DVName,

YourDataFrame$IVName,mean)

– Could also do median, sd, etc.

● For a 2-way (or more!) table– tapply(YourDataFrame$DVName,

list(YourDataFrame$IVName1, YourDataFrame$IVName2), mean)

● Doesn't work if you have missing values

– But Tuan has made a version of tapply that fixes this problem

Page 33: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Outline

● Why use contrast coding?● Example contrasts● Contrast estimates● Contrasts in R● Multiple comparisons● How does it work?● Other kinds of coding● Interactions

Page 34: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Multiple Comparisons(Here Comes Trouble!)

Page 35: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Multiple Comparisons

● Lots of comparisons you can run● Suppose we tested both young & older

adults on the disfluency task:

FLUENT /YOUNGER

FLUENT /OLDER

TYPICAL /YOUNGER

TYPICAL /OLDER

ATYPICAL /YOUNGER

ATYPICAL /OLDER

Page 36: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Multiple Comparisons

● Some comparisons are (wholly or partial) redundant

● Suppose we find typical > fluent, but typical and atypical don't reliably differ

● Should expect atypical > fluent (to at least some degree)

● Or, we find a main effect of age● Would expect to find an effect of age

within at least some conditions if we looked at them individually

Page 37: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Multiple Comparisons

● Some comparisons are (wholly or partial) redundant

● j – 1 contrasts actually describe everything● j = # of levels

FLUENT

MEAN OF:TypicalAtypical

.35730}TYPICAL

ATYPICAL}.04825Can calculate all

differences between levels based on this!

Page 38: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Multiple Comparisons● Want to avoid multiple comparisons

● Error rate increases if you run overlapping, redundant tests

● Suppose we have the wrong value for one of means (due to sampling error, etc.)

● In a single test, we set alpha so there is a 5% chance of incorrectly rejecting H

0 .05

Page 39: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Multiple Comparisons● But now we run a 2nd test comparing that

same “bad” condition to another condition● Outcome of this test is correlated with the

previous one since they both refer to one of the same conditions

● Not an independent 5% chance of error● Multiple tests compound Type I error rate

Page 40: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Orthogonality● Avoid this issue w/ orthogonal contrasts

– Products of weights (across contrasts) sum to 0

– Matrix of contrast is made up of orthogonal vectors

– Can think of this as the contrasts being uncorrelated with each other

Page 41: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Orthogonality● Avoid this issue w/ orthogonal contrasts

– Products of weights (across contrasts) sum to 0

.25

.25

-.5

.33

.33

-.66

.50

-.50

0

.165

-.165

0

x =

= 0

CONTRAST 1 CONTRAST 2 PRODUCT

TYPICAL

ATYPICAL

FLUENT +

x

x

Page 42: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Orthogonality● Avoid this issue w/ orthogonal contrasts

– Products of weights (across contrasts) sum to 0

.25

.25

-.5

.50

-.50

0

.50

0

-.50

.25

.0

.0

x =

= .25

CONTRAST 1 CONTRAST 2 PRODUCT

TYPICAL

ATYPICAL

FLUENT +

x

x

Page 43: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Corrections

● “But, Scott, I really want to do more than j – 1 comparisons”

● Can apply corrections to control Type I error

● Bonferroni: Multiply p value by # of comparisons

– Worst case scenario

● Less conservative corrections may be available

Page 44: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Outline

● Why use contrast coding?● Example contrasts● Contrast estimates● Contrasts in R● Multiple comparisons● How does it work?● Other kinds of coding● Interactions

Page 45: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

How Does it Work?

=LOCATION OF DISFLUENCY

SUBJECT ITEM

+ ++PRIOR

KNOWLEDGE

Behind the scenes...

Page 46: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

How Does it Work?

β2X

2 + β

3X

3 + ...Y=β

0● Each categorical factor gets coded as

j - 1 variables● j = number of levels in that factor● Number of contrasts you have

β0+ β

1X

1 +

=LOCATION OF DISFLUENCY

SUBJECT ITEM

+ ++PRIOR

KNOWLEDGE

Page 47: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

How Does it Work?

● Each coded variable represents one of your contrasts

β2X

2 + β

3X

3 + ...Y=β

0+ β

1X

1 +

.33

.33-.66

CONTRAST 1

X2 =

if typical location for disfluenciesif atypical

if fluent

Value of

contrast: β2

● Sig. difference between levelsif β differsfrom 0

Page 48: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Outline

● Why use contrast coding?● Example contrasts● Contrast estimates● Contrasts in R● Multiple comparisons● How does it work?● Other kinds of coding● Interactions

Page 49: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Other Kinds of Coding● Dummy/Treatment

Coding– Compare all levels to a

baseline level

– Doesn't allow direct comparisons between non-baseline levels

– R does this by default :(

100

010

TypicalAtypicalFluent

X2X2 X3

Page 50: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Other Kinds of Coding● Dummy/Treatment Coding

– Compare all levels to a baseline level

– Doesn't allow comparisons between levels

– R does this by default :(

● Sum/Effects Coding– Test whether each level

differs from overall mean or from chance

Page 51: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Outline

● Why use contrast coding?● Example contrasts● Contrast estimates● Contrasts in R● Multiple comparisons● How does it work?● Other kinds of coding● Interactions

Page 52: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Contrasts & Interactions

● Contrasts also apply in cases where we have interactions between variables

● Interaction term represents whether the value of the contrast depends on another variable

● We'll see some examples on the next slides

Page 53: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Interaction Example● Suppose we also sampled different age

groups in the disfluency experiment– 3 x 2 design

● What are possible patterns of results?

Fluent,young

Typical disfluencies,young

Atypical disfluencies,young

Fluent,older

Typical disfluencies,older

Atypical disfluencies,older

YOUNGADULTS

OLDER ADULTS

Gro

up

FLUENT TYPICAL ATYPICAL

Story Type

Page 54: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Possible Result 1

● Contrast 1 significant– Effect of disfluencies

● Contrast 2 non-sig.– Location irrelevant

● No effect of age at all in this case

– Everything the same for both age groups

YO

UN

GO

LD

ER

Before Plot Point After Plot Point Rest of Story

0

1

2

3

4

5

6

7

8

9

Before Plot Point After Plot Point Rest of Story

0

1

2

3

4

5

6

7

8

9

CONTRAST 1

CONTRAST 2 no

AGE no

CONTRAST 1 yes

C1 x AGE no

C2 x AGE no

SIGNIFICANT?

Page 55: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Possible Result 2

● Contrast 2 is now significant

– Typical > atypical

● Still no effect of AGE

CONTRAST 1

CONTRAST 2 yes

AGE no

CONTRAST 1 yes

C1 x AGE no

C2 x AGE no

SIGNIFICANT?

Before Plot Point After Plot Point Rest of Story

0

1

2

3

4

5

6

7

8

9

Before Plot Point After Plot Point Rest of Story

0

1

2

3

4

5

6

7

8

9

YO

UN

GO

LD

ER

Page 56: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Possible Result 3

● Now, AGE effect– Older adults remember

more across the board

● But, no interaction– Disfluency effect is the

same under both load conditions

CONTRAST 1

CONTRAST 2 yes

AGE yes

CONTRAST 1 yes

C1 x AGE no

C2 x AGE no

SIGNIFICANT?

Before Plot Point After Plot Point Rest of Story

0

1

2

3

4

5

6

7

8

9

Before Plot Point After Plot Point Rest of Story

0

1

2

3

4

5

6

7

8

9

YO

UN

GO

LD

ER

Page 57: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Possible Result 4

● Contrast 1 interacts with AGE

– Presence of disfluencies differs across age

● Effect only foryoung adults

● Contrast 2 (location) still same in all cases

CONTRAST 1

CONTRAST 2 yes

AGE yes

CONTRAST 1 yes

C1 x AGE yes

C2 x AGE no

SIGNIFICANT?

Before Plot Point After Plot Point Rest of Story

0

1

2

3

4

5

6

7

8

9

Before Plot Point After Plot Point Rest of Story

0

1

2

3

4

5

6

7

8

9

YO

UN

GO

LD

ER

Page 58: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Possible Result 5

● Now, Contrast 2 also interacts with AGE

– Reversal of Typical vs Atypical effect across age

CONTRAST 1

CONTRAST 2 yes

AGE yes

CONTRAST 1 yes

C1 x AGE yes

C2 x AGE yes

SIGNIFICANT?

Before Plot Point After Plot Point Rest of Story

0

1

2

3

4

5

6

7

8

9

Before Plot Point After Plot Point Rest of Story

0

1

2

3

4

5

6

7

8

9

YO

UN

GO

LD

ER

Page 59: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Possible Result 6

● Contrast 2 interaction but not Contrast 1

– Typical vs Atypical comparison does depend on age

– Overall effect of having fillers does not

CONTRAST 1

CONTRAST 2 yes

AGE yes

CONTRAST 1 yes

C1 x AGE no

C2 x AGE yes

SIGNIFICANT?

Before Plot Point After Plot Point Rest of Story

0

1

2

3

4

5

6

7

8

9

Before Plot Point After Plot Point Rest of Story

0

1

2

3

4

5

6

7

8

9

YO

UN

GO

LD

ER

Page 60: Contrast Coding - Learning Research and Development CenterContrast Coding Contrasts: Test differences between specific levels – Same as a planned comparison in an ANOVA – Also

Interactions in R● Implementing interactions in an R model

formula (lmer or otherwise):– A + B

● Main effects of A and B, no interaction– A * B

● All possible interactions and main effects of A and B

– A : B

● Interaction of A and B, no main effect (unless you add it separately)

● In, say, a corpus analysis with 20 predictors, you wouldn't want to test a 20-way interaction … but this lets you control what to include