knitr::opts_knit$set(root.dir = "C:/Users/Spencer/Desktop/R Directory")
source('http://psych.colorado.edu/~jclab/R/mcSummaryLm.R')
library(lmSupport)
## Warning: package 'lmSupport' was built under R version 3.6.3
## Registered S3 methods overwritten by 'lme4':
## method from
## cooks.distance.influence.merMod car
## influence.merMod car
## dfbeta.influence.merMod car
## dfbetas.influence.merMod car
library(tinytex)
library(knitr)
opts_chunk$set(tidy.opts=list(width.cutoff=70),tidy=TRUE)
Question 5 in your last homework was the following:
Test the homogeneity of regression assumption: do we need to worry that the effects of KINDER on PEABODY vary across the cells of our 3x2 design?
In answering this question, you found that as a set the interactions of KINDER with your five contrast coded predictors was not significant (i.e., you could make the homogeneity of regression assumption).
Nevertheless, in the context of the model that includes all five KINDER interactions (Model A for testing the homogeneity of regression assumption), derive the simple KINDER slopes for two groups of children in the design:
First, we extract the relevant betas from the linear model originally used to test the homogeneity of regression assumption:
myNursery = read.csv("nursery.csv")
# Define contrast codes: nursCode: -1/2 if 'no', +1/2 if 'yes' - tests
# for main effect of nursery on PEABODY scores collegeNone: 2/3 if
# none, -1/3 if one or both - tests for significant mean difference
# between PEABODY scores of no-college kids vs. one/both-college kids
# collegeOneorTwo: -1/2 if one, +1/2 if both - tests for significant
# mean difference between PEABODY scores of one-college vs. two-college
# kids
myNursery$nursCode = -1/2 * (myNursery$NURSERY == "no") + 1/2 * (myNursery$NURSERY ==
"yes")
myNursery$collegeNone = 2/3 * (myNursery$COLLEGE == "none") - 1/3 * (myNursery$COLLEGE ==
"one") - 1/3 * (myNursery$COLLEGE == "both")
myNursery$collegeOneorTwo = 0 * (myNursery$COLLEGE == "none") + 1/2 * (myNursery$COLLEGE ==
"one") - 1/2 * (myNursery$COLLEGE == "both")
testHR_modelA = lm(myNursery$PEABODY ~ myNursery$nursCode * (myNursery$collegeNone +
myNursery$collegeOneorTwo) + myNursery$KINDER + myNursery$KINDER *
(myNursery$collegeNone + myNursery$collegeOneorTwo + myNursery$nursCode) +
myNursery$KINDER * myNursery$collegeNone * myNursery$nursCode + myNursery$KINDER *
myNursery$collegeOneorTwo * myNursery$nursCode)
mcSummary(testHR_modelA)
## Loading required package: car
## Warning: package 'car' was built under R version 3.6.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 3.6.3
## lm(formula = myNursery$PEABODY ~ myNursery$nursCode * (myNursery$collegeNone +
## myNursery$collegeOneorTwo) + myNursery$KINDER + myNursery$KINDER *
## (myNursery$collegeNone + myNursery$collegeOneorTwo + myNursery$nursCode) +
## myNursery$KINDER * myNursery$collegeNone * myNursery$nursCode +
## myNursery$KINDER * myNursery$collegeOneorTwo * myNursery$nursCode)
##
## Omnibus ANOVA
## SS df MS EtaSq F p
## Model 3649.677 11 331.789 0.818 15.502 0
## Error 813.303 38 21.403
## Corr Total 4462.980 49 91.081
##
## RMSE AdjEtaSq
## 4.626 0.765
##
## Coefficients
## Est
## (Intercept) 14.722
## myNursery$nursCode 12.901
## myNursery$collegeNone 9.247
## myNursery$collegeOneorTwo -10.239
## myNursery$KINDER 0.895
## myNursery$nursCode:myNursery$collegeNone 8.319
## myNursery$nursCode:myNursery$collegeOneorTwo -10.979
## myNursery$collegeNone:myNursery$KINDER -0.171
## myNursery$collegeOneorTwo:myNursery$KINDER 0.143
## myNursery$nursCode:myNursery$KINDER -0.135
## myNursery$nursCode:myNursery$collegeNone:myNursery$KINDER -0.139
## myNursery$nursCode:myNursery$collegeOneorTwo:myNursery$KINDER 0.102
## StErr
## (Intercept) 6.972
## myNursery$nursCode 13.944
## myNursery$collegeNone 13.664
## myNursery$collegeOneorTwo 18.285
## myNursery$KINDER 0.099
## myNursery$nursCode:myNursery$collegeNone 27.328
## myNursery$nursCode:myNursery$collegeOneorTwo 36.570
## myNursery$collegeNone:myNursery$KINDER 0.202
## myNursery$collegeOneorTwo:myNursery$KINDER 0.253
## myNursery$nursCode:myNursery$KINDER 0.199
## myNursery$nursCode:myNursery$collegeNone:myNursery$KINDER 0.404
## myNursery$nursCode:myNursery$collegeOneorTwo:myNursery$KINDER 0.506
## t
## (Intercept) 2.112
## myNursery$nursCode 0.925
## myNursery$collegeNone 0.677
## myNursery$collegeOneorTwo -0.560
## myNursery$KINDER 9.015
## myNursery$nursCode:myNursery$collegeNone 0.304
## myNursery$nursCode:myNursery$collegeOneorTwo -0.300
## myNursery$collegeNone:myNursery$KINDER -0.846
## myNursery$collegeOneorTwo:myNursery$KINDER 0.564
## myNursery$nursCode:myNursery$KINDER -0.678
## myNursery$nursCode:myNursery$collegeNone:myNursery$KINDER -0.344
## myNursery$nursCode:myNursery$collegeOneorTwo:myNursery$KINDER 0.201
## SSR(3)
## (Intercept) 95.430
## myNursery$nursCode 18.322
## myNursery$collegeNone 9.801
## myNursery$collegeOneorTwo 6.711
## myNursery$KINDER 1739.401
## myNursery$nursCode:myNursery$collegeNone 1.983
## myNursery$nursCode:myNursery$collegeOneorTwo 1.929
## myNursery$collegeNone:myNursery$KINDER 15.318
## myNursery$collegeOneorTwo:myNursery$KINDER 6.815
## myNursery$nursCode:myNursery$KINDER 9.832
## myNursery$nursCode:myNursery$collegeNone:myNursery$KINDER 2.531
## myNursery$nursCode:myNursery$collegeOneorTwo:myNursery$KINDER 0.867
## EtaSq tol
## (Intercept) 0.105 NA
## myNursery$nursCode 0.022 0.009
## myNursery$collegeNone 0.012 0.010
## myNursery$collegeOneorTwo 0.008 0.012
## myNursery$KINDER 0.681 0.574
## myNursery$nursCode:myNursery$collegeNone 0.002 0.009
## myNursery$nursCode:myNursery$collegeOneorTwo 0.002 0.009
## myNursery$collegeNone:myNursery$KINDER 0.018 0.010
## myNursery$collegeOneorTwo:myNursery$KINDER 0.008 0.012
## myNursery$nursCode:myNursery$KINDER 0.012 0.010
## myNursery$nursCode:myNursery$collegeNone:myNursery$KINDER 0.003 0.009
## myNursery$nursCode:myNursery$collegeOneorTwo:myNursery$KINDER 0.001 0.010
## CI_2.5
## (Intercept) 0.608
## myNursery$nursCode -15.326
## myNursery$collegeNone -18.415
## myNursery$collegeOneorTwo -47.254
## myNursery$KINDER 0.694
## myNursery$nursCode:myNursery$collegeNone -47.004
## myNursery$nursCode:myNursery$collegeOneorTwo -85.010
## myNursery$collegeNone:myNursery$KINDER -0.579
## myNursery$collegeOneorTwo:myNursery$KINDER -0.369
## myNursery$nursCode:myNursery$KINDER -0.536
## myNursery$nursCode:myNursery$collegeNone:myNursery$KINDER -0.956
## myNursery$nursCode:myNursery$collegeOneorTwo:myNursery$KINDER -0.922
## CI_97.5
## (Intercept) 28.835
## myNursery$nursCode 41.129
## myNursery$collegeNone 36.908
## myNursery$collegeOneorTwo 26.777
## myNursery$KINDER 1.096
## myNursery$nursCode:myNursery$collegeNone 63.642
## myNursery$nursCode:myNursery$collegeOneorTwo 63.052
## myNursery$collegeNone:myNursery$KINDER 0.238
## myNursery$collegeOneorTwo:myNursery$KINDER 0.655
## myNursery$nursCode:myNursery$KINDER 0.267
## myNursery$nursCode:myNursery$collegeNone:myNursery$KINDER 0.678
## myNursery$nursCode:myNursery$collegeOneorTwo:myNursery$KINDER 1.126
## p
## (Intercept) 0.041
## myNursery$nursCode 0.361
## myNursery$collegeNone 0.503
## myNursery$collegeOneorTwo 0.579
## myNursery$KINDER 0.000
## myNursery$nursCode:myNursery$collegeNone 0.762
## myNursery$nursCode:myNursery$collegeOneorTwo 0.766
## myNursery$collegeNone:myNursery$KINDER 0.403
## myNursery$collegeOneorTwo:myNursery$KINDER 0.576
## myNursery$nursCode:myNursery$KINDER 0.502
## myNursery$nursCode:myNursery$collegeNone:myNursery$KINDER 0.733
## myNursery$nursCode:myNursery$collegeOneorTwo:myNursery$KINDER 0.842
In general, we can derive the simple slopes for KINDER as \[ \beta_1 + \beta_2*collegeNone_i + \beta_3*CollegeOneorTwo_i + \beta_4*nursCode_i + \beta_5*collegeNone_i*nursCode_i + \beta_6*collegeOneorTwo_i*nursCode_i \]
Children with neither parent college-educated who did not go to nursery school From the beta estimates above we can compute the simple slope of KINDER with these specifications as: \[ \beta_{KINDER} = .8948 - .17(2/3) + 0 - .134(-1/2) -.138(2/3)(-1/2) + 0 \approx .8944 \]
Children with neither parent college-educated who did go to nursery school From the beta estimates above we can likewise compute the simple slope of KINDER with these specifications as: \[ \beta_{KINDER} = .8948 - .17(2/3) + 0 - .134(1/2) -.138(2/3)(1/2) + 0 \approx .6684 \]
Even though these two simple slopes are probably not significantly different from each other, make up some semi-plausible explanation for the difference in these two simple KINDER slopes.
The difference in KINDER slopes may be explained as a kind of fade-out effect of nursery school attendance. That is, KINDER score bumps from educational enrichment in nursery school may be less predictive of later success because those gains fade by the time of PEABODY assessment. In this case, nursery school acts to unsystematically raise KINDER scores, which revert back to some natural baseline reflected in PEABODY scores. Children not attending nursery school will not experience these KINDER boosts, so their KINDER results may be more reflective of their natural baseline displayed in the PEABODY tests.
To test this question one would run an ANCOVA model with a single KINDER-by-nursery interaction term and see if the interaction term is a significant predictor of PEABODY scores.
Discuss whether or not the word ‘mediation’ might be used in describing the results of the ANOVA and ANCOVA you found in the last homework. (We are not asking you to do a formal state-of-the-science test, just to evaluate the patterns in light of a mediation-style argument–this question does not require a statistical test or R code.)
The results of the ANOVA and ANCOVA tests can be interpreted in a mediation framework as registering the direct paths from independent and dependent variables with and without controls for the mediator (the ‘c’ and ‘c - prime’ paths, respectively). Here, taking nursery attendance as the IV, the nursCode ANOVA beta is the coefficient of the c path and the nursCode ANCOVA beta the c - prime path. Further, because the mediator variable KINDER was likewise included in the ANCOVA model controlling for the IV, its ANCOVA beta can be taken as the coefficient of the ‘b’ path, or the controlled effect of the mediator on the DV. Taken together, the coefficients of the c, c - prime and b paths extracted from the ANOVA/ANCOVA results allow one to compute the coefficient of the ‘a’ path, or the effect of the IV on the mediator. That is, the ANOVA/ANCOVA results permit an exact specification of all the paths in a mediation model where the IV is nursery attendance, the mediator KINDER score, and the DV PEABODY results.