Psychology 412 - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Psychology 412

Description:

We can make as many comparisons as we have degrees of freedom ... Solution: Compare groups to each other by pitting ... Comparing two groups of variable levels ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 32
Provided by: adamk2
Category:

less

Transcript and Presenter's Notes

Title: Psychology 412


1
Psychology 412
  • Instructor Adam Kramer
  • Week 6

2
Reprisal
  • Midterm due tomorrow 9am
  • Ask for meeting extension if necessary
  • Today Contrast coding
  • Next week Interactions
  • Multiple variables, continuous categorical
  • Beyond Nested or repeated-measures or
    within-subjects designs

3
Review
  • Multiple regression is great
  • Estimates indicate the effect of a one-point
    increase when other variables equal zero
  • Allows us to partial out confounds
  • Allows for dummy coding to compare groups to a
    baseline

4
Beyond baselines
  • Choosing a baseline does not answer every
    possible research question
  • We can make as many comparisons as we have
    degrees of freedom
  • Because we dont want to re-use variance
  • The art
  • What a unit increase means
  • What zero means

5
Coding contrasts
  • Solution A tug of war with zero as the line
    and the categories as tuggers
  • No religion vs. General, specific, prac
  • Weight them equally so that they sum to 0
  • Three copies of no religion against one each of
    general, specific, prac. 1 1 1 3 0
  • A one unit increase means ¼ of the way from
    none to some
  • Zero means they balance out

6
Coding contrasts
  • A one-unit increase is ¼ the distance from none
    to some
  • Because its 4 steps from 1 to -3
  • So the SLOPE changes, and the error with it, so
    the SIGNIFICANCE stays the same
  • (could also code -3/4, 1/4)

7
Degrees of Freedom
  • Religiosity has four categories, thus three
    degrees of freedom
  • Three degrees of freedom means we can do three
    tests
  • Logic extends from paired t-test
  • Fewer than 3 means we have not analyzed all of
    the differences among our groups
  • More than 3 means we have OVERanalyzed the
    existing differences

8
Orthogonality
  • swl religNoneVSome
  • What else would we test?
  • We were free to choose our first contrast, but
    in the full model, contrasts control for each
    other
  • Each contrast is effectively flattened out when
    testing other variables
  • Equating none and some, now lets look at

9
Orthogonality
  • Equating none and some, now lets look at
  • any other contrast that doesnt care or isnt
    affected by whether none or some differ
  • Unrelated or orthogonal contrasts are contrasts
    that are not statistically related
  • Meaning, you cant predict a CATEGORYS level on
    one from its level on the other

10
Orthogonality illustrated
  • Our dummy codes are correlated
  • If youre basic we know youre NOT anything
    else, r-0.33
  • When we control for Specific and Practicing,
    a one-unit increase in basic compares it to the
    baseline
  • We need non-orthogonal contrasts!

11
Orthogonality illustrated
  • We need non-orthogonal contrasts!
  • but not all the time.
  • If we change c2 to be our none versus some
    test, all of the interpretations change
  • When there is no difference between none and
    some, is there a difference between none and
    basic?

12
Orthogonality illustrated
  • We need orthogonal contrasts, too!
  • If none and some differ (or if they dont),
    there might be differences in the some.
  • Compare practicing to the other somes
  • These contrasts are uncorrelated, r0.00
  • One contrast left?

13
Orthogonality illustrated
  • One contrast left
  • Only one is orthogonal to both
  • One way to be sure contrasts are orthogonal if
    they are nested, testing, in turn,
    undifferentiated groups
  • C1 didnt differentiate B, S, P
  • C2 did, but didnt differentiate B, S

14
Coding in R
  • R uses the factor type for a categorical
    variable
  • Converts strings, levels into factors
  • kreligion is a factor variable, which has a
    contrasts attribute
  • factor(kreligion) would factorize it if
    necessary
  • gt contrasts(kreligion)
  • general specific practicing
  • none 0 0 0
  • general 1 0 0
  • specific 0 1 0
  • practicing 0 0 1

15
Coding in R
  • gt contrasts(kreligion)
  • general specific practicing
  • none 0 0 0
  • general 1 0 0
  • specific 0 1 0
  • practicing 0 0 1
  • The contrasts are themselves a data matrix
  • column names (contrast names)
  • a row for each category

16
Coding in R
  • gt contrasts(kreligion)
  • NoneVSome PracVNonprac
    GeneralVSpecific
  • none 0 0
    0
  • general 1 0
    0
  • specific 0 1
    0
  • practicing 0 0
    1
  • We can rename and assign at will
  • colnames( contrasts(kreligion) ) lt-
    c(NoneVSome,PracVNonprac,GeneralVSpecific)

17
Coding in R
  • gt contrasts(kreligion)
  • NoneVSome PracVNonprac
    GeneralVSpecific
  • none 0 0
    0
  • general 1 0
    0
  • specific 0 1
    0
  • practicing 0 0
    1
  • We can rename and assign at will
  • contrasts(kreligion),1 lt- c(-3,1,1,1)
  • contrasts(kreligion),2 lt- c(0,1,1,-2)
  • contrasts(kreligion),3 lt- c(0,1,-1,0)

18
Coding in R
  • gt contrasts(kreligion)
  • NoneVSome PracVNonprac
    GeneralVSpecific
  • none -3 0
    0
  • general 1 1
    1
  • specific 1 1
    -1
  • practicing 1 -2
    0
  • lm respects this matrix

19
Contrast variables
  • gt summary(lm(swls religion, datak))
  • ...
  • Coefficients
  • Estimate Std. Error t
    value Pr(gtt)
  • (Intercept) 64.3966 1.3203
    48.774 lt2e-16
  • religionNoneVSome 0.8832 0.7049
    1.253 0.211
  • religionPracVNonprac -0.2224 1.2016
    -0.185 0.853
  • religionGeneralVSpecific -0.3885 1.7738
    -0.219 0.827
  • ---
  • Signif. codes 0 â 0.001 â 0.01 â 0.05 â 0.1 â 1
  • Residual standard error 21.28 on 269 degrees of
    freedom
  • (4 observations deleted due to missingness)
  • Multiple R-squared 0.005973, Adjusted
    R-squared -0.005113
  • F-statistic 0.5388 on 3 and 269 DF, p-value
    0.6561

20
Contrast variables
  • (Intercept) 64.3966 1.3203
    48.774 lt2e-16
  • religionNoneVSome 0.8832 0.7049
    1.253 0.211
  • religionPracVNonprac -0.2224 1.2016
    -0.185 0.853
  • religionGeneralVSpecific -0.3885 1.7738
    -0.219 0.827
  • Residual standard error 21.28 on 269 degrees of
    freedom
  • (4 observations deleted due to missingness)
  • Multiple R-squared 0.005973, Adjusted
    R-squared -0.005113
  • F-statistic 0.5388 on 3 and 269 DF, p-value
    0.6561
  • R2, intercept, model p unchanged
  • Because it is the same variable
  • Slopes change, slope ps change
  • Because we analyzed it differently

21
Polynomial Contrasts
  • Instead of none versus some, maybe our
    hypothesis is linear More religion leads to more
    SWL
  • colnames( contrasts(kreligion) )1 lt- linear
  • contrasts(kreligion),1 lt- c(-3,-1,1,3)
  • (why?)

22
Polynomial Contrasts
  • Instead of none versus some, maybe our
    hypothesis is linear More religion leads to more
    SWL
  • colnames( contrasts(kreligion) )1 lt- linear
  • contrasts(kreligion),1 lt- c(-3,-1,1,3)
  • Spaces the levels evenly and sums to zero
  • Contrast tests where the linear effect is zero

23
Polynomial Contrasts
  • contrasts(kreligion),1 lt- c(-3,-1,1,3)
  • What else? Two more are possible, but not
    necessary
  • Polynomial effects are orthogonal
  • contrasts(kreligion),2 lt- c(1,-1,-1,1)
  • colnames(contrasts(kreligion))2 lt- quad
  • contrasts(kreligion),3 lt- c(-1,3,-3,1)
  • why?

24
Polynomial Contrasts
  • Fits a line to the contrasts

25
Polynomial Contrasts
  • Why three?
  • Allows for a test of the main effect
  • summary(lm(swls religion, datak))

26
When to contrast code
  • Whenever you have groups
  • Define a set of contrasts
  • Use all your contrast codes
  • Otherwise, you are not fully analyzing the
    groups there is variance you could explain
  • Use all the group codes together test the group
    fully
  • So, the R2 for adding all groups tests the
    groupings worth

27
When to contrast code
  • What if you only have one contrast?
  • Then why did you have more groups?
  • I only care whether differences exist!
  • Choosing orthogonal contrasts haphazardly is ok
    just dont interpret them
  • R2 is the same if all contrasts are used
  • I have several controls!
  • Test the control directly

28
Contrasts vs. Dummy Coding
  • When is one good?
  • Depends on your research question
  • Contrast codes allow for random group comparison
  • But orthogonality make each subsequent contrast
    less free to define
  • Dummy coding for a single baseline

29
ANOVA
  • is its own plural
  • Is about analyzing where variance can be
    accounted for
  • E.g., by groups, instead of by means
  • Regression is the same thing
  • But its about lines through means

30
ANOVA
  • The F test for change in R2 is the F test for
    ANOVA
  • Same DF, same result, same interpretation
  • The t-test for each contrast is the explanation
    of group differences
  • Each one is a contrast in ANOVA terms
  • Tests a specific theory about groups

31
ANOVA
  • Next week
  • More than one categorical variable
  • Just make as many contrast variables for each
    variable as you need
  • Interactions
  • Does the effect of one variable depend on the
    level of another?
  • If the product of the variables is significant!
  • Interpretations
Write a Comment
User Comments (0)
About PowerShow.com