Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Current Topics in Stats

H5 Mediation
Instructor: Stephanie Keer

Let’s say previous studies have suggested that higher grades predict higher happiness: X
(grades) → Y (happiness). (This research example is made up for illustration purposes. Please
don’t consider it a scientific statement!)

I think, however, grades are not the real reason that happiness increases. I hypothesize that
good grades boost one’s self-esteem and then high self-esteem boosts one’s happiness: X
(grades) → M (self-esteem) → Y (happiness).

PREPARE:

Make sure your Working Directory is set to where you saved the data
Make sure you have the following libraries loaded:
 psych
 skimr (optional)
 mediation
 diagram
 tidyverse
 tinytex (optional if not knitting to PDF)
Check the data structure
If you have a problem with a mediation running, make sure you call in the package using
mediation::
1. Using the dataset, meddata2.csv, read the data in and assign the dataframe to an object
named meddata
Variables:
 Grades: 0-10 grades on a math assessment, higher numbers mean better
grades.
 Self-esteem: scale from 0-10, with higher numbers indicating higher self-esteem.
 Happiness: scale from 0-10, with higher numbers indicating higher self-esteem.
 Gender: Male or Female
1
2. Get descriptive statistics using either the describe function in the psych package or the
summary function in basic R. Write up a description of the data APA style ( see template
under R and APA references tab and Homework attachments).

3. Go through the four steps for mediation analysis, ending with the causal mediation
model that brings everything together. Please number using R Markdown on your steps
so I know which step is which and interpret all of the results at each step.

a. Step 1: Make sure you assign the model for this to a name called Totaleffect.
i. Is this step necessary? If so, explain why, if not explain why.
b. Step 2: Make sure you assign this to the name fit.mediator
c. Step 3 and Step 4 are run together: Make sure you assign this to the name
fit.dv. INTERPRET THIS. Explain how you know mediation occurred.

4. Run the mediation using the mediation package (make sure you have the mediation
package installed and loaded) to get the CI’s as well as the ACME, ADE and Total
Effect.
a. Explain what ACME, ADE and Total Effect are and how they relate to the
mediation you ran in question #3c(steps 3 and 4).

5. Using the diagram package (make sure you have diagram installed and loaded) and the
code below, place the appropriate path coefficients in the diagram model below to
visualize the model with code.
a. The data is inserted where the xx’s are
b. Make sure to appropriately put * for significance as right now they are included
with the xx’s, but may not be appropriate.

data <- c(0, "'.xx*'", 0,

0, 0, 0,

"'.xx*'", "'.xx* (.xx)'", 0)

M<- matrix (nrow=3, ncol=3, byrow = TRUE, data=data)

plot<- plotmat (M, pos=c(1,2),

name= c( "self.esteem","grades", "happiness"),

box.type = "rect", box.size = 0.13, box.prop=0.5, curve=0)

6. RMD your document and include a final conclusion and write-up APA style on the model
as a whole (see template in R and APA content and in the attachment to the homework
assignment for an example).
a. Please include the F value, df, p value and adjusted R squared (you should know
which step this information for F etc. should come from!)
b. Write up the bootstrapping portion as in the APA template
c. Write up the mediator proportion as in the APA template

You might also like