Moderation

Klinkenberg

University of Amsterdam

13 nov 2022

Moderation

Moderation

In statistics and regression analysis, moderation occurs when the relationship between two variables depends on a third variable. The third variable is referred to as the moderator variable or simply the moderator. The effect of a moderating variable is characterized statistically as an interaction.

Source WIKIPEDIA

Model

Outi=b0+b1Predi+b2Modi+b3Predi×Modi+ϵi

Example

Video games are among the favourite online activities for young people: two-thirds of 5–16-year-olds have their own video games console, and 88% of boys aged 8–15 own at least one games console. Although playing violent video games can enhance visuospatial acuity, visual memory, probabilistic inference, and mental rotation, compared to games such as Tetris, these games have also been linked to increased aggression in youths Another predictor of aggression and conduct problems is callous-unemotional traits such as lack of guilt, lack of empathy, and callous use of others for personal gain.

Imagine a scientist wanted to look at the relationship between playing violent video games such as Grand Theft Auto, MadWorld and Manhunt and aggression. She gathered data from 442 youths. She measured their aggressive behaviour, callous unemotional traits, and the number of hours per week they play video games.

Source: Field 11.3.1

Simulate data

set.seed(283) ## Mooie seed :-)
predictor <-             rnorm(100, 0, 3)
moderator <- predictor + rnorm(100, 0, 3) ## multicollineariteit
error     <-             rnorm(100, 0, 3) ## error
intercept <- 5
outcome   <- intercept + .5*predictor + 
                        -.4*moderator + 
                         .4*predictor*moderator + 
                         error

Mean un centring

predictor <- predictor + 15 
moderator <- moderator + 7

data <- data.frame(predictor, moderator, outcome)
head(data) 
  predictor moderator   outcome
1  18.02061  7.746939  9.797006
2  15.60117  5.937336  8.638962
3  14.02281  6.477516  8.336367
4  16.47405  9.520816  5.396567
5  11.99709  5.404452  8.246535
6  13.00026  2.415985 11.893936

View data

 

Correlations

cor(data)
          predictor moderator   outcome
predictor 1.0000000 0.7220140 0.2151668
moderator 0.7220140 1.0000000 0.1094856
outcome   0.2151668 0.1094856 1.0000000

Scatterplots

3D plot

Take it for a spin (does not work on tablet)

1 SD planes

quantiles <- as.vector(quantile(moderator,seq(.1,.9,.1)))
sds       <- c(mean(moderator)+(sd(moderator)*c(-1,0,1)))  

Fit model

#fit2 <- lm(outcome ~ predictor + moderator)
fit <- lm(outcome ~ predictor + moderator + predictor*moderator); summary(fit)

Call:
lm(formula = outcome ~ predictor + moderator + predictor * moderator)

Residuals:
    Min      1Q  Median      3Q     Max 
-7.1725 -2.0186  0.2975  2.2995 10.0602 

Coefficients:
                    Estimate Std. Error t value Pr(>|t|)    
(Intercept)         40.70870    3.38786  12.016  < 2e-16 ***
predictor           -2.18586    0.24825  -8.805 5.47e-14 ***
moderator           -5.91087    0.42821 -13.804  < 2e-16 ***
predictor:moderator  0.37000    0.02649  13.967  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.086 on 96 degrees of freedom
Multiple R-squared:  0.6869,    Adjusted R-squared:  0.6771 
F-statistic:  70.2 on 3 and 96 DF,  p-value: < 2.2e-16

Regression equation

^Outi=b0+b1Predi+b2Modi+b3Predi×Modi

^Outi=40.71+−2.19×Predi+−5.91×Modi+0.37×Predi×Modi

regeq <- function(model, predictor, moderator) { 
    fit$coefficients[1] + 
    fit$coefficients[2]*predictor + 
    fit$coefficients[3]*moderator + 
    fit$coefficients[4]*predictor*moderator
}

x.pre <- seq(10,21,length.out=30)
y.mod <- seq( 0,16,length.out=30)

z.pre <- outer(x.pre, y.mod, FUN='regeq', model=fit)

Expected surface

Expected values

data$exp <- fit$fitted.values

Explained variance

End

Contact

  • @shklinkenberg
  • Klinkenberg
  • ln.AvU@grebneknilK.S
  • ShKlinkenberg

CC BY-NC-SA 4.0

Scientific & Statistical Reasoning

1 / 21
Moderation Klinkenberg University of Amsterdam 13 nov 2022

  1. Slides

  2. Tools

  3. Close
  • Moderation
  • Moderation
  • Moderation
  • Model
  • Example
  • Simulate data
  • Mean un centring
  • View data
  • Correlations
  • Scatterplots
  • 3D plot
  • 1 SD planes
  • {"x":{"material":{"color":"#000000","alpha":1,"lit":true,"ambient":"#000000","specular":"#FFFFFF","emission":"#000000","shininess":50,"smooth":true,"front":"filled","back":"filled","size":3,"lwd":1,"fog":true,"point_antialias":false,"line_antialias":false,"texture":null,"textype":"rgb","texmipmap":false,"texminfilter":"linear","texmagfilter":"linear","texenvmap":false,"depth_mask":true,"depth_test":"less","isTransparent":false,"polygon_offset":[0,0],"margin":"","floating":false,"tag":"","blend":["src_alpha","one_minus_src_alpha"]},"rootSubscene":7,"objects":{"13":{"id":13,"type":"points","material":{"lit":false,"size":8},"vertices":"0","colors":"1","centers":"2","ignoreExtent":false,"flags":34816},"15":{"id":15,"type":"text","material":{"lit":false,"margin":0,"floating":true,"edge":[0,1,1]},"vertices":"3","colors":"4","texts":[["predictor"]],"cex":[[1]],"adj":[[0.5,0.5,0.5]],"centers":"5","family":[["sans"]],"font":[[1]],"ignoreExtent":true,"flags":33808},"16":{"id":16,"type":"text","material":{"lit":false,"margin":1,"floating":true,"edge":[1,1,1]},"vertices":"6","colors":"7","texts":[["moderator"]],"cex":[[1]],"adj":[[0.5,0.5,0.5]],"centers":"8","family":[["sans"]],"font":[[1]],"ignoreExtent":true,"flags":33808},"17":{"id":17,"type":"text","material":{"lit":false,"margin":2,"floating":true,"edge":[1,1,1]},"vertices":"9","colors":"10","texts":[["outcome"]],"cex":[[1]],"adj":[[0.5,0.5,0.5]],"centers":"11","family":[["sans"]],"font":[[1]],"ignoreExtent":true,"flags":33808},"24":{"id":24,"type":"planes","material":{"alpha":0.69803923368454,"isTransparent":true},"vertices":"12","colors":"14","offsets":[[-3.68484354019165],[-7.80768585205078],[-11.9305276870728]],"centers":"15","normals":"13","ignoreExtent":true,"flags":32803},"11":{"id":11,"type":"light","vertices":[[0,0,1]],"colors":[[1,1,1,1],[1,1,1,1],[1,1,1,1]],"viewpoint":true,"finite":false},"10":{"id":10,"type":"background","material":{},"colors":"16","centers":"17","sphere":false,"fogtype":"none","fogscale":1,"flags":32768},"12":{"id":12,"type":"background","material":{"lit":false,"back":"lines"},"colors":"18","centers":"19","sphere":false,"fogtype":"none","fogscale":1,"flags":32768},"14":{"id":14,"type":"bboxdeco","material":{"front":"lines","back":"lines"},"vertices":"20","colors":"21","axes":{"mode":["pretty","pretty","pretty"],"step":[2,5,5],"nticks":[5,5,5],"marklen":[15,15,15],"expand":[1.02999997138977,1.02999997138977,1.02999997138977]},"draw_front":true,"flags":32769},"7":{"id":7,"type":"subscene","par3d":{"antialias":4,"FOV":30,"ignoreExtent":false,"listeners":7,"mouseMode":{"none":"none","left":"zAxis","right":"zoom","middle":"fov","wheel":"pull"},"observer":[0,0,93.2443389892578],"modelMatrix":[[1.83016312122345,0,0,-28.3119354248047],[0,0.398108631372452,0.670632183551788,-12.8184976577759],[0,-1.09379434585571,0.244090154767036,-87.0747222900391],[0,0,0,1]],"projMatrix":[[3.73205065727234,0,0,0],[0,3.73205065727234,0,0],[0,0,-3.86370325088501,-336.135070800781],[0,0,-1,0]],"skipRedraw":false,"userMatrix":[[1,0,0,0],[0,0.342020143325668,0.939692620785909,0],[0,-0.939692620785909,0.342020143325668,0],[0,0,0,1]],"userProjection":[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],"scale":[1.83016312122345,1.16399168968201,0.713671863079071],"viewport":{"x":0,"y":0,"width":1,"height":1},"zoom":1,"bbox":[9.45918750762939,21.4800586700439,-0.703057706356049,18.1975536346436,-1.4919501543045,29.3347587585449],"windowRect":[0,45,256,301],"family":"sans","font":1,"cex":1,"useFreeType":true,"fontname":"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rgl/fonts/FreeSans.ttf","maxClipPlanes":6,"glVersion":2.1,"activeSubscene":0},"embeddings":{"viewport":"replace","projection":"replace","model":"replace","mouse":"replace"},"objects":[12,14,13,15,16,17,24,11],"subscenes":[],"flags":36147}},"crosstalk":{"key":[],"group":[],"id":[],"options":[]},"width":960,"height":480,"buffer":{"accessors":[{"bufferView":0,"componentType":5126,"count":100,"type":"VEC3"},{"bufferView":1,"componentType":5121,"count":1,"type":"VEC4"},{"bufferView":2,"componentType":5126,"count":100,"type":"VEC3"},{"bufferView":3,"componentType":5126,"count":1,"type":"VEC3"},{"bufferView":4,"componentType":5121,"count":1,"type":"VEC4"},{"bufferView":5,"componentType":5126,"count":1,"type":"VEC3"},{"bufferView":6,"componentType":5126,"count":1,"type":"VEC3"},{"bufferView":7,"componentType":5121,"count":1,"type":"VEC4"},{"bufferView":8,"componentType":5126,"count":1,"type":"VEC3"},{"bufferView":9,"componentType":5126,"count":1,"type":"VEC3"},{"bufferView":10,"componentType":5121,"count":1,"type":"VEC4"},{"bufferView":11,"componentType":5126,"count":1,"type":"VEC3"},{"bufferView":12,"componentType":5126,"count":3,"type":"VEC3"},{"bufferView":13,"componentType":5121,"count":3,"type":"VEC3"},{"bufferView":14,"componentType":5126,"count":1,"type":"VEC4"},{"bufferView":15,"componentType":5126,"count":12,"type":"VEC3"},{"bufferView":16,"componentType":5126,"count":1,"type":"VEC4"},{"bufferView":17,"componentType":5121,"count":1,"type":"VEC3"},{"bufferView":18,"componentType":5121,"count":1,"type":"VEC4"},{"bufferView":19,"componentType":5121,"count":1,"type":"VEC3"},{"bufferView":20,"componentType":5126,"count":16,"type":"VEC3"},{"bufferView":21,"componentType":5121,"count":1,"type":"VEC4"}],"bufferViews":[{"buffer":0,"byteLength":1200,"byteOffset":0},{"buffer":0,"byteLength":4,"byteOffset":1200},{"buffer":0,"byteLength":1200,"byteOffset":1204},{"buffer":0,"byteLength":12,"byteOffset":2404},{"buffer":0,"byteLength":4,"byteOffset":2416},{"buffer":0,"byteLength":12,"byteOffset":2420},{"buffer":0,"byteLength":12,"byteOffset":2432},{"buffer":0,"byteLength":4,"byteOffset":2444},{"buffer":0,"byteLength":12,"byteOffset":2448},{"buffer":0,"byteLength":12,"byteOffset":2460},{"buffer":0,"byteLength":4,"byteOffset":2472},{"buffer":0,"byteLength":12,"byteOffset":2476},{"buffer":0,"byteLength":36,"byteOffset":2488},{"buffer":0,"byteLength":9,"byteOffset":2524},{"buffer":0,"byteLength":16,"byteOffset":2536},{"buffer":0,"byteLength":144,"byteOffset":2552},{"buffer":0,"byteLength":16,"byteOffset":2696},{"buffer":0,"byteLength":3,"byteOffset":2712},{"buffer":0,"byteLength":4,"byteOffset":2715},{"buffer":0,"byteLength":3,"byteOffset":2719},{"buffer":0,"byteLength":192,"byteOffset":2724},{"buffer":0,"byteLength":4,"byteOffset":2916}],"buffers":[{"byteLength":2920,"bytes":"NSqQQe3m90CJwBxBYJ55Qan+vUAwOQpBcl1gQdBHz0DCYQVB2cqDQURVGEGtsKxAFfQ/QUbx\nrEDO8QNBFAFQQYCfGkCQTT5B9dyoQafhO0Gfe5pBkjCUQcTBSUHV1DRBLiOVQfBDUUHUMBlB\n8EWiQSEqB0GjiDxBp3h6Qd6QukDWLyw+1yyQQQwnXUFdYBpBNkhBQQSkuz/kl0xB1OePQXJ7\nbUHiT1xB0vKCQbzAlEAbsqtAI39aQf958kBJdcc/7kk3QdUDSkAHzgdBFm6KQT1KHkGLLeRA\n2m98QcxeE0EK5PFA2Zo0QbjqwT/PxnlBjGQ0QbK/lj6LRWVBXjFtQdpRPr7l6CtB1VgXQS75\nXkCjhylBM6k/QSgQAkGQhzK/eaadQdJ4UkFekohB9dhSQVazZEAYER1BrP2FQUhZ10BFaJNA\nznWKQZfea0HSwjJBjrgZQddaYT4QqWxB30CUQWC6XUGVwz9BSyGGQT8I+kBV0wxBozw5QaCe\njkCMIPNAM9BjQWZzn0BI2MlA7kp6QSX5N0Glkuw/kLJnQR4o8UBUxiJB84JcQe1KI0Hbp9Y/\nfANWQVKmd0CXxAhBnSBKQc674kAHCqpAigVCQci/bkC4TNxAw3iRQXLqLEHe3/JA9KYwQcsu\nlkDU+ipB6zaTQTgbaUFRZYFBUVmVQTsL50BJokJA70eMQaIzCEGB6kRBYc+FQdfg/kAhcm5A\nxMGCQbhJP0ETpMxA2uN/QSOUHkHf9IJAuciAQbWlhz5Eks1AMAF6QfwBI0FlmNxAFeBtQfWh\nrUC7dclAokdcQScb+T9rlERBACuFQdNtQEHnWhxBBt9EQTcnkEDfCY5Bi7JvQe6a/EC0MQF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oiGQS7kOEHnjvhACaCJQPFv\nd0FtSPBAkfrpQIuJWUHHAAFBS4MLQERwlkEEVdFA0o8QQZZCQ0FaIp5AI8QQQWBJi0HQL/9A\n0fn9QDTeNkE/KJBAzgVrQMmlKEGX+zO/HTa4QSnXq0GYenxBKJLGQfa8l0ESiEhBiyg7QSQv\niUFzTihBwmAVQR2QYkF3MxFBrqOkv1EkkUE7YzBBBP0/QQHcXUGqjD1BtuhpQAomWEFQJKVA\nIT3APm4jkkE3wzhBeUkTQV9LqEHmiUtBRJN3QQAAwH8AAIBAAACAPwAAAAEAAMB/AACAQAAA\ngD8AAMB/AACAQAAAgD8AAAABAADAfwAAgEAAAIA/AADAfwAAgEAAAIA/AAAAAQAAwH8AAIBA\nAACAP9VYF0F61GtAOfi+v9VYF0F61GtAlq3qQSnXq0F61GtAlq3qQQABAAABAAABAAAAAAAA\nAAAAAAAAAACAP7OyMj9UdVdBe9RrQDh5mEHqyItBe9RrQLSJDEEAAMB/AADAfwAAwH8AAMB/\nAADAfwAAwH9UdVdBkNj5QDh5mEHqyItBkNj5QLSJDEEAAMB/AADAfwAAwH8AAMB/AADAfwAA\nwH9UdVdBcuM+QTh5mEHqyItBcuM+QbSJDEEAAMB/AADAfwAAwH8AAMB/AADAfwAAwH+ZmJg+\nmZiYPpmYmD4AAIA/AAAAAQEBAQAAAAAAAAAgQQAAwH8AAMB/AABAQQAAwH8AAMB/AABgQQAA\nwH8AAMB/AACAQQAAwH8AAMB/AACQQQAAwH8AAMB/AACgQQAAwH8AAMB/AADAfwAAAAAAAMB/\nAADAfwAAoEAAAMB/AADAfwAAIEEAAMB/AADAfwAAcEEAAMB/AADAfwAAwH8AAAAAAADAfwAA\nwH8AAKBAAADAfwAAwH8AACBBAADAfwAAwH8AAHBBAADAfwAAwH8AAKBBAADAfwAAwH8AAMhB\nAAAAAQ=="}]},"context":{"shiny":false,"rmarkdown":null},"vertexShader":"#line...
  • Fit model
  • Regression equation
  • Expected surface
  • Expected values
  • Explained variance
  • Slide 19
  • End
  • Contact
  • f Fullscreen
  • s Speaker View
  • o Slide Overview
  • e PDF Export Mode
  • ? Keyboard Help