knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
knitr::include_graphics("pictures/medmod/1.png")
Mediation is tested through three regression models:
Four conditions of mediation:
Two solutions:
What is bootstrapping?
So, what does that do for data screening?
library(rio) master <- import("data/mediation.sav") str(master) summary(master) master <- na.omit(master)
model1 <- lm(exam ~ previous, data = master) summary(model1)
model2 <- lm(facebook ~ previous, data = master) summary(model2)
model3 <- lm(exam ~ previous + facebook, data = master) summary(model3)
If the indirect effect is larger than the error, we would conclude that the addition of the M variable changed the c path.
#aroian sobel a <- coef(model2)[2] b <- coef(model3)[3] SEa <- summary(model2)$coefficients[2,2] SEb <- summary(model3)$coefficients[3,2] zscore <- (a*b)/(sqrt((b^2*SEa^2)+(a^2*SEb^2)+(SEa^2*SEb^2))) zscore #two tailed test pnorm(abs(zscore), lower.tail = F)*2
#devtools::install_github("doomlab/MeMoBootR") library(MeMoBootR) #no missing data allowed med_results <- mediation1(y = "exam", x = "previous", m = "facebook", df = master)
head(med_results$datascreening$fulldata) med_results$datascreening$correl med_results$datascreening$linearity med_results$datascreening$normality med_results$datascreening$homogen
summary(med_results$model1) summary(med_results$model2) summary(med_results$model3)
med_results$indirect.effect med_results$z.score med_results$p.value
Last, let's get the bootstrapped results:
The indirect effect would be reported as: $0.06, 95\% CI[-0.01, 0.12]$
med_results$boot.results med_results$boot.ci med_results$diagram
The combined effect of two variables on another is known conceptually as moderation, and in statistical terms as an interaction effect.
Do violent video games make people aggressive?
IV:
knitr::include_graphics("pictures/medmod/4.png")
knitr::include_graphics("pictures/medmod/5.png")
knitr::include_graphics("pictures/medmod/6.png")
knitr::include_graphics("pictures/medmod/7.png")
Centering solves two problems:
Easiest way to center to make them useful:
Centered variables for main effects have two interpretations
For continuous variables, you "create" low, average, and high groups.
master <- import("data/moderation.sav") str(master)
Center your variables using scale()
#center the X and M variable (NOT THE DV) #when you create these use the final dataset master$zvid = scale(master$Vid_Games, scale = F) #mean center, not z score master$zcal = scale(master$CaUnTs, scale = F)
Run the model:
#run the model to see if the moderation is significant #use the z score variables! #be sure to do X*M so the graph is right modmodel <- lm(Aggression ~ zvid*zcal, data = master)
summary(modmodel)
So, how do we create groups when we have a continuous variable?
Create the low and high versions of the M variable (callousness in this example)
#create the low and high z score variables master$zcallow <- master$zcal + sd(master$zcal) #bring them up master$zcalhigh <- master$zcal - sd(master$zcal) #bring them down summary(master)
#run the models #be sure to X*M modmodellow <- lm(Aggression ~ zvid*zcallow, data = master) modmodelhigh <- lm(Aggression ~ zvid*zcalhigh, data = master)
summary(modmodellow) #low slope
summary(modmodel) #average slope
summary(modmodelhigh) #high slope
library(ggplot2) cleanup <- theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line.x = element_line(color = "black"), axis.line.y = element_line(color = "black"), legend.key = element_rect(fill = "white"), text = element_text(size = 15)) modgraph <- ggplot(master, aes(zvid, Aggression)) ##change Cal to the new moderator label ##change xlab for the new X label modgraph + xlab("Centered Video Games") + geom_point(color = "gray") + geom_abline(aes(intercept = modmodellow$coefficients[1], slope = modmodellow$coefficients[2], linetype = "-1SD Cal"), size = 1) + geom_abline(aes(intercept = modmodel$coefficients[1], slope = modmodel$coefficients[2], linetype = "Average Cal"), size = 1) + geom_abline(aes(intercept = modmodelhigh$coefficients[1], slope = modmodelhigh$coefficients[2], linetype = "+1SD Cal"), size = 1) + scale_linetype_manual(values = c("dotted", "dashed", "solid"), breaks = c("-1SD Cal", "Average Cal", "+1SD Cal"), name = "Simple Slope") + cleanup
MeMoBootR
to complete the entire processing, including data screening for us! mod_model <- moderation1(y = "Aggression", x = "Vid_Games", m = "CaUnTs", df = master)
#data screening head(mod_model$datascreening$fulldata) #mod_model$datascreening$correl #mod_model$datascreening$linearity #mod_model$datascreening$normality #mod_model$datascreening$homogen #models summary(mod_model$model1) #summary(mod_model$model1low) #summary(mod_model$model1high) mod_model$interpretation #graphs mod_model$graphslopes
In this lecture, we have covered:
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.