… here be monsters

Data Analysis for Psychology in R 3

Josiah King - josiah.king@ed.ac.uk

Psychology, PPLS

University of Edinburgh

CFA is a gateway…

stuff beyond here definitely won’t be in any assessment for DAPR3

Structural Equation Models (SEM)

SEM models generally have:

  • a structural part (relations between constructs of interest)
  • a measurement part (a model of how each construct is measured)

It all gets estimated at once!

# measurement model
Y =~ y1 + y2 + y3 + ...
X =~ x1 + x2 + x3 + ...
# regressions
Y ~ X + Z
# covariances
X ~~ Z

Why SEM?

  1. Estimate paths between constructs while explicitly modelling measurement error
    • whenever we calculate/estimate a ‘score’ (scale scores, PCA scores, factor scores), and then use that in another analysis, we are assuming it is measured without error
  2. Offers a framework for testing theories (beyond just the CFA theories of measurement).

common uses of SEM

“Nomological Net”
Do things correlate with other things we expect them to correlate with?
Good for assessing if our measure is measuring the thing we want it to measure!


# measurement model
F1 =~ y1 + y2 + y3 + ...
F2 =~ x1 + x2 + x3 + ...
F3 =~ w1 + w2 + w3 + ...
# latent variable covariances
F1 ~~ F2
F1 ~~ F3
F2 ~~ F3

common uses of SEM

Measurement Invariance
Do factor loadings differ between groups/timepoints/contexts?


model <- "F1 =~ y1 + y2 + y3 + ..."


m1 <- cfa(model, data, group = "mygroups")
m2 <- cfa(model, data, group = "mygroups", 
                 group.equal = "loadings")  
  
semTools::compareFit(m1,m2)

common uses of SEM

Mediation
How much of X -> Y is because of X -> M and M -> Y?


model <- "
  Y ~ a*M + c*X
  M ~ b*X
  indirect := a*b
  direct := c
"
sem(model, data)

⚠ mediation is almost always incredibly problematic. Many people will (possibly correctly) dismiss it altogether as useless because confounding is everywhere.

Cross-sectional observational mediation is even worse (“three correlations in a trenchcoat”1)

common uses of SEM

Latent Growth Curves
The same as lmer(Y ~ TimePoint + (1 + TimePoint | Person))


model <- "
  int =~ 1*Time1 + 1*Time2 + 1*Time3 + ...
  slope =~ 0*Time1 + 1*Time2 + 2*Time3 + ...
  int ~~ slope
"
growth(model, data)

the big big caution…

  • The idea of SEM originally is to build a model that reflects the theoretical data generating process

  • Too often, people force their data to a shape that fits with an off-the-shelf SEM structure

  • It’s far too easy to estimate SEM models and report ‘associations’ while remaining blind to the strict causal assumptions required to give those paths real-world meaning

diagrams

  • diagrams are:
    • for back of envelope thinking
    • for presenting to the reader your theory about how the data are generated
  • SEM diagrams adhere to “covariance algebra” (linear paths imply a covariance matrix)
  • diagrams more generally adhere to a system of formal logic of causality

the logic of diagrams

the logic of diagrams

the logic of diagrams

the logic of diagrams

to estimate the “effect of X on Y”, we need to isolate the flow of information from X to Y, along only the path(s) we are interested in.

  • path x←z1→y is open
  • controlling for z1 closes it
  • path x→z2→y is open
  • controlling for z2 closes it
  • path x→z3←y is closed
  • controlling for z3 opens it

most common interpretation of “effect of X on Y”: what happens to Y when X changes?

  • close the back-doors, keep causal front-doors open
  • control for z1, don’t control for z2 or z3.

the logic of diagrams

  • diagrams can help us figure out what to control for (and what not to control for)

  • can help you consider (and be transparent about) limitations

the grey area

quite often…

  1. ask a question that is at least implicitly causal

  2. do analysis, controlling for some stuff (often without clearly discussing why)

  3. report “associations”

  4. draw implicitly causal conclusions

  5. emphasise everything is just correlations so can’t make any causal conclusions, to maintain plausible deniability

the grey area

  • it’s not clear what people actually mean by “x is associated with y”

Descriptive Qs

  • “does X tend to appear with Y?”

if so, we probably don’t want to control for other things.

Causal Qs

  • “does X cause Y?”

we want to control for the things that allow us to get an unbiased estimate of what would happen to an observation’s Y value if its X value changed.

Implicitly Causal Qs

  • “does X influence Y?”
  • “does X affect Y?”
  • “does X explain Y?”
  • “does X prevent Y?”
  • “is Y due to X?”
  • “does X increase/decrease Y?”
  • “does X protect against Y?”
  • “does X improve Y?”
  • “does X make Y?”

Associational Qs

  • ????