class: center, middle, inverse, title-slide .title[ # LECTURE 16: repeated measures ] .subtitle[ ## FANR 6750 (Experimental design) ] .author[ ###
Fall 2023 ] --- # outline <br/> 1) Motivation <br/> -- 2) Split-plot with adjustments <br/> -- 3) MANOVA <br/> -- 4) Linear mixed-effect models --- # motivation <br/> #### Suppose we want to test the effect of diet on the early growth of chicks <br/> -- #### We assign each of 36 chicks to one of four diet treatments <br/> -- #### How should we measure the response of each chick to the treatment? --- # chick data <table> <thead> <tr> <th style="empty-cells: hide;border-bottom:hidden;" colspan="1"></th> <th style="empty-cells: hide;border-bottom:hidden;" colspan="1"></th> <th style="border-bottom:hidden;padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="10"><div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">Weight</div></th> </tr> <tr> <th style="text-align:left;"> Chick </th> <th style="text-align:left;"> Diet </th> <th style="text-align:right;"> Day 0 </th> <th style="text-align:right;"> Day 2 </th> <th style="text-align:right;"> Day 4 </th> <th style="text-align:right;"> Day 6 </th> <th style="text-align:right;"> Day 8 </th> <th style="text-align:right;"> Day 10 </th> <th style="text-align:right;"> Day 12 </th> <th style="text-align:right;"> Day 14 </th> <th style="text-align:right;"> Day 16 </th> <th style="text-align:right;"> Day 18 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> 1 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 49 </td> <td style="text-align:right;"> 56 </td> <td style="text-align:right;"> 67 </td> <td style="text-align:right;"> 74 </td> <td style="text-align:right;"> 87 </td> <td style="text-align:right;"> 102 </td> <td style="text-align:right;"> 108 </td> <td style="text-align:right;"> 136 </td> <td style="text-align:right;"> 154 </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> 1 </td> <td style="text-align:right;"> 41 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 48 </td> <td style="text-align:right;"> 60 </td> <td style="text-align:right;"> 79 </td> <td style="text-align:right;"> 106 </td> <td style="text-align:right;"> 141 </td> <td style="text-align:right;"> 164 </td> <td style="text-align:right;"> 197 </td> <td style="text-align:right;"> 199 </td> </tr> <tr> <td style="text-align:left;"> 10 </td> <td style="text-align:left;"> 2 </td> <td style="text-align:right;"> 40 </td> <td style="text-align:right;"> 50 </td> <td style="text-align:right;"> 62 </td> <td style="text-align:right;"> 86 </td> <td style="text-align:right;"> 125 </td> <td style="text-align:right;"> 163 </td> <td style="text-align:right;"> 217 </td> <td style="text-align:right;"> 240 </td> <td style="text-align:right;"> 275 </td> <td style="text-align:right;"> 307 </td> </tr> <tr> <td style="text-align:left;"> 11 </td> <td style="text-align:left;"> 2 </td> <td style="text-align:right;"> 41 </td> <td style="text-align:right;"> 55 </td> <td style="text-align:right;"> 64 </td> <td style="text-align:right;"> 77 </td> <td style="text-align:right;"> 90 </td> <td style="text-align:right;"> 95 </td> <td style="text-align:right;"> 108 </td> <td style="text-align:right;"> 111 </td> <td style="text-align:right;"> 131 </td> <td style="text-align:right;"> 148 </td> </tr> <tr> <td style="text-align:left;"> 19 </td> <td style="text-align:left;"> 3 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 53 </td> <td style="text-align:right;"> 62 </td> <td style="text-align:right;"> 73 </td> <td style="text-align:right;"> 85 </td> <td style="text-align:right;"> 102 </td> <td style="text-align:right;"> 123 </td> <td style="text-align:right;"> 138 </td> <td style="text-align:right;"> 170 </td> <td style="text-align:right;"> 204 </td> </tr> <tr> <td style="text-align:left;"> 20 </td> <td style="text-align:left;"> 3 </td> <td style="text-align:right;"> 41 </td> <td style="text-align:right;"> 49 </td> <td style="text-align:right;"> 65 </td> <td style="text-align:right;"> 82 </td> <td style="text-align:right;"> 107 </td> <td style="text-align:right;"> 129 </td> <td style="text-align:right;"> 159 </td> <td style="text-align:right;"> 179 </td> <td style="text-align:right;"> 221 </td> <td style="text-align:right;"> 263 </td> </tr> <tr> <td style="text-align:left;"> 28 </td> <td style="text-align:left;"> 4 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 49 </td> <td style="text-align:right;"> 63 </td> <td style="text-align:right;"> 84 </td> <td style="text-align:right;"> 103 </td> <td style="text-align:right;"> 126 </td> <td style="text-align:right;"> 160 </td> <td style="text-align:right;"> 174 </td> <td style="text-align:right;"> 204 </td> <td style="text-align:right;"> 234 </td> </tr> <tr> <td style="text-align:left;"> 29 </td> <td style="text-align:left;"> 4 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 55 </td> <td style="text-align:right;"> 69 </td> <td style="text-align:right;"> 96 </td> <td style="text-align:right;"> 131 </td> <td style="text-align:right;"> 157 </td> <td style="text-align:right;"> 184 </td> <td style="text-align:right;"> 188 </td> <td style="text-align:right;"> 197 </td> <td style="text-align:right;"> 198 </td> </tr> </tbody> </table> --- # chick data <img src="16_repeated_measures_files/figure-html/unnamed-chunk-2-1.png" width="504" style="display: block; margin: auto;" /> -- #### What are the experimental units? How do we handle time? --- # repeated measures designs ### General features - Whole units are called subjects -- - One or more treatments is applied to each subject -- - The response variable is measured multiple times on each subject -- - Time can be thought of as a treatment variable applied at the subunit level, but it *can't be randomly assigned* -- - We are often most interested in the interaction between treatment and time -- - In some cases, one of the treatment variables might be applied part way through the experiment. A BACI design is one example --- # examples of repeated measures designs #### To investigate the effect of three drugs, each drug is administered to 8 people, and each person's heart rate is measured every 5 minutes for 4 time intervals #### The effects of predator exclosures are assessed by monitoring prey abundance over multiple years in exclosures and control sites #### The effect of dam removal is evaluated by measuring upstream fish abundance before and after dam removal at multiple rivers --- # options for analysis #### At least three ways to analyze data from repeated measures designs 1) Split-plot model with adjusted p-values 2) Profile analysis 3) Linear mixed-effects model (LMM) with serial correlation --- class: inverse, middle, center # split-plot with adjustments --- # model `$$\Large y_{ijk} = \mu + \alpha_i + \beta_j + \alpha \beta_{ij} + \delta_{ik} + \epsilon_{ijk}$$` -- `$$i = 1, ..., a \;(treatment \;levels)$$` `$$j = 1, ..., b \;(time \; periods)$$` `$$k = 1, ..., c \;(subjects \;per \;treatment \;level)$$` -- - `\(\mu =\)` grand mean - `\(\alpha_i =\)` effect of the `\(i\)`th treatment level - `\(\beta_{j} =\)` effect of the `\(j\)`th level of time - `\(\alpha \beta_{ij} =\)` interaction effect between treatment and time - `\(\delta_{ik} =\)` subject effect - `\(\epsilon_{ijk} =\)` residual, unexplained variation --- # model `$$\Large y_{ijk} = \mu + \alpha_i + \beta_j + \alpha \beta_{ij} + \delta_{ik} + \epsilon_{ijk}$$` <br/> Because we want our inferences to apply to all subjects, `\(\delta_{ik}\)` is random: `$$\large \delta_{ik} \sim normal(0, \sigma^2_D)$$` -- If residuals are uncorrelated, we assume: `$$\large \epsilon_{ijk} \sim normal(0, \sigma^2)$$` <br/> -- **Note**: Hypothesis tests are analogous to those in the split-plot design --- # anova table <table class="table" style="font-size: 14px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:right;"> Source </th> <th style="text-align:center;"> df </th> <th style="text-align:center;"> SS </th> <th style="text-align:center;"> MS </th> <th style="text-align:center;"> F </th> </tr> </thead> <tbody> <tr> <td style="text-align:right;"> Treatment </td> <td style="text-align:center;"> \(a-1\) </td> <td style="text-align:center;"> \(SS_a\) </td> <td style="text-align:center;"> \(SS_a/(a-1)\) </td> <td style="text-align:center;"> \(MS_{a}/MS_{subject}\) </td> </tr> <tr> <td style="text-align:right;"> Error (among-subjects) </td> <td style="text-align:center;"> \(N-a\) </td> <td style="text-align:center;"> \(SS_{subject}\) </td> <td style="text-align:center;"> \(SS_{subject}/(N-a)\) </td> <td style="text-align:center;"> </td> </tr> <tr> <td style="text-align:right;"> Time </td> <td style="text-align:center;"> \(b-1\) </td> <td style="text-align:center;"> \(SS_{Time}\) </td> <td style="text-align:center;"> \(SS_{Time}/(b-1)\) </td> <td style="text-align:center;"> \(MS_{Time}/MS_{e}\) </td> </tr> <tr> <td style="text-align:right;"> Interaction </td> <td style="text-align:center;"> \((a-1)(b-1)\) </td> <td style="text-align:center;"> \(SS_{a \times time}\) </td> <td style="text-align:center;"> \(SS_{a \times time}/(a-1)(b-1)\) </td> <td style="text-align:center;"> \(MS_{a \times time}/MS_{e}\) </td> </tr> <tr> <td style="text-align:right;"> Error (within-subjects) </td> <td style="text-align:center;"> \((N-a)(b-1)\) </td> <td style="text-align:center;"> \(SS_e\) </td> <td style="text-align:center;"> \(SS_e/(N-a)(b-1)\) </td> <td style="text-align:center;"> </td> </tr> </tbody> </table> -- Note that these formulas assume *balanced* data (same number of subjects per treatment and measurements per subject) -- Also, if residuals *are* correlated (which we expect them to be. Why?), *p*-values will be wrong (too low) --- # chick data <table class="table" style="font-size: 14px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:right;"> Source </th> <th style="text-align:center;"> df </th> <th style="text-align:center;"> SS </th> <th style="text-align:center;"> MS </th> <th style="text-align:center;"> F </th> <th style="text-align:center;"> p </th> </tr> </thead> <tbody> <tr> <td style="text-align:right;"> Treatment </td> <td style="text-align:center;"> 3 </td> <td style="text-align:center;"> 31811 </td> <td style="text-align:center;"> 10604 </td> <td style="text-align:center;"> 2.70 </td> <td style="text-align:center;"> 0.062 </td> </tr> <tr> <td style="text-align:right;"> Error (among-subjects) </td> <td style="text-align:center;"> 32 </td> <td style="text-align:center;"> 125635 </td> <td style="text-align:center;"> 3926 </td> <td style="text-align:center;"> </td> <td style="text-align:center;"> </td> </tr> <tr> <td style="text-align:right;"> Time </td> <td style="text-align:center;"> 9 </td> <td style="text-align:center;"> 931818 </td> <td style="text-align:center;"> 103535 </td> <td style="text-align:center;"> 227.80 </td> <td style="text-align:center;"> <0.001 </td> </tr> <tr> <td style="text-align:right;"> Interaction </td> <td style="text-align:center;"> 27 </td> <td style="text-align:center;"> 24189 </td> <td style="text-align:center;"> 896 </td> <td style="text-align:center;"> 1.97 </td> <td style="text-align:center;"> 0.0036 </td> </tr> <tr> <td style="text-align:right;"> Error (within-subjects) </td> <td style="text-align:center;"> 288 </td> <td style="text-align:center;"> 130911 </td> <td style="text-align:center;"> 455 </td> <td style="text-align:center;"> </td> <td style="text-align:center;"> </td> </tr> </tbody> </table> -- Which effect in the above table are we primarily interested in? -- But remember, if residuals *are* correlated, *p*-values will be wrong (too low) --- # adjusting *p* -values If we use a split-plot type of ANOVA, we can deal with correlated residuals by adjusting the *p*-values -- The two common adjustment methods are called the **Greenhouse-Geisser** and the **Huynh-Feldt** methods. Estimate `\(\hat{\epsilon}\)`, the degree to which assumption of "*sphericity*" is violated ( `\(\hat{\epsilon}<1\)` indicate assumption violated) - Sphericity is equivalent to equal variances but applied to variances of the *differences* ( `\(\sigma^2_{1-2} = \sigma^2_{1-3} = \sigma^2_{2-3}\)`...) - In general, `\(\hat{\epsilon}_{H-F} > \hat{\epsilon}_{G-G}\)` -- The adjustments involve modifying the degrees-of-freedom of the *F* tests of the among-subjects factors (treatment and among-subject error) - `\(df_{adj} = (a - 1) \hat{\epsilon}\)`, `\((a - 1)(N - 1)\hat{\epsilon}\)` -- Adjustments only make the *p*-values go up, so there is no need to bother with them if your tests aren't significant under the independence assumption -- We will explore this further in lab --- # problems with split-plot analysis The split-plot ANOVA approach is relatively simple to perform in `R` and is a natural extension of concepts we have already learned. However: -- - results are not robust in the presence of severely unbalanced data -- - *p*-value adjustments apply to the main treatment, not to time or time `\(\times\)` treatment interaction -- - difficult to accomodate additional model structure (blocks, multiple random effects, etc.) --- class: inverse, middle, center # profile analysis --- # profile analysis Profile analysis is typically used to test the effects of time or the time-treatment interaction in repeated measures studies. A common application is in growth studies -- If we plot the *rate of change* between measurements, we can think of several possible outcomes: -- - If the interaction is significant, the growth curves for each treatment will not be parallel -- - If the interaction is not significant, but the time effect is, then the curves will be parallel but not flat -- - If neither time nor the interaction is significant, the curves will be flat -- These possibilities can be explored using a profile analysis. --- # profile analysis <img src="figs/profile.png" width="1061" style="display: block; margin: auto;" /> --- # profile analysis Profile analysis can be performed by analyzing the differences in the response variable over consecutive time periods <div style="border: 1px solid #ddd; padding: 0px; overflow-y: scroll; height:67%; overflow-x: scroll; width:100%; "><table class="table table-responsive table-condensed table-hover" style="font-size: 12px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="empty-cells: hide;border-bottom:hidden;position: sticky; top:0; background-color: #FFFFFF;" colspan="1"></th> <th style="empty-cells: hide;border-bottom:hidden;position: sticky; top:0; background-color: #FFFFFF;" colspan="1"></th> <th style="border-bottom:hidden;padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; position: sticky; top:0; background-color: #FFFFFF;" colspan="10"><div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">Weight</div></th> </tr> <tr> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> Chick </th> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> Diet </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Day 0 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Day 2 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Day 4 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Day 6 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Day 8 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Day 10 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Day 12 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Day 14 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Day 16 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Day 18 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> 1 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 49 </td> <td style="text-align:right;"> 56 </td> <td style="text-align:right;"> 67 </td> <td style="text-align:right;"> 74 </td> <td style="text-align:right;"> 87 </td> <td style="text-align:right;"> 102 </td> <td style="text-align:right;"> 108 </td> <td style="text-align:right;"> 136 </td> <td style="text-align:right;"> 154 </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> 1 </td> <td style="text-align:right;"> 41 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 48 </td> <td style="text-align:right;"> 60 </td> <td style="text-align:right;"> 79 </td> <td style="text-align:right;"> 106 </td> <td style="text-align:right;"> 141 </td> <td style="text-align:right;"> 164 </td> <td style="text-align:right;"> 197 </td> <td style="text-align:right;"> 199 </td> </tr> <tr> <td style="text-align:left;"> 10 </td> <td style="text-align:left;"> 2 </td> <td style="text-align:right;"> 40 </td> <td style="text-align:right;"> 50 </td> <td style="text-align:right;"> 62 </td> <td style="text-align:right;"> 86 </td> <td style="text-align:right;"> 125 </td> <td style="text-align:right;"> 163 </td> <td style="text-align:right;"> 217 </td> <td style="text-align:right;"> 240 </td> <td style="text-align:right;"> 275 </td> <td style="text-align:right;"> 307 </td> </tr> <tr> <td style="text-align:left;"> 11 </td> <td style="text-align:left;"> 2 </td> <td style="text-align:right;"> 41 </td> <td style="text-align:right;"> 55 </td> <td style="text-align:right;"> 64 </td> <td style="text-align:right;"> 77 </td> <td style="text-align:right;"> 90 </td> <td style="text-align:right;"> 95 </td> <td style="text-align:right;"> 108 </td> <td style="text-align:right;"> 111 </td> <td style="text-align:right;"> 131 </td> <td style="text-align:right;"> 148 </td> </tr> <tr> <td style="text-align:left;"> 19 </td> <td style="text-align:left;"> 3 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 53 </td> <td style="text-align:right;"> 62 </td> <td style="text-align:right;"> 73 </td> <td style="text-align:right;"> 85 </td> <td style="text-align:right;"> 102 </td> <td style="text-align:right;"> 123 </td> <td style="text-align:right;"> 138 </td> <td style="text-align:right;"> 170 </td> <td style="text-align:right;"> 204 </td> </tr> <tr> <td style="text-align:left;"> 20 </td> <td style="text-align:left;"> 3 </td> <td style="text-align:right;"> 41 </td> <td style="text-align:right;"> 49 </td> <td style="text-align:right;"> 65 </td> <td style="text-align:right;"> 82 </td> <td style="text-align:right;"> 107 </td> <td style="text-align:right;"> 129 </td> <td style="text-align:right;"> 159 </td> <td style="text-align:right;"> 179 </td> <td style="text-align:right;"> 221 </td> <td style="text-align:right;"> 263 </td> </tr> <tr> <td style="text-align:left;"> 28 </td> <td style="text-align:left;"> 4 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 49 </td> <td style="text-align:right;"> 63 </td> <td style="text-align:right;"> 84 </td> <td style="text-align:right;"> 103 </td> <td style="text-align:right;"> 126 </td> <td style="text-align:right;"> 160 </td> <td style="text-align:right;"> 174 </td> <td style="text-align:right;"> 204 </td> <td style="text-align:right;"> 234 </td> </tr> <tr> <td style="text-align:left;"> 29 </td> <td style="text-align:left;"> 4 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 55 </td> <td style="text-align:right;"> 69 </td> <td style="text-align:right;"> 96 </td> <td style="text-align:right;"> 131 </td> <td style="text-align:right;"> 157 </td> <td style="text-align:right;"> 184 </td> <td style="text-align:right;"> 188 </td> <td style="text-align:right;"> 197 </td> <td style="text-align:right;"> 198 </td> </tr> </tbody> </table></div> --- # profile analysis Profile analysis can be performed by analyzing the differences in the response variable over consecutive time periods <div style="border: 1px solid #ddd; padding: 0px; overflow-y: scroll; height:67%; overflow-x: scroll; width:100%; "><table class="table table-responsive table-condensed table-hover" style="font-size: 12px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="empty-cells: hide;border-bottom:hidden;position: sticky; top:0; background-color: #FFFFFF;" colspan="1"></th> <th style="empty-cells: hide;border-bottom:hidden;position: sticky; top:0; background-color: #FFFFFF;" colspan="1"></th> <th style="border-bottom:hidden;padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; position: sticky; top:0; background-color: #FFFFFF;" colspan="9"><div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">Weight change</div></th> </tr> <tr> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> Chick </th> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> Diet </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Int. 1 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Int. 2 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Int. 3 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Int. 4 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Int. 5 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Int. 6 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Int. 7 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Int. 8 </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Int. 9 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> 1 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 11 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 13 </td> <td style="text-align:right;"> 15 </td> <td style="text-align:right;"> 6 </td> <td style="text-align:right;"> 28 </td> <td style="text-align:right;"> 18 </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> 1 </td> <td style="text-align:right;"> 1 </td> <td style="text-align:right;"> 6 </td> <td style="text-align:right;"> 12 </td> <td style="text-align:right;"> 19 </td> <td style="text-align:right;"> 27 </td> <td style="text-align:right;"> 35 </td> <td style="text-align:right;"> 23 </td> <td style="text-align:right;"> 33 </td> <td style="text-align:right;"> 2 </td> </tr> <tr> <td style="text-align:left;"> 10 </td> <td style="text-align:left;"> 2 </td> <td style="text-align:right;"> 10 </td> <td style="text-align:right;"> 12 </td> <td style="text-align:right;"> 24 </td> <td style="text-align:right;"> 39 </td> <td style="text-align:right;"> 38 </td> <td style="text-align:right;"> 54 </td> <td style="text-align:right;"> 23 </td> <td style="text-align:right;"> 35 </td> <td style="text-align:right;"> 32 </td> </tr> <tr> <td style="text-align:left;"> 11 </td> <td style="text-align:left;"> 2 </td> <td style="text-align:right;"> 14 </td> <td style="text-align:right;"> 9 </td> <td style="text-align:right;"> 13 </td> <td style="text-align:right;"> 13 </td> <td style="text-align:right;"> 5 </td> <td style="text-align:right;"> 13 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 20 </td> <td style="text-align:right;"> 17 </td> </tr> <tr> <td style="text-align:left;"> 19 </td> <td style="text-align:left;"> 3 </td> <td style="text-align:right;"> 11 </td> <td style="text-align:right;"> 9 </td> <td style="text-align:right;"> 11 </td> <td style="text-align:right;"> 12 </td> <td style="text-align:right;"> 17 </td> <td style="text-align:right;"> 21 </td> <td style="text-align:right;"> 15 </td> <td style="text-align:right;"> 32 </td> <td style="text-align:right;"> 34 </td> </tr> <tr> <td style="text-align:left;"> 20 </td> <td style="text-align:left;"> 3 </td> <td style="text-align:right;"> 8 </td> <td style="text-align:right;"> 16 </td> <td style="text-align:right;"> 17 </td> <td style="text-align:right;"> 25 </td> <td style="text-align:right;"> 22 </td> <td style="text-align:right;"> 30 </td> <td style="text-align:right;"> 20 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 28 </td> <td style="text-align:left;"> 4 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 14 </td> <td style="text-align:right;"> 21 </td> <td style="text-align:right;"> 19 </td> <td style="text-align:right;"> 23 </td> <td style="text-align:right;"> 34 </td> <td style="text-align:right;"> 14 </td> <td style="text-align:right;"> 30 </td> <td style="text-align:right;"> 30 </td> </tr> <tr> <td style="text-align:left;"> 29 </td> <td style="text-align:left;"> 4 </td> <td style="text-align:right;"> 13 </td> <td style="text-align:right;"> 14 </td> <td style="text-align:right;"> 27 </td> <td style="text-align:right;"> 35 </td> <td style="text-align:right;"> 26 </td> <td style="text-align:right;"> 27 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 9 </td> <td style="text-align:right;"> 1 </td> </tr> </tbody> </table></div> --- # chick data <img src="16_repeated_measures_files/figure-html/unnamed-chunk-8-1.png" width="504" style="display: block; margin: auto;" /> --- # model Profile analysis is based on multivariate analysis of variance (MANOVA) -- `$$\LARGE \Delta y_{i} \sim MVN(\mu_i, \Sigma)$$` -- where - `\(\large \Delta y_i\)` is a vector with the differences in the response variable between consecutive measurements for subject *i* (e.g., `\(y_1 - y_0\)`, `\(y_2 - y_1\)`, etc.) - `\(\large \mu_i\)` is the vector of expected values for subject *i* (determined by the fixed time and treatment effects and the subject-specific random effects) - `\(\large \Sigma\)` is the variance-covariance matrix of the multivariate normal distribution. It has *T* rows and *T* columns, where *T* is the number of time periods -- If the multivariate test is significant, univariate ANOVAs `\(-\)` one for each time period `\(-\)` can be used to determine when the treatment had significant effects -- We will explore this in more detail in lab --- class: inverse, middle, center # linear mixed models --- # linear mixed models Increasingly, linear mixed models that account for autocorrelation are the preferred method to fit repeated measures data -- Linear mixed models have several advantages over the split-plot ANOVA or profile analysis methods: -- - Highly flexible (e.g., can include additional random effects and interactions) -- - Can handle unbalanced designs -- - the `nlme` package provides methods for accounted for serial autocorrelation common in repeated measures data --- # chick data .pull-left[ .vsmall-code[ ```r library(nlme) lmm2 <- lme(fixed = weight ~ Diet *Time, random = ~ (Time-1)|Chick, data = chickdata, correlation = corAR1()) summary(lmm2) ``` ] ] .pull-right[ .vsmall-code[ ``` ## Linear mixed-effects model fit by maximum likelihood ## Data: chickdata ## AIC BIC logLik ## 2715 2758 -1347 ## ## Random effects: ## Formula: ~(Time - 1) | Chick ## Time Residual ## StdDev: 2.564 15.1 ## ## Correlation Structure: AR(1) ## Formula: ~1 | Chick ## Parameter estimate(s): ## Phi ## 0.8249 ## Fixed effects: weight ~ Diet * Time ## Value Std.Error DF t-value p-value ## (Intercept) 38.26 4.951 320 7.728 0.0000 ## Diet2 -2.83 7.002 32 -0.404 0.6887 ## Diet3 -6.48 7.002 32 -0.926 0.3616 ## Diet4 -0.63 7.002 32 -0.090 0.9288 ## Time 6.56 0.937 320 6.998 0.0000 ## Diet2:Time 1.85 1.325 320 1.399 0.1629 ## Diet3:Time 3.93 1.325 320 2.969 0.0032 ## Diet4:Time 2.61 1.325 320 1.967 0.0500 ## Correlation: ## (Intr) Diet2 Diet3 Diet4 Time Dt2:Tm Dt3:Tm ## Diet2 -0.707 ## Diet3 -0.707 0.500 ## Diet4 -0.707 0.500 0.500 ## Time -0.254 0.180 0.180 0.180 ## Diet2:Time 0.180 -0.254 -0.127 -0.127 -0.707 ## Diet3:Time 0.180 -0.127 -0.254 -0.127 -0.707 0.500 ## Diet4:Time 0.180 -0.127 -0.127 -0.254 -0.707 0.500 0.500 ## ## Standardized Within-Group Residuals: ## Min Q1 Med Q3 Max ## -2.4886 -0.8607 -0.2404 0.2688 2.3246 ## ## Number of Observations: 360 ## Number of Groups: 36 ``` ] ] --- # chick data .pull-left[ Compare the results from the previous slide to a similar model that does not account for autocorrelation (look particularly at the SE estimates) .vsmall-code[ ```r lmm3 <- lme(fixed = weight ~ Diet *Time, random = ~ (Time-1)|Chick, data = chickdata) summary(lmm3) ``` ] ] .pull-right[ .vsmall-code[ ``` ## Linear mixed-effects model fit by maximum likelihood ## Data: chickdata ## AIC BIC logLik ## 2972 3011 -1476 ## ## Random effects: ## Formula: ~(Time - 1) | Chick ## Time Residual ## StdDev: 2.313 12.1 ## ## Fixed effects: weight ~ Diet * Time ## Value Std.Error DF t-value p-value ## (Intercept) 32.77 2.398 320 13.668 0.0000 ## Diet2 -2.58 3.391 32 -0.760 0.4530 ## Diet3 -8.96 3.391 32 -2.642 0.0126 ## Diet4 -0.06 3.391 32 -0.018 0.9854 ## Time 6.90 0.811 320 8.499 0.0000 ## Diet2:Time 1.57 1.147 320 1.369 0.1718 ## Diet3:Time 3.53 1.147 320 3.075 0.0023 ## Diet4:Time 2.52 1.147 320 2.197 0.0288 ## Correlation: ## (Intr) Diet2 Diet3 Diet4 Time Dt2:Tm Dt3:Tm ## Diet2 -0.707 ## Diet3 -0.707 0.500 ## Diet4 -0.707 0.500 0.500 ## Time -0.233 0.165 0.165 0.165 ## Diet2:Time 0.165 -0.233 -0.117 -0.117 -0.707 ## Diet3:Time 0.165 -0.117 -0.233 -0.117 -0.707 0.500 ## Diet4:Time 0.165 -0.117 -0.117 -0.233 -0.707 0.500 0.500 ## ## Standardized Within-Group Residuals: ## Min Q1 Med Q3 Max ## -2.5658 -0.6256 -0.0314 0.6650 3.4411 ## ## Number of Observations: 360 ## Number of Groups: 36 ``` ] ] --- # summary <br/> #### Which of the three methods should I use? -- - For well-balanced, experimental data, the simplest approach might be the split-plot option with adjusted p-values -- - For unbalanced data or observational studies (which often require additional model complexity), the most robust approach is likely linear mixed models with serial correlation --- # looking ahead <br/> ### **Next time**: Generalized linear models <br/> ### **Reading**: [Fieberg chp. 14](https://statistics4ecologists-v1.netlify.app/glm)