class: center, middle, title-slide, inverse, no-scribble layout: false # Repeated measures and the GLM ## Professor Andy Field <div> <img style="vertical-align:middle; width:30px; height:30px" src="media/twitter_60.png"> <span style="line-height:40px;">@profandyfield</span> </div> <div> <img style="vertical-align:middle; width:60px" src="media/youtube.png"> <span style="line-height:40px;">www.youtube.com/user/ProfAndyField/</span> </div> <div> <img style="vertical-align:middle; width:30px; height:30px" src="media/ds_com_fav.png"> <span style="line-height:40px;">www.discoveringstatistics.com</span> </div> <div> <img style="vertical-align:middle; width:30px; height:30px" src="media/milton_grey_fav.png"> <span style="line-height:40px;">www.milton-the-cat.rocks</span> </div> <div> <img style="vertical-align:middle; width:30px; height:30px" src="media/discovr_fav.png"> <span style="line-height:40px;">www.discovr.rocks</span> </div> ??? h or ?: Toggle the help window j: Jump to next slide k: Jump to previous slide b: Toggle blackout mode m: Toggle mirrored mode. p: Toggle PresenterMode f: Toggle Fullscreen t: Reset presentation timer <number> + <Return>: Jump to slide <number> c: Create a clone presentation on a new window class: inverse background-image: url("media/spaceship_neon_ppt_hex.jpg") background-size: cover <style>p {font-size: 24px; font-weight: bold;}</style> --- background-image: none background-color: #000000 class: no-scribble <video width="100%" height="100%" controls id="my_video"> <source src="media/space_opening_scene.mp4" type="video/mp4"> </video> ??? --- background-image: none background-color: #000000 class: no-scribble <video width="100%" height="100%" controls id="my_video"> <source src="media/daze_intro_01.mp4" type="video/mp4"> </video> ??? **Daze**: Hora Stet, I'm so glad to see you. **Hora Stet**: Daze? Where have you been? --- background-image: none background-color: #000000 class: no-scribble <video width="100%" height="100%" controls id="my_video"> <source src="media/daze_intro_02.mp4" type="video/mp4"> </video> ??? **Daze**: On a long, dangerous, heroic mission, where I was very heroic. I have intercepted a transmission from Lazinc Durt, leader of the inane cult. It's not good news. **Hora**: What is it? --- background-image: none background-color: #000000 class: no-scribble <video width="100%" height="100%" controls id="my_video"> <source src="media/transmission_01.mp4" type="video/mp4"> </video> ??? **Daze**: Let me show you .... --- background-image: none background-color: #000000 class: no-scribble <video width="100%" height="100%" controls id="my_video"> <source src="media/daze_intro_03.mp4" type="video/mp4"> </video> ??? **Hora Stet**: Oh, that is bad .... **Daze**: Hora, how can we stop them? **Hora Stet**: We've been experimenting with training sniffer dogs to detect aliens but we need more research. Can you get me some sniffer dogs? --- background-image: none background-color: #000000 class: no-scribble <video width="100%" height="100%" controls id="my_video"> <source src="media/daze_intro_04.mp4" type="video/mp4"> </video> ??? **Daze**: We have the best spaniels in the land, but we could only find 8 of them. **Hora Stet**: Hmmm, that's not many. I'm nopt sure whjat I can do with 8 spaniels. I may need to consult a higher intelligence. --- background-image: none background-color: #000000 class: no-scribble <video width="100%" height="100%" controls id="my_video"> <source src="media/space_hippo.mp4" type="video/mp4"> </video> --- class: center  ??? We've seen this map of the process of fitting models before --- class: center  ??? Today we focus back on the model itself to look at the form of the model we're fitting. The faded stuff still applies though - we'll look at bias, robust models, and of course samples and estimation and so on. But they are the same as for other models, what is different is the form of the model we're fitting. --- .center[  ] * **Systematic variance**: created by our manipulation * **Unsystematic variance**: variance created by unknown factors ??? If we test the same puppies while sniffing humans at two points in time, we’d expect them to get similar scores (other things being equal their vocalizations shouldn't change much). A lot of unsystematic variance is removed (e.g. how much they naturally vocalise, how sensitive their nose is etc.). Like an independent design, in a repeated measures design, differences between the two conditions can be caused by one of two things: (1) the manipulation that was carried out on the participants (whether the puppies sniffed aliens or humans), or (2) other factors that we couldn’t account for (time of day, mood, excitability). The latter factor in is likely to create much less random variation in a RM design because many sources of possible variation are controlled. As such, there are always two sources of variation: Systematic variation: This variation is due to the experimenter doing something to all of the participants in one condition but not in the other condition. Unsystematic variation: This variation results from random factors that could not be controlled. Like independent designs, repeated measures designs still compare the amount of systematic variance to the amount of unsystematic variance. In other words it compares the amount of variation caused by the experiment to the amount of natural variation (created by uncontrolled variables). However, the source of the systematic variance is different (I.e. it comes from within participants rather than between). --- # Benefits of repeated measures designs * Sensitivity + Unsystematic variance is reduced + More sensitive to experimental effects * Economy + Less participants are needed + But, be careful of fatigue ??? Sensitivity The effect of our experimental manipulation is likely to be more apparent in a repeated measures design than in a between-group design because in the former unsystematic variation can be caused only by differences in the way in which someone behaves at different times. In between-group designs we have differences in innate ability contributing to the unsystematic variation. Therefore, this error variation will almost always be much larger than if the same participants had been used. When we look at the effect of our experimental manipulation, it is always against a background of ‘noise’ caused by random, uncontrollable differences between our conditions. In a repeated measures design this ‘noise’ is kept to a minimum and so the effect of the experiment is more likely to show up. This means that repeated measures designs have more power to detect effects that genuinely exist than independent designs. Economy Repeated measures designs make more efficient use of participants and so save time and money. However, although in theory you could have a participant take part in many different conditions, they do tend to get very bored and frustrated in long experiments. Therefore, it’s always worth trying to bear in mind what your participants will have to endure before designing an experiment with 250 different experimental conditions --- # Can puppies sniff out aliens? * Outcome = vocalizations during 1 min sniffing (**vocalizations**) * Predictor: type of entity being sniffed (**entity**) - Alien (not in humanoid form) - Human (control for alien vs human) - Mannequin (control for humanoid form) - Shapeshifter (alien in humanoid form) * **dog_name** indicates the name of the dog (*N* = 8) ??? Imagine a scientist wanted to look at --- # The data .center[.whitebox[
dog_name
Alien
Human
Mannequin
Shapeshifter
Mean
Variance
Milton
8
7
1
6
5.50
7.25
Woofy
9
5
2
5
5.25
6.19
Ramsey
6
2
3
8
4.75
5.69
Mr. Snifficus III
5
3
1
9
4.50
8.75
Willock
8
4
5
8
6.25
3.19
The Venerable Dr. Waggy
7
5
6
7
6.25
0.69
Lord Scenticle
10
2
7
2
5.25
11.69
Professor Nose
12
6
8
1
6.75
15.69
Mean
—
8.12
4.25
4.12
5.75
—
—
]] --- # The data in <svg style="height: 1em; top:.04em; position: relative; fill: #136CB9;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>
--- # Repeated measures and the linear model To keep things simple, imagine a design where dogs sniff only aliens or humans (e.g., two conditions) .pull-left[.eq_lrge[.ong[ $$ `\begin{aligned} \text{vocalizations}_{i} & = \hat{b}_{0} + \hat{b}_{1}\text{entity}_{i} + e_{i} \end{aligned}` $$ ]]] .pull-right[ <table> <thead> <tr> <th style="text-align:left;"> Entity sniffed </th> <th style="text-align:center;"> Dummy variable (entity) </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Alien </td> <td style="text-align:center;"> 1 </td> </tr> <tr> <td style="text-align:left;"> Human </td> <td style="text-align:center;"> 0 </td> </tr> </tbody> </table> ] </br> .warning[ <svg style="height: 1em; top:.04em; position: relative; fill: #CA3E34;" viewBox="0 0 576 512"><path d="M192,320h32V224H192Zm160,0h32V224H352ZM544,112H512a32.03165,32.03165,0,0,0-32,32v16H416V128h32a32.03165,32.03165,0,0,0,32-32V64a32.03165,32.03165,0,0,0-32-32H416a32.03165,32.03165,0,0,0-32,32H352a32.03165,32.03165,0,0,0-32,32v32H256V96a32.03165,32.03165,0,0,0-32-32H192a32.03165,32.03165,0,0,0-32-32H128A32.03165,32.03165,0,0,0,96,64V96a32.03165,32.03165,0,0,0,32,32h32v32H96V144a32.03165,32.03165,0,0,0-32-32H32A32.03165,32.03165,0,0,0,0,144V288a32.03165,32.03165,0,0,0,32,32H64v32a32.03165,32.03165,0,0,0,32,32h32v64a32.03165,32.03165,0,0,0,32,32h80a32.03165,32.03165,0,0,0,32-32V416a32.03165,32.03165,0,0,0-32-32h96a32.03165,32.03165,0,0,0-32,32v32a32.03165,32.03165,0,0,0,32,32h80a32.03165,32.03165,0,0,0,32-32V384h32a32.03165,32.03165,0,0,0,32-32V320h32a32.03165,32.03165,0,0,0,32-32V144A32.03165,32.03165,0,0,0,544,112ZM416,64h32V96H416ZM128,96V64h32V96ZM240,448H160V384h32v32h48Zm176,0H336V416h48V384h32ZM544,288H480v64H96V288H32V144H64V256H96V192h96V96h32v64H352V96h32v96h96v64h32V144h32Z"/></svg> Same participants in all conditions * Scores across conditions correlate * Violates the assumption of independent residuals (think back to the lecture on bias) ] --- # Repeated measures: hierrachical data structure .center[  ] --- # Repeated measures and the linear model Need to adjust the model to estimate this dependency .center[.ong[.eq_lrge[ $$ `\begin{aligned} \text{vocalizations}_{ij} & = \hat{\beta}_{0j} + \hat{\beta}_{1j}\text{entity}_{ij}+ e_{ij}\\ \hat{\beta}_{0j} & = \hat{\beta}_0 + \hat{u}_{0j} \\ \hat{\beta}_{1j} & = \hat{\beta}_1 + \hat{u}_{1j} \end{aligned}` $$ ]]] --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover <!-- --> .center[.ong[.eq_lrge[ $$ `\begin{aligned} \text{vocalizations}_{ij} & = (\hat{\beta}_{0} + \hat{u}_{0j})+ \hat{\beta}_{1}\text{entity}_{ij}+ e_{ij} \end{aligned}` $$ ]]] --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover <!-- --> .center[.ong[.eq_lrge[ $$ `\begin{aligned} \text{vocalizations}_{ij} & = (\hat{\beta}_{0} + \hat{u}_{0j}) + (\hat{\beta}_{1} + \hat{u}_{1j})\text{entity}_{ij}+ e_{ij} \end{aligned}` $$ ]]] --- # Repeated measures and the linear model Back to our actual design (with 4 conditions: Alien, Human, Mannequin, Shapeshifter) * **entity** would be split into 3 dummy/contrast variables * Let's just use default dummy coding <table> <thead> <tr> <th style="text-align:left;"> Entity sniffed </th> <th style="text-align:center;"> Dummy 1 (Alien vs. mannequin) </th> <th style="text-align:center;"> Dummy 2 (Shapeshifter vs. mannequin) </th> <th style="text-align:left;"> Dummy 3 (Human vs. mannequin) </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Alien </td> <td style="text-align:center;"> 1 </td> <td style="text-align:center;"> 0 </td> <td style="text-align:left;"> 0 </td> </tr> <tr> <td style="text-align:left;"> Shapeshifter </td> <td style="text-align:center;"> 0 </td> <td style="text-align:center;"> 1 </td> <td style="text-align:left;"> 0 </td> </tr> <tr> <td style="text-align:left;"> Human </td> <td style="text-align:center;"> 0 </td> <td style="text-align:center;"> 0 </td> <td style="text-align:left;"> 1 </td> </tr> <tr> <td style="text-align:left;"> Mannequin </td> <td style="text-align:center;"> 0 </td> <td style="text-align:center;"> 0 </td> <td style="text-align:left;"> 0 </td> </tr> </tbody> </table> --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover <!-- --> --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover <!-- --> .center[.ong[.eq_lrge[ $$ `\begin{aligned} \text{vocalizations}_{ij} & = \hat{\beta}_{0j} + \hat{\beta}_{1}\text{alien vs. manq}_{ij} + \hat{\beta}_{2}\text{shape vs. manq}_{ij} + \hat{\beta}_{3}\text{human vs. manq}_{ij} + e_{ij} \\ \hat{\beta}_{0j} &= \hat{\beta}_{0} + \hat{u}_{0j} \end{aligned}` $$ ]]] --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover <!-- --> .center[.ong[.eq_lrge[ $$ `\begin{aligned} \text{vocalizations}_{ij} & = \hat{\beta}_{0j} + \hat{\beta}_{1j}\text{alien vs. manq}_{ij} + \hat{\beta}_{2j}\text{shape vs. manq}_{ij} + \hat{\beta}_{3j}\text{human vs. manq}_{ij} + e_{ij} \\ \hat{\beta}_{0j} &= \hat{\beta}_{0} + \hat{u}_{0j} \\ \hat{\beta}_{1j} &= \hat{\beta}_{1} + \hat{u}_{1j} \\ \end{aligned}` $$ ]]] --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover <!-- --> .center[.ong[.eq_lrge[ $$ `\begin{aligned} \text{vocalizations}_{ij} & = \hat{\beta}_{0j} + \hat{\beta}_{1j}\text{alien vs. manq}_{ij} + \hat{\beta}_{2j}\text{shape vs. manq}_{ij} + \hat{\beta}_{3j}\text{human vs. manq}_{ij} + e_{ij} \\ \hat{\beta}_{0j} &= \hat{\beta}_{0} + \hat{u}_{0j} \\ \hat{\beta}_{1j} &= \hat{\beta}_{1} + \hat{u}_{1j} \\ \hat{\beta}_{2j} &= \hat{\beta}_{2} + \hat{u}_{2j} \\ \end{aligned}` $$ ]]] --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover <!-- --> .center[.ong[.eq_lrge[ $$ `\begin{aligned} \text{vocalizations}_{ij} & = \hat{\beta}_{0j} + \hat{\beta}_{1j}\text{alien vs. manq}_{ij} + \hat{\beta}_{2j}\text{shape vs. manq}_{ij} + \hat{\beta}_{3j}\text{human vs. manq}_{ij} + e_{ij} \\ \hat{\beta}_{0j} &= \hat{\beta}_{0} + \hat{u}_{0j} \\ \hat{\beta}_{1j} &= \hat{\beta}_{1} + \hat{u}_{1j} \\ \hat{\beta}_{2j} &= \hat{\beta}_{2} + \hat{u}_{2j} \\ \hat{\beta}_{3j} &= \hat{\beta}_{3} + \hat{u}_{3j} \\ \end{aligned}` $$ ]]] --- # Approaches to repeated measures designs Historic: Repeated measures ANOVA (RM-ANOVA) * Restricts the model in two ways * Assumes effects are equivalent across participants (the effect in participant 1 is the same as in participant 2) * Errors have compound symmetry/sphericity + CS: The correlation between scores across conditions is the same + Sphericity: differences between scores in pairs of conditions have the same variance + These restrictions may be unrealistic Multilevel modelling (MLM) approach * Fewer restrictions: doesn't require CS or sphericity * MLM can include multiple hierarchical structures (e.g., observations within people, within clinics) * MLMs can (in general) cope with missing values RM-ANOVA cannot. * MLMs can be extended to categorical outcomes, RM-ANOVA cannot. * Contrast coding is possible --- # Fitting the model .pull-left[ * Use `lme4::lme()` or `nlme::lme()` + A trickier but more flexible option + Manually set contrasts + Can get parameter estimates, diagnostic plots, and robust methods ] -- .pull-right[ * The `afex::aov_4()` function + Specify the repeated measures with `(rm_predictors|id_var)` + Automatically sets contrasts + Built in interaction plot with `afex_plot()` + But ... no parameter estimates, diagnostic plots, or robust methods + See other lecture ] --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover # Contrasts If the dog training has been successful then we'd expect sniffer dogs to make more vocalizations when sniffing alien entities than non alien-entities. * **Contrast 1**: {alien, shapeshifter} vs. {human, mannequin} We have two 'chunks' in contrast 1 that would then need to be decomposed: * **Contrast 2**: {alien} vs. {shapeshifter} * **Contrast 3**: {human} vs. {mannequin} Using the rules for contrast coding we'd get the codes in Table 4: .center[ <table> <caption>Table 4: Contrast coding for the entity variable</caption> <thead> <tr> <th style="text-align:left;"> Group </th> <th style="text-align:left;"> Contrast 1 </th> <th style="text-align:left;"> Contrast 2 </th> <th style="text-align:left;"> Contrast 3 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Alien </td> <td style="text-align:left;"> 1/2 </td> <td style="text-align:left;"> 1/2 </td> <td style="text-align:left;"> 0 </td> </tr> <tr> <td style="text-align:left;"> Human </td> <td style="text-align:left;"> -1/2 </td> <td style="text-align:left;"> 0 </td> <td style="text-align:left;"> 1/2 </td> </tr> <tr> <td style="text-align:left;"> Mannequin </td> <td style="text-align:left;"> -1/2 </td> <td style="text-align:left;"> 0 </td> <td style="text-align:left;"> -1/2 </td> </tr> <tr> <td style="text-align:left;"> Shapeshifter </td> <td style="text-align:left;"> 1/2 </td> <td style="text-align:left;"> -1/2 </td> <td style="text-align:left;"> 0 </td> </tr> </tbody> </table> ] --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover # Fitting the model ```r aliens_vs_non = c(1/2, -1/2, -1/2, 1/2) alien_vs_shape = c(1/2, 0, 0, -1/2) human_vs_manquin = c(0, 1/2, -1/2, 0) contrasts(sniff_tib$entity) <- cbind(aliens_vs_non, alien_vs_shape, human_vs_manquin) sniff_ri <- nlme::lme( * vocalizations ~ 1, * random = ~1|dog_name, # data = sniff_tib ) sniff_ent <- nlme::lme( * vocalizations ~ entity, # random = ~1|dog_name, data = sniff_tib ) sniff_rs <- nlme::lme( vocalizations ~ entity, * random = ~entity|dog_name, # data = sniff_tib) ``` --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover # The model ```r anova(sniff_ent) ``` <table> <thead> <tr> <th style="text-align:left;"> Effect </th> <th style="text-align:right;"> numDF </th> <th style="text-align:right;"> denDF </th> <th style="text-align:right;"> F-value </th> <th style="text-align:right;"> p-value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> (Intercept) </td> <td style="text-align:right;"> 1 </td> <td style="text-align:right;"> 21 </td> <td style="text-align:right;"> 162.36 </td> <td style="text-align:right;"> 0.00 </td> </tr> <tr> <td style="text-align:left;"> entity </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 21 </td> <td style="text-align:right;"> 4.54 </td> <td style="text-align:right;"> 0.01 </td> </tr> </tbody> </table> </br> .infobox[
The entity sniffed had a significant effect on the number of vocalizations by sniffer dogs, *F*(3, 21) = 4.54, *p* = 0.01. ] ??? --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover # Contrasts ```r broom.mixed::tidy(sniff_ent, effects = "fixed") ``` </br> .whitebox[ <table> <thead> <tr> <th style="text-align:left;"> effect </th> <th style="text-align:left;"> term </th> <th style="text-align:right;"> estimate </th> <th style="text-align:right;"> std.error </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> statistic </th> <th style="text-align:right;"> p.value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> (Intercept) </td> <td style="text-align:right;"> 5.563 </td> <td style="text-align:right;"> 0.437 </td> <td style="text-align:right;"> 21 </td> <td style="text-align:right;"> 12.742 </td> <td style="text-align:right;"> 0.000 </td> </tr> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityaliens_vs_non </td> <td style="text-align:right;"> 2.750 </td> <td style="text-align:right;"> 0.873 </td> <td style="text-align:right;"> 21 </td> <td style="text-align:right;"> 3.150 </td> <td style="text-align:right;"> 0.005 </td> </tr> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityalien_vs_shape </td> <td style="text-align:right;"> 2.375 </td> <td style="text-align:right;"> 1.235 </td> <td style="text-align:right;"> 21 </td> <td style="text-align:right;"> 1.924 </td> <td style="text-align:right;"> 0.068 </td> </tr> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityhuman_vs_manquin </td> <td style="text-align:right;"> 0.125 </td> <td style="text-align:right;"> 1.235 </td> <td style="text-align:right;"> 21 </td> <td style="text-align:right;"> 0.101 </td> <td style="text-align:right;"> 0.920 </td> </tr> </tbody> </table> ] --- class: center # Interpretation <!-- --> --- background-image: url("media/daze_mid_still.jpg") background-size: cover class: no-scribble <audio> <source src="media/spaceship_interior.mp3" type="audio/mpeg"> <source src="media/spaceship_interior.ogg" type="audio/ogg"/> </audio> ??? **Hora**: Daze, you're back. Good news. The sniffer dogs did well - it looks like the training worked:the dogs make significantly more vocalisations to aliens and shapeshifters than they do for the mannequins. I'm optimistic. --- background-image: none background-color: #000000 class: no-scribble <video width="100%" height="100%" controls id="my_video"> <source src="media/daze_middle_01.mp4" type="video/mp4"> </video> ??? **Daze**: We have intercepted another transmission. **Hora**: Oh no, show me. --- background-image: none background-color: #000000 class: no-scribble <video width="100%" height="100%" controls id="my_video"> <source src="media/transmission_02_lme.mp4" type="video/mp4"> </video> ??? --- background-image: none background-color: #000000 class: no-scribble <video width="100%" height="100%" controls id="my_video"> <source src="media/daze_middle_02.mp4" type="video/mp4"> </video> ??? **Daze**: I told you, not good news ... they don't like dogs! What kind of evil creatures are we dealing with? **Hora**: Masking with scents? Interesting. Let's do some more research. --- class: center, middle, title-slide, inverse layout: false ## Scenting a victory ... factorial repeated measures designs --- # Can scents distract the sniffer dogs? .pull-left[ * 50 sniffer dogs + Participated in all conditions + Sniffed 9 different 'things' * Predictor: **entity** + **Human**: the dog sniffs a human + **Shapeshifter** the dog sniffs an alien in humanoid form + **Alien** the dog sniffs an alien in lizard form * Predictor: **scent_mask** + The entity had no masking scent (**none**) + The entity was smeared with **human** pheromones + The entity was smeared with **fox** pheromones * Outcome: + Number of vocalizations during each 1 minute sniff ] .pull-right[ .center[  ] ] --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover # The model * Let's simplify things by ignoring the fact that **entity** and **scent_mask** will be represented by two dummy variables each (and the interaction by 4!) * We can model individual differences in all parameters .center[.eq_lrge[.ong[ $$ `\begin{aligned} \text{vocalizations}_{ij} & = \hat{b}_{0j} + \hat{b}_{1j}\text{entity}_{ij} + \hat{b}_{2j}\text{scent}_{ij} + \hat{b}_{3j}(\text{entity}_{ij}\times\text{scent}_{ij}) + e_{ij}\\ \hat{b}_{0j} & = \hat{b}_0 + \hat{u}_{0j} \\ \hat{b}_{1j} & = \hat{b}_1 + \hat{u}_{1j} \\ \hat{b}_{2j} & = \hat{b}_2 + \hat{u}_{2j} \\ \hat{b}_{3j} & = \hat{b}_3 + \hat{u}_{3j} \\ \end{aligned}` $$ ]]] * This model will be too complex to fit * The simplest version of the repeated measures model instead treats the effects of predictor variables as fixed, but acknowledges that dogs, overall, will vary in their vocalizations: .center[.eq_lrge[.ong[ $$ `\begin{aligned} \text{vocalizations}_{ij} & = \hat{b}_{0j} + \hat{b}_{1}\text{entity}_{ij} + \hat{b}_{2}\text{scent}_{ij} + \hat{b}_{3}(\text{entity}_{ij}\times\text{scent}_{ij}) + e_{ij}\\ \hat{b}_{0j} & = \hat{b}_0 + \hat{u}_{0j} \\ \end{aligned}` $$ ]]] --- class: center background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover # The data
--- class: center # The data <!-- --> --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover # Contrasts We have a natural control group for the entity (human) so a natural contrast is to use dummy coding. * **Contrast 1**: {alien} vs. {human} * **Contrast 2**: {shapeshifter} vs. {human} We have a natural control group for the scent masks (no scent) so a natural contrast is to use dummy coding. * **Contrast 1**: {human} vs. {none} * **Contrast 2**: {fox} vs. {none} --- # Specifying contrasts The level order of the variables is: ```r levels(scent_tib$entity) ``` ``` ## [1] "Human" "Shapeshifter" "Alien" ``` ```r levels(scent_tib$scent_mask) ``` ``` ## [1] "None" "Human" "Fox" ``` We can do nothing (default dummy coding will do the above) or set up contrasts explicitly with: ```r contrasts(scent_tib$entity) <- contr.treatment(3, base = 1) contrasts(scent_tib$scent_mask) <- contr.treatment(3, base = 1) ``` --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover # Building models ```r scent_base <- nlme::lme( * vocalizations ~ 1, # random = ~1|dog_id, data = scent_tib ) scent_ent <- nlme::lme( * vocalizations ~ entity, # random = ~1|dog_id, data = scent_tib ) scent_scent <- nlme::lme( * vocalizations ~ entity + scent_mask, # random = ~1|dog_id, data = scent_tib ) scent_int <- nlme::lme( * vocalizations ~ entity + scent_mask + entity:scent_mask, # random = ~1|dog_id, data = scent_tib ) ``` --- ```r anova(scent_base, scent_ent, scent_scent, scent_int) ``` .whitebox[ <table> <thead> <tr> <th style="text-align:left;"> Name </th> <th style="text-align:right;"> Model </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> AIC </th> <th style="text-align:right;"> BIC </th> <th style="text-align:right;"> logLik </th> <th style="text-align:left;"> Test </th> <th style="text-align:right;"> L.Ratio </th> <th style="text-align:left;"> p-value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> scent_base </td> <td style="text-align:right;"> 1 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 2428.57 </td> <td style="text-align:right;"> 2440.89 </td> <td style="text-align:right;"> -1211.29 </td> <td style="text-align:left;"> </td> <td style="text-align:right;"> NA </td> <td style="text-align:left;"> NA </td> </tr> <tr> <td style="text-align:left;"> scent_ent </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 5 </td> <td style="text-align:right;"> 2107.09 </td> <td style="text-align:right;"> 2127.60 </td> <td style="text-align:right;"> -1048.54 </td> <td style="text-align:left;"> 1 vs 2 </td> <td style="text-align:right;"> 325.48 </td> <td style="text-align:left;"> <.001 </td> </tr> <tr> <td style="text-align:left;"> scent_scent </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 2099.80 </td> <td style="text-align:right;"> 2128.48 </td> <td style="text-align:right;"> -1042.90 </td> <td style="text-align:left;"> 2 vs 3 </td> <td style="text-align:right;"> 11.29 </td> <td style="text-align:left;"> .004 </td> </tr> <tr> <td style="text-align:left;"> scent_int </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 11 </td> <td style="text-align:right;"> 1925.05 </td> <td style="text-align:right;"> 1970.03 </td> <td style="text-align:right;"> -951.53 </td> <td style="text-align:left;"> 3 vs 4 </td> <td style="text-align:right;"> 182.74 </td> <td style="text-align:left;"> <.001 </td> </tr> </tbody> </table> ] -- </br> .eq_lrge[.warning[ <svg style="height: 1em; top:.04em; position: relative; fill: #CA3E34;" viewBox="0 0 576 512"><path d="M192,320h32V224H192Zm160,0h32V224H352ZM544,112H512a32.03165,32.03165,0,0,0-32,32v16H416V128h32a32.03165,32.03165,0,0,0,32-32V64a32.03165,32.03165,0,0,0-32-32H416a32.03165,32.03165,0,0,0-32,32H352a32.03165,32.03165,0,0,0-32,32v32H256V96a32.03165,32.03165,0,0,0-32-32H192a32.03165,32.03165,0,0,0-32-32H128A32.03165,32.03165,0,0,0,96,64V96a32.03165,32.03165,0,0,0,32,32h32v32H96V144a32.03165,32.03165,0,0,0-32-32H32A32.03165,32.03165,0,0,0,0,144V288a32.03165,32.03165,0,0,0,32,32H64v32a32.03165,32.03165,0,0,0,32,32h32v64a32.03165,32.03165,0,0,0,32,32h80a32.03165,32.03165,0,0,0,32-32V416a32.03165,32.03165,0,0,0-32-32h96a32.03165,32.03165,0,0,0-32,32v32a32.03165,32.03165,0,0,0,32,32h80a32.03165,32.03165,0,0,0,32-32V384h32a32.03165,32.03165,0,0,0,32-32V320h32a32.03165,32.03165,0,0,0,32-32V144A32.03165,32.03165,0,0,0,544,112ZM416,64h32V96H416ZM128,96V64h32V96ZM240,448H160V384h32v32h48Zm176,0H336V416h48V384h32ZM544,288H480v64H96V288H32V144H64V256H96V192h96V96h32v64H352V96h32v96h96v64h32V144h32Z"/></svg> Repeat the following mantra: **"It is never sensible to interpret main effects in the presence of a significant interaction effect."** ]] --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover # Entity × scent_mask interaction .infobox[
The interaction effect suggests that the effect of entity on vocalizations was significantly moderated by what scent the entity was wearing, `\(\chi^2\)`(4) = 11.29, *p* < .001. ] .center[ <!-- --> ] --- ```r broom.mixed::tidy(scent_int, effects = "fixed") ``` </br> .whitebox[ <table> <thead> <tr> <th style="text-align:left;"> effect </th> <th style="text-align:left;"> term </th> <th style="text-align:right;"> estimate </th> <th style="text-align:right;"> std.error </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> statistic </th> <th style="text-align:right;"> p.value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> (Intercept) </td> <td style="text-align:right;"> 2.98 </td> <td style="text-align:right;"> 0.331 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> 8.993 </td> <td style="text-align:right;"> 0.000 </td> </tr> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityShapeshifter </td> <td style="text-align:right;"> 7.44 </td> <td style="text-align:right;"> 0.360 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> 20.641 </td> <td style="text-align:right;"> 0.000 </td> </tr> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityAlien </td> <td style="text-align:right;"> 9.08 </td> <td style="text-align:right;"> 0.360 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> 25.191 </td> <td style="text-align:right;"> 0.000 </td> </tr> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> scent_maskHuman </td> <td style="text-align:right;"> 1.18 </td> <td style="text-align:right;"> 0.360 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> 3.274 </td> <td style="text-align:right;"> 0.001 </td> </tr> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> scent_maskFox </td> <td style="text-align:right;"> 4.34 </td> <td style="text-align:right;"> 0.360 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> 12.041 </td> <td style="text-align:right;"> 0.000 </td> </tr> <tr> <td style="text-align:left;background-color: yellow !important;"> fixed </td> <td style="text-align:left;background-color: yellow !important;"> entityShapeshifter:scent_maskHuman </td> <td style="text-align:right;background-color: yellow !important;"> -2.82 </td> <td style="text-align:right;background-color: yellow !important;"> 0.510 </td> <td style="text-align:right;background-color: yellow !important;"> 392 </td> <td style="text-align:right;background-color: yellow !important;"> -5.532 </td> <td style="text-align:right;background-color: yellow !important;"> 0.000 </td> </tr> <tr> <td style="text-align:left;background-color: yellow !important;"> fixed </td> <td style="text-align:left;background-color: yellow !important;"> entityAlien:scent_maskHuman </td> <td style="text-align:right;background-color: yellow !important;"> -3.26 </td> <td style="text-align:right;background-color: yellow !important;"> 0.510 </td> <td style="text-align:right;background-color: yellow !important;"> 392 </td> <td style="text-align:right;background-color: yellow !important;"> -6.395 </td> <td style="text-align:right;background-color: yellow !important;"> 0.000 </td> </tr> <tr> <td style="text-align:left;background-color: yellow !important;"> fixed </td> <td style="text-align:left;background-color: yellow !important;"> entityShapeshifter:scent_maskFox </td> <td style="text-align:right;background-color: yellow !important;"> -5.92 </td> <td style="text-align:right;background-color: yellow !important;"> 0.510 </td> <td style="text-align:right;background-color: yellow !important;"> 392 </td> <td style="text-align:right;background-color: yellow !important;"> -11.614 </td> <td style="text-align:right;background-color: yellow !important;"> 0.000 </td> </tr> <tr> <td style="text-align:left;background-color: yellow !important;"> fixed </td> <td style="text-align:left;background-color: yellow !important;"> entityAlien:scent_maskFox </td> <td style="text-align:right;background-color: yellow !important;"> -7.22 </td> <td style="text-align:right;background-color: yellow !important;"> 0.510 </td> <td style="text-align:right;background-color: yellow !important;"> 392 </td> <td style="text-align:right;background-color: yellow !important;"> -14.164 </td> <td style="text-align:right;background-color: yellow !important;"> 0.000 </td> </tr> </tbody> </table> ] --- ## Entity × scent_mask interaction: parameter 1 .center[.whitebox[ <table> <thead> <tr> <th style="text-align:left;"> effect </th> <th style="text-align:left;"> term </th> <th style="text-align:right;"> estimate </th> <th style="text-align:right;"> std.error </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> statistic </th> <th style="text-align:right;"> p.value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityShapeshifter:scent_maskHuman </td> <td style="text-align:right;"> -2.82 </td> <td style="text-align:right;"> 0.51 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> -5.53 </td> <td style="text-align:right;"> 0 </td> </tr> </tbody> </table> ]] .center[ <!-- --> ] --- ## Entity × scent_mask interaction: parameter 1 .center[.whitebox[ <table> <thead> <tr> <th style="text-align:left;"> effect </th> <th style="text-align:left;"> term </th> <th style="text-align:right;"> estimate </th> <th style="text-align:right;"> std.error </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> statistic </th> <th style="text-align:right;"> p.value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityShapeshifter:scent_maskHuman </td> <td style="text-align:right;"> -2.82 </td> <td style="text-align:right;"> 0.51 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> -5.53 </td> <td style="text-align:right;"> 0 </td> </tr> </tbody> </table> ]] .center[ <!-- --> ] --- ## Entity × scent_mask interaction: parameter 2 .center[.whitebox[ <table> <thead> <tr> <th style="text-align:left;"> effect </th> <th style="text-align:left;"> term </th> <th style="text-align:right;"> estimate </th> <th style="text-align:right;"> std.error </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> statistic </th> <th style="text-align:right;"> p.value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityAlien:scent_maskHuman </td> <td style="text-align:right;"> -3.26 </td> <td style="text-align:right;"> 0.51 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> -6.4 </td> <td style="text-align:right;"> 0 </td> </tr> </tbody> </table> ]] .center[ <!-- --> ] ??? The human scent increases vocalizations to humans and although it reduces vocalizations to aliens dogs are still able to discriminate between aliens smeared with human scent and humans smeared with human scent. And aliens smeared with human scent still have a lot more vocalizations than humans with no scent. --- ## Entity × scent_mask interaction: parameter 2 .center[.whitebox[ <table> <thead> <tr> <th style="text-align:left;"> effect </th> <th style="text-align:left;"> term </th> <th style="text-align:right;"> estimate </th> <th style="text-align:right;"> std.error </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> statistic </th> <th style="text-align:right;"> p.value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityAlien:scent_maskHuman </td> <td style="text-align:right;"> -3.26 </td> <td style="text-align:right;"> 0.51 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> -6.4 </td> <td style="text-align:right;"> 0 </td> </tr> </tbody> </table> ]] .center[ <!-- --> ] ??? The human scent increases vocalizations to humans and although it reduces vocalizations to shapeshifters, dogs are still able to discriminate between shapeshifters smeared with human scent and humans smeared with human scent. And shapeshifters smeared with human scent still have a lot more vocalizations than humans with no scent. --- ## Entity × scent_mask interaction: parameter 3 .center[.whitebox[ <table> <thead> <tr> <th style="text-align:left;"> effect </th> <th style="text-align:left;"> term </th> <th style="text-align:right;"> estimate </th> <th style="text-align:right;"> std.error </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> statistic </th> <th style="text-align:right;"> p.value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityShapeshifter:scent_maskFox </td> <td style="text-align:right;"> -5.92 </td> <td style="text-align:right;"> 0.51 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> -11.61 </td> <td style="text-align:right;"> 0 </td> </tr> </tbody> </table> ]] .center[ <!-- --> ] --- ## Entity × scent_mask interaction: parameter 3 .center[.whitebox[ <table> <thead> <tr> <th style="text-align:left;"> effect </th> <th style="text-align:left;"> term </th> <th style="text-align:right;"> estimate </th> <th style="text-align:right;"> std.error </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> statistic </th> <th style="text-align:right;"> p.value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityShapeshifter:scent_maskFox </td> <td style="text-align:right;"> -5.92 </td> <td style="text-align:right;"> 0.51 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> -11.61 </td> <td style="text-align:right;"> 0 </td> </tr> </tbody> </table> ]] .center[ <!-- --> ] ??? The fox scent increases vocalizations to humans and although it reduces vocalizations to shapeshifters dogs are still able to discriminate between shapeshifters smeared with fox scent and humans smeared with fox scent. And shapeshifters smeared with fox scent still have a lot more vocalizations than humans with no scent. --- ## Entity × scent_mask interaction: parameter 4 .center[.whitebox[ <table> <thead> <tr> <th style="text-align:left;"> effect </th> <th style="text-align:left;"> term </th> <th style="text-align:right;"> estimate </th> <th style="text-align:right;"> std.error </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> statistic </th> <th style="text-align:right;"> p.value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityAlien:scent_maskFox </td> <td style="text-align:right;"> -7.22 </td> <td style="text-align:right;"> 0.51 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> -14.16 </td> <td style="text-align:right;"> 0 </td> </tr> </tbody> </table> ]] .center[ <!-- --> ] --- ## Entity × scent_mask interaction: parameter 4 .center[.whitebox[ <table> <thead> <tr> <th style="text-align:left;"> effect </th> <th style="text-align:left;"> term </th> <th style="text-align:right;"> estimate </th> <th style="text-align:right;"> std.error </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> statistic </th> <th style="text-align:right;"> p.value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> fixed </td> <td style="text-align:left;"> entityAlien:scent_maskFox </td> <td style="text-align:right;"> -7.22 </td> <td style="text-align:right;"> 0.51 </td> <td style="text-align:right;"> 392 </td> <td style="text-align:right;"> -14.16 </td> <td style="text-align:right;"> 0 </td> </tr> </tbody> </table> ]] .center[ <!-- --> ] ??? The fox scent increases vocalizations to humans and although it reduces vocalizations to aliens dogs are still able to discriminate between aliens smeared with fox scent and humans smeared with fox scent. And aliens smeared with fox scent still have a lot more vocalizations than humans with no scent. --- background-image: none background-color: #000000 class: no-scribble <video width="100%" height="100%" controls id="my_video"> <source src="media/space_closing_scene.mp4" type="video/mp4"> </video>