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> .eq_lrge[.center[There is unrest in the universe. A race of evil space lizards known as the Inane Cult are planning to take over Earth. Their leader *Lazinc Durt* is poised for the invasion. *Hora Stet*, a brave but exhausted saviour of our world is oblivious to Lazinc Durt's plans. He has spend many years protecting the Earth, but he is counting the days until he can pass his mission on and retire to a nice beach. His fearless protégé, *Daze Flich*, arrives with a message ...]] --- 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 bnaturally 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 $$ `\begin{aligned} \text{vocalizations}_{i} & = \hat{b}_{0} + \hat{b}_{1}\text{entity}_{i}+ e_{i}\\ \end{aligned}` $$ * Same participants in all conditions + Scores across conditions correlate + Violates the assumption of independent residuals (think back to the lecture on bias) * Need to adjust the model to estimate this dependency .center[.ong[.eq_lrge[ $$ `\begin{aligned} \text{vocalizations}_{ij} &= (\hat{b}_{0} + \hat{u}_{0j}) + (\hat{b}_{1j} + \hat{u}_{1j})\text{entity}_{ij}+ e_{ij}\\ \hat{u}_{0j} &\sim N(0, \sigma^2_{u_0})\\ \hat{u}_{1j} &\sim N(0, \sigma^2_{u_1})\\ \end{aligned}` $$ ]]] * Remember that **entity** would actually be split into 3 dummy/contrast variables --- # Approaches to repeated measures designs and the GLM 1. Assume **sphericity** + Estimate it + Correct for it (adjust the degrees of freedom) 2. Fit a different kind of model (a *multilevel growth model*) + Can model different kinds of dependency in errors --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover # What is sphericity, `\(\epsilon\)` ? .center[
Alien-Human
Alien-Mannequin
Alien-Shapeshifter
Human-Mannequin
Human-Shapeshifter
Mannequin-Shapeshifter
Milton
1
7
2
6
1
-5
Woofy
4
7
4
3
0
-3
Ramsey
4
3
-2
-1
-6
-5
Mr. Snifficus III
2
4
-4
2
-6
-8
Willock
4
3
0
-1
-4
-3
The Venerable Dr. Waggy
2
1
0
-1
-2
-1
Lord Scenticle
8
3
8
-5
0
5
Professor Nose
6
4
11
-2
5
7
Variance
5.27
4.29
25.70
11.55
14.29
26.55
] --- # The assumption of sphericity, `\(\epsilon\)` * What is it? + The differences between pairs of groups should have equal variances * How is it estimated? + Greenhouse-Geisser estimate, `\(\hat{\epsilon}\)` + Huynh-Feldt estimate, `\(\tilde{\epsilon}\)` + If `\(\epsilon = 1\)`, sphericity is perfect + If `\(\epsilon < 1\)`, sphericity is violated (to some degree) --- # What to do about sphericity? * (<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> can) multiply *df* by these estimates to correct for the effect of sphericity * Given that `\(\epsilon\)` quantifies the deviation from perfect sphericity, we correct the *df* by the degree to which spehercity is violated * *df* get smaller making it harder for the test statistic to be significant * Routinely apply the G-G correction and forget about sphericity --- background-image: none background-color: #000000 class: no-scribble <video width="100%" height="100%" controls id="my_video"> <source src="media/sphericity_song.mp4" type="video/mp4"> </video> --- # Fitting the model .pull-left[ * 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 ```r sniff_afx <- afex::aov_4(vocalizations ~ entity + (entity|dog_name), data = sniff_tib) ``` ] -- .pull-right[ * Use `lmer()` from the `lme4` package + A trickier option (we don't teach you it) + Manually set contrasts + Can get parameter estimates, diagnostic plots, and robust methods ] --- 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 # Overall model summary ```r sniff_afx <- afex::aov_4(vocalizations ~ entity + (entity|dog_name), data = sniff_tib) sniff_afx ``` ``` ## Anova Table (Type 3 tests) ## ## Response: vocalizations ## Effect df MSE F ges p.value ## 1 entity 1.60, 11.19 13.71 3.79 + .327 .063 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1 ## ## Sphericity correction method: GG ``` </br> .infobox[
The entity sniffed did not have a significant effect on the number of vocalizations by sniffer dogs, *F*(1.60, 11.19) = 3.79, *p* = 0.063. The effect size suggested that the entity sniffed accounted for about a third of the variance in vocalizations, `\(\eta^2_{G} = 0.33\)`. ] ??? Note we use generalized eta-squared, which is better for repeated measures designs. --- class: center # Interpretation <!-- --> --- background-image: url("media/spaceship_light_2_ppt_hex.jpg") background-size: cover # Contrasts ```r sniff_emm <- emmeans::emmeans(sniff_afx, ~entity, model = "multivariate") sniff_cons <- list( 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) ) emmeans::contrast(sniff_emm, sniff_cons) ``` </br> <table> <thead> <tr> <th style="text-align:left;"> contrast </th> <th style="text-align:right;"> estimate </th> <th style="text-align:right;"> SE </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> t.ratio </th> <th style="text-align:right;"> p.value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> aliens_vs_non </td> <td style="text-align:right;"> 2.750 </td> <td style="text-align:right;"> 0.641 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 4.291 </td> <td style="text-align:right;"> 0.004 </td> </tr> <tr> <td style="text-align:left;"> alien_vs_shape </td> <td style="text-align:right;"> 1.187 </td> <td style="text-align:right;"> 0.896 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 1.325 </td> <td style="text-align:right;"> 0.227 </td> </tr> <tr> <td style="text-align:left;"> human_vs_manquin </td> <td style="text-align:right;"> 0.062 </td> <td style="text-align:right;"> 0.601 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 0.104 </td> <td style="text-align:right;"> 0.920 </td> </tr> </tbody> </table> --- # Post hoc tests ```r pairs(sniff_emm, adjust = "holm") ``` </br> <table> <thead> <tr> <th style="text-align:left;"> contrast </th> <th style="text-align:right;"> estimate </th> <th style="text-align:right;"> SE </th> <th style="text-align:right;"> df </th> <th style="text-align:right;"> t.ratio </th> <th style="text-align:right;"> p.value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Alien - Human </td> <td style="text-align:right;"> 3.875 </td> <td style="text-align:right;"> 0.811 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 4.775 </td> <td style="text-align:right;"> 0.010 </td> </tr> <tr> <td style="text-align:left;"> Alien - Mannequin </td> <td style="text-align:right;"> 4.000 </td> <td style="text-align:right;"> 0.732 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 5.465 </td> <td style="text-align:right;"> 0.006 </td> </tr> <tr> <td style="text-align:left;"> Alien - Shapeshifter </td> <td style="text-align:right;"> 2.375 </td> <td style="text-align:right;"> 1.792 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 1.325 </td> <td style="text-align:right;"> 0.907 </td> </tr> <tr> <td style="text-align:left;"> Human - Mannequin </td> <td style="text-align:right;"> 0.125 </td> <td style="text-align:right;"> 1.202 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 0.104 </td> <td style="text-align:right;"> 0.920 </td> </tr> <tr> <td style="text-align:left;"> Human - Shapeshifter </td> <td style="text-align:right;"> -1.500 </td> <td style="text-align:right;"> 1.336 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> -1.122 </td> <td style="text-align:right;"> 0.907 </td> </tr> <tr> <td style="text-align:left;"> Mannequin - Shapeshifter </td> <td style="text-align:right;"> -1.625 </td> <td style="text-align:right;"> 1.822 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> -0.892 </td> <td style="text-align:right;"> 0.907 </td> </tr> </tbody> </table> --- # Robust models ```r WRS2::rmanova( y = sniff_tib$vocalizations, groups = sniff_tib$entity, blocks = sniff_tib$dog_name ) ``` ``` ## Call: ## WRS2::rmanova(y = sniff_tib$vocalizations, groups = sniff_tib$entity, ## blocks = sniff_tib$dog_name) ## ## Test statistic: F = 2.7528 ## Degrees of freedom 1: 2.31 ## Degrees of freedom 2: 11.55 ## p-value: 0.1002 ``` --- # Robust *post hoc* tests ```r WRS2::rmmcp( y = sniff_tib$vocalizations, groups = sniff_tib$entity, blocks = sniff_tib$dog_name ) ``` ``` ## Call: ## WRS2::rmmcp(y = sniff_tib$vocalizations, groups = sniff_tib$entity, ## blocks = sniff_tib$dog_name) ## ## psihat ci.lower ci.upper p.value p.crit sig ## Alien vs. Human 3.66667 -0.48300 7.81633 0.01360 0.01020 FALSE ## Alien vs. Mannequin 4.00000 -0.35728 8.35728 0.01172 0.00851 FALSE ## Alien vs. Shapeshifter 2.00000 -8.09920 12.09920 0.44148 0.01690 FALSE ## Human vs. Mannequin 0.00000 -5.38802 5.38802 1.00000 0.05000 FALSE ## Human vs. Shapeshifter -1.83333 -9.23266 5.56599 0.34371 0.01270 FALSE ## Mannequin vs. Shapeshifter -2.00000 -12.54827 8.54827 0.46001 0.02500 FALSE ``` --- --- 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, although the result was not significant, the sample was small and the effect sizes look strong. 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.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}_{0} + \hat{u}_{0j}) + (\hat{b}_{1j} +\hat{u}_{1j})\text{entity}_{ij} + (\hat{b}_{2j} + \hat{u}_{2j})\text{scent}_{ij} + \\ &\quad \ (\hat{b}_{3j}+\hat{u}_{3j})(\text{entity}_{ij}\times\text{scent}_{ij}) + e_{ij}\\ \hat{u}_{0j} &\sim N(0, \sigma^2_{u_0})\\ \hat{u}_{1j} &\sim N(0, \sigma^2_{u_1})\\ \hat{u}_{2j} &\sim N(0, \sigma^2_{u_2})\\ \hat{u}_{3j} &\sim N(0, \sigma^2_{u_3})\\ \end{aligned}` $$ ]]] * This model may 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{u}_{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{u}_{0j} &\sim N(0, \sigma^2_{u_0})\\ \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 # Overall model summary ```r scent_afx <- afex::aov_4(vocalizations ~ entity*scent_mask + (entity*scent_mask|dog_id), data = scent_tib) scent_afx ``` ``` ## Anova Table (Type 3 tests) ## ## Response: vocalizations ## Effect df MSE F ges p.value ## 1 entity 1.98, 96.88 4.23 315.95 *** .522 <.001 ## 2 scent_mask 1.95, 95.75 2.71 12.91 *** .027 <.001 ## 3 entity:scent_mask 3.66, 179.27 3.37 60.26 *** .235 <.001 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1 ## ## Sphericity correction method: GG ``` -- .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 # Overall model summary ``` ## Anova Table (Type 3 tests) ## ## Response: vocalizations ## Effect df MSE F ges p.value ## 1 entity 1.98, 96.88 4.23 315.95 *** .522 <.001 ## 2 scent_mask 1.95, 95.75 2.71 12.91 *** .027 <.001 ## 3 entity:scent_mask 3.66, 179.27 3.37 60.26 *** .235 <.001 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1 ## ## Sphericity correction method: GG ``` .infobox[
The interaction effect suggests that the effect of entity on vocalizations was significantly moderated by what scent the entity was wearing, *F*(3.66, 179.27) = 60.26, *p* < .001. The effect size suggested that the interaction accounted for about 24% of the variance in vocalizations not accounted for by other variables, `\(\eta^2_{G} = 0.24\)` . ] --- # Simple effects analysis ## The effect of entity within type of scent ```r emmeans::joint_tests(scent_afx, "scent_mask") ``` ``` ## scent_mask = None: ## model term df1 df2 F.ratio p.value ## entity 2 49 391.102 <.0001 ## ## scent_mask = Human: ## model term df1 df2 F.ratio p.value ## entity 2 49 133.309 <.0001 ## ## scent_mask = Fox: ## model term df1 df2 F.ratio p.value ## entity 2 49 19.099 <.0001 ``` * The effect of entity is significant for all three scents. -- * That's not a helpful finding. --- # Simple effects analysis ## The effect of scent used within entity ```r emmeans::joint_tests(scent_afx, "entity") ``` ``` ## entity = Human: ## model term df1 df2 F.ratio p.value ## scent_mask 2 49 166.937 <.0001 ## ## entity = Shapeshifter: ## model term df1 df2 F.ratio p.value ## scent_mask 2 49 10.984 0.0001 ## ## entity = Alien: ## model term df1 df2 F.ratio p.value ## scent_mask 2 49 24.969 <.0001 ``` * The effect of the type of scent worn is significant in all three entities. -- * This is also not a helpful finding! --- # Post hoc tests across an interaction <!-- --> ??? If we compare all 9 means against all other means we'll end up with 36 tests, so we might want to focus in on particular tests. For example, what are the differences between entities within each scent. This yields 9 tests (1/4 of what we'd otherwise have). --- # Post hoc tests across an interaction ```r int_emm <- emmeans::emmeans(scent_afx, ~entity|scent_mask, method = "multivariate") pairs(int_emm, adjust = "holm") ``` ``` ## scent_mask = None: ## contrast estimate SE df t.ratio p.value ## Human - Shapeshifter -7.44 0.350 49 -21.250 <.0001 ## Human - Alien -9.08 0.382 49 -23.764 <.0001 ## Shapeshifter - Alien -1.64 0.433 49 -3.787 0.0004 ## ## scent_mask = Human: ## contrast estimate SE df t.ratio p.value ## Human - Shapeshifter -4.62 0.354 49 -13.035 <.0001 ## Human - Alien -5.82 0.377 49 -15.456 <.0001 ## Shapeshifter - Alien -1.20 0.343 49 -3.500 0.0010 ## ## scent_mask = Fox: ## contrast estimate SE df t.ratio p.value ## Human - Shapeshifter -1.52 0.378 49 -4.019 0.0004 ## Human - Alien -1.86 0.318 49 -5.846 <.0001 ## Shapeshifter - Alien -0.34 0.394 49 -0.862 0.3929 ## ## P value adjustment: holm method for 3 tests ``` --- # Post hoc tests across an interaction .infobox[
When no scent is worn, mean vocalizations differ between all entities: aliens elicit significantly more vocalizations than both shapeshifters and humans, and shapeshifters elicit significantly more vocalizations than humans.
This pattern of findings is the same when a human scent is worn.
When fox scent is worn, there are still significantly more vocalizations when sniffing aliens and shapeshifters compared to humans, but the difference between shapeshifters and aliens is *not significant*.
To sum up, the scents don't distract the sniffer dogs from detecting aliens compared to humans, but confuses them when distinguishing aliens in their lizard form compared to when in humanoid form. ] --- # Diagnostic plots and robust models .center[  ] ??? You can't do them so here's a picture of a spaniel looking sad --- 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> --- # Summary * Repeated measures designs violate the assumption of independent errors * Sphericity + The degree to which the variances of differences between pairs of conditions are similar + Apply the Greenhouse-Geisser correctiona nd forget about it * Interpret *F*-statistics as you would for other models * Follow-up tests + Simple effect analysis + Selective *post hoc* tests + Contrasts (but for factorial designs goes beyond what we teach)