class: center, middle background-image: url("./figs/logos.png") background-position: 50% 95% background-size: 400px 90px ## Analysis of longitudinal data using linear mixed models ### Lucas Veras <br> <br> <br> --- ## Today <br> .huge[ <ol> <li> What is a longitudinal study? </ol> ] -- .huge[ <ol start=2> <li> Usual approach to data analysis </ol> ] -- .huge[ <ol start=3> <li> Using linear mixed models </ol> ] --- class: center, middle <img src="./figs/R.svg" width="40%" style="display: block; margin: auto;" /> --- class: inverse, center, middle ## What is a longitudinal study? --- ## Longitudinal study <br> -- * Repeated observations of the same variables over time -- (> 2 observations) -- * Can be observational (*e.g.*, cohort) or experimental (*e.g.*, randomized controlled trials) -- * Can detect the effect of time -- * Time-consuming and expensive -- * Missing data --- class: inverse, center, middle ## Usual approach to data analysis --- ## Usual approach <br> -- * ANOVA, ANCOVA, etc. -- * Cannot be used due to correlated error terms -- * Repeated measures ANOVA is usually used --- ## The data .center[Lean mass in bariatric surgery patients] -- .center[Does exercise attenuates the lean mass loss after bariatric surgery?] -- <table> <thead> <tr> <th style="text-align:left;"> subj </th> <th style="text-align:left;"> group </th> <th style="text-align:right;"> T1 </th> <th style="text-align:right;"> T2 </th> <th style="text-align:right;"> T3 </th> <th style="text-align:right;"> T4 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 47.8 </td> <td style="text-align:right;"> 41.2 </td> <td style="text-align:right;"> 40.1 </td> <td style="text-align:right;"> NA </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 52.1 </td> <td style="text-align:right;"> 46.2 </td> <td style="text-align:right;"> 42.7 </td> <td style="text-align:right;"> 41.9 </td> </tr> <tr> <td style="text-align:left;"> 3 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 67.9 </td> <td style="text-align:right;"> 63.0 </td> <td style="text-align:right;"> 60.6 </td> <td style="text-align:right;"> 56.8 </td> </tr> <tr> <td style="text-align:left;"> 4 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 50.7 </td> <td style="text-align:right;"> 47.6 </td> <td style="text-align:right;"> 44.2 </td> <td style="text-align:right;"> 43.1 </td> </tr> <tr> <td style="text-align:left;"> 5 </td> <td style="text-align:left;"> CG </td> <td style="text-align:right;"> 50.8 </td> <td style="text-align:right;"> 43.9 </td> <td style="text-align:right;"> 42.1 </td> <td style="text-align:right;"> 42.1 </td> </tr> <tr> <td style="text-align:left;"> 6 </td> <td style="text-align:left;"> CG </td> <td style="text-align:right;"> 53.6 </td> <td style="text-align:right;"> 49.6 </td> <td style="text-align:right;"> 49.1 </td> <td style="text-align:right;"> 46.3 </td> </tr> </tbody> </table> --- ## The data * For repeated measures ANOVA, we cannot have any missing data <br> <table> <thead> <tr> <th style="text-align:left;"> subj </th> <th style="text-align:left;"> group </th> <th style="text-align:right;"> T1 </th> <th style="text-align:right;"> T2 </th> <th style="text-align:right;"> T3 </th> <th style="text-align:right;"> T4 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 47.8 </td> <td style="text-align:right;"> 41.2 </td> <td style="text-align:right;"> 40.1 </td> <td style="text-align:right;"> NA </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 52.1 </td> <td style="text-align:right;"> 46.2 </td> <td style="text-align:right;"> 42.7 </td> <td style="text-align:right;"> 41.9 </td> </tr> <tr> <td style="text-align:left;"> 3 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 67.9 </td> <td style="text-align:right;"> 63.0 </td> <td style="text-align:right;"> 60.6 </td> <td style="text-align:right;"> 56.8 </td> </tr> <tr> <td style="text-align:left;"> 4 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 50.7 </td> <td style="text-align:right;"> 47.6 </td> <td style="text-align:right;"> 44.2 </td> <td style="text-align:right;"> 43.1 </td> </tr> <tr> <td style="text-align:left;"> 5 </td> <td style="text-align:left;"> CG </td> <td style="text-align:right;"> 50.8 </td> <td style="text-align:right;"> 43.9 </td> <td style="text-align:right;"> 42.1 </td> <td style="text-align:right;"> 42.1 </td> </tr> <tr> <td style="text-align:left;"> 6 </td> <td style="text-align:left;"> CG </td> <td style="text-align:right;"> 53.6 </td> <td style="text-align:right;"> 49.6 </td> <td style="text-align:right;"> 49.1 </td> <td style="text-align:right;"> 46.3 </td> </tr> </tbody> </table> --- ## The data * For repeated measures ANOVA, we cannot have any missing data <br> <table> <thead> <tr> <th style="text-align:left;"> subj </th> <th style="text-align:left;"> group </th> <th style="text-align:right;"> T1 </th> <th style="text-align:right;"> T2 </th> <th style="text-align:right;"> T3 </th> <th style="text-align:right;"> T4 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 52.1 </td> <td style="text-align:right;"> 46.2 </td> <td style="text-align:right;"> 42.7 </td> <td style="text-align:right;"> 41.9 </td> </tr> <tr> <td style="text-align:left;"> 3 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 67.9 </td> <td style="text-align:right;"> 63.0 </td> <td style="text-align:right;"> 60.6 </td> <td style="text-align:right;"> 56.8 </td> </tr> <tr> <td style="text-align:left;"> 4 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 50.7 </td> <td style="text-align:right;"> 47.6 </td> <td style="text-align:right;"> 44.2 </td> <td style="text-align:right;"> 43.1 </td> </tr> <tr> <td style="text-align:left;"> 5 </td> <td style="text-align:left;"> CG </td> <td style="text-align:right;"> 50.8 </td> <td style="text-align:right;"> 43.9 </td> <td style="text-align:right;"> 42.1 </td> <td style="text-align:right;"> 42.1 </td> </tr> <tr> <td style="text-align:left;"> 6 </td> <td style="text-align:left;"> CG </td> <td style="text-align:right;"> 53.6 </td> <td style="text-align:right;"> 49.6 </td> <td style="text-align:right;"> 49.1 </td> <td style="text-align:right;"> 46.3 </td> </tr> <tr> <td style="text-align:left;"> 7 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 51.7 </td> <td style="text-align:right;"> 45.5 </td> <td style="text-align:right;"> 41.6 </td> <td style="text-align:right;"> 40.1 </td> </tr> </tbody> </table> --- ## The data * For repeated measures ANOVA, we cannot have any missing data * Also, data have to be in "long" format <table> <thead> <tr> <th style="text-align:left;"> subj </th> <th style="text-align:left;"> group </th> <th style="text-align:right;"> T1 </th> <th style="text-align:right;"> T2 </th> <th style="text-align:right;"> T3 </th> <th style="text-align:right;"> T4 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 52.1 </td> <td style="text-align:right;"> 46.2 </td> <td style="text-align:right;"> 42.7 </td> <td style="text-align:right;"> 41.9 </td> </tr> <tr> <td style="text-align:left;"> 3 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 67.9 </td> <td style="text-align:right;"> 63.0 </td> <td style="text-align:right;"> 60.6 </td> <td style="text-align:right;"> 56.8 </td> </tr> <tr> <td style="text-align:left;"> 4 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 50.7 </td> <td style="text-align:right;"> 47.6 </td> <td style="text-align:right;"> 44.2 </td> <td style="text-align:right;"> 43.1 </td> </tr> <tr> <td style="text-align:left;"> 5 </td> <td style="text-align:left;"> CG </td> <td style="text-align:right;"> 50.8 </td> <td style="text-align:right;"> 43.9 </td> <td style="text-align:right;"> 42.1 </td> <td style="text-align:right;"> 42.1 </td> </tr> <tr> <td style="text-align:left;"> 6 </td> <td style="text-align:left;"> CG </td> <td style="text-align:right;"> 53.6 </td> <td style="text-align:right;"> 49.6 </td> <td style="text-align:right;"> 49.1 </td> <td style="text-align:right;"> 46.3 </td> </tr> <tr> <td style="text-align:left;"> 7 </td> <td style="text-align:left;"> EG </td> <td style="text-align:right;"> 51.7 </td> <td style="text-align:right;"> 45.5 </td> <td style="text-align:right;"> 41.6 </td> <td style="text-align:right;"> 40.1 </td> </tr> </tbody> </table> --- ## The data * For repeated measures ANOVA, we cannot have any missing data * Also, data have to be in "long" format <table> <thead> <tr> <th style="text-align:left;"> subj </th> <th style="text-align:left;"> group </th> <th style="text-align:left;"> time </th> <th style="text-align:right;"> lean_mass </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T1 </td> <td style="text-align:right;"> 52.1 </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T2 </td> <td style="text-align:right;"> 46.2 </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T3 </td> <td style="text-align:right;"> 42.7 </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T4 </td> <td style="text-align:right;"> 41.9 </td> </tr> <tr> <td style="text-align:left;"> 3 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T1 </td> <td style="text-align:right;"> 67.9 </td> </tr> <tr> <td style="text-align:left;"> 3 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T2 </td> <td style="text-align:right;"> 63.0 </td> </tr> </tbody> </table> -- * N = 49 subjects --- ## The data <br> .pull-left[ Also, we have to specify: * Outcome ] --- ## The data <br> .pull-left[ Also, we have to specify: * Outcome * Between-subjects variable ] --- ## The data <br> .pull-left[ Also, we have to specify: * Outcome * Between-subjects variable * Within-subjects variable ] --- ## The data <br> .pull-left[ Also, we have to specify: * Outcome * Between-subjects variable * Within-subjects variable * Covariates ] --- ## The data <br> .pull-left[ Also, we have to specify: * Outcome: * Between-subjects variable * Within-subjects variable * Covariates ] .pull-right[ <br> `lean_mass` ] --- ## The data <br> .pull-left[ Also, we have to specify: * Outcome: * Between-subjects variable: * Within-subjects variable * Covariates ] .pull-right[ <br> `lean_mass` `group` ] --- ## The data <br> .pull-left[ Also, we have to specify: * Outcome: * Between-subjects variable: * Within-subjects variable: * Covariates ] .pull-right[ <br> `lean_mass` `group` `time` ] --- ## The data <br> .pull-left[ Also, we have to specify: * Outcome: * Between-subjects variable: * Within-subjects variable: * Covariates: ] .pull-right[ <br> `lean_mass` `group` `time` baseline values of `lean_mass` ] --- ## The analysis <br> **Main outcome:** between-group differences in lean mass at the end of the intervention -- Pairwise comparisons: ``` ## contrast estimate SE df t.ratio p.value ## 1 EG T1 - CG T1 1.352855e-16 1.266022e-16 46 1.068588 2.908313e-01 ## 2 EG T1 - EG T2 5.513813e+00 3.169273e-01 46 17.397722 7.330702e-22 ## 3 EG T1 - CG T2 6.085172e+00 4.552198e-01 46 13.367547 1.873215e-17 ## 4 EG T1 - EG T3 7.842742e+00 3.920524e-01 46 20.004321 2.486864e-24 ## 5 EG T1 - CG T3 9.052269e+00 5.631260e-01 46 16.075034 1.683304e-20 ## 6 EG T1 - EG T4 8.639867e+00 4.705911e-01 46 18.359605 8.368599e-23 ## 7 EG T1 - CG T4 9.996956e+00 6.759354e-01 46 14.789810 4.230588e-19 ## 8 CG T1 - EG T2 5.513813e+00 3.169273e-01 46 17.397722 7.330702e-22 ## 9 CG T1 - CG T2 6.085172e+00 4.552198e-01 46 13.367547 1.873215e-17 ## 10 CG T1 - EG T3 7.842742e+00 3.920524e-01 46 20.004321 2.486864e-24 ``` --- ## The analysis <br> **Main outcome:** between-group differences in lean mass at the end of the intervention Pairwise comparisons: ``` ## contrast estimate SE df t.ratio p.value ## 28 EG T4 - CG T4 1.357089 0.8237718 46 1.647409 0.1062893 ``` --- class: inverse, center, middle ## Using linear mixed models --- ## The general linear model <br> `$$Y_i = \beta_0 + \beta_1X_1 + \beta_2X_2 + ... + \beta_nX_n + \varepsilon_i$$` <br> -- Linear regression, *t*-test, ANOVA, ANCOVA, etc -- Includes only **fixed effects** -- But we can also include **random effects** --- ## Linear mixed models Mixed = (fixed + random) effects -- But what are **fixed** and **random** effects? -- * **Fixed effects:** * Variables that we expect will have an effect on the dependent variable -- * **Random effects:** * Grouping factors for which we are trying to control -- * Always categorical variables -- * Rule of thumb: at least five levels --- ## Linear mixed models Random effects can be either **random intercept** -- <img src="slides_files/figure-html/unnamed-chunk-11-1.png" width="60%" style="display: block; margin: auto;" /> --- ## Linear mixed models Random effects can be either random intercept, **random slope** <img src="slides_files/figure-html/unnamed-chunk-12-1.png" width="60%" style="display: block; margin: auto;" /> --- ## Linear mixed models Random effects can be either random intercept, random slope, or **both** <img src="slides_files/figure-html/unnamed-chunk-13-1.png" width="60%" style="display: block; margin: auto;" /> --- ## Linear mixed models We will usually need random intercept -- <br> `$$Y_i = (\beta_0 + u_0) + \beta_1X_1 + \beta_2X_2 + ... + \beta_nX_n + \varepsilon_i$$` <br> -- In our case, the intercept will vary across each subject --- ## Linear mixed models .center[.huge["Multilevel"]] <br> <br> <img src="./figs/multilevel.png" width="90%" style="display: block; margin: auto;" /> --- ## Doing the analysis using R <br> What will we need? -- * Data -- * Packages -- * Build the model -- * Inspect the results --- ## The data <br> <br> <br> <br> <table> <thead> <tr> <th style="text-align:left;"> subj </th> <th style="text-align:left;"> group </th> <th style="text-align:left;"> time </th> <th style="text-align:right;"> lean_mass </th> <th style="text-align:right;"> lean_mass_baseline </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T1 </td> <td style="text-align:right;"> 47.8 </td> <td style="text-align:right;"> 47.8 </td> </tr> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T2 </td> <td style="text-align:right;"> 41.2 </td> <td style="text-align:right;"> 47.8 </td> </tr> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T3 </td> <td style="text-align:right;"> 40.1 </td> <td style="text-align:right;"> 47.8 </td> </tr> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T4 </td> <td style="text-align:right;"> NA </td> <td style="text-align:right;"> NA </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T1 </td> <td style="text-align:right;"> 52.1 </td> <td style="text-align:right;"> 52.1 </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T2 </td> <td style="text-align:right;"> 46.2 </td> <td style="text-align:right;"> 52.1 </td> </tr> </tbody> </table> --- ## The data * Remember: * Allow missing data * `lean_mass_baseline` is the covariate <table> <thead> <tr> <th style="text-align:left;"> subj </th> <th style="text-align:left;"> group </th> <th style="text-align:left;"> time </th> <th style="text-align:right;"> lean_mass </th> <th style="text-align:right;"> lean_mass_baseline </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T1 </td> <td style="text-align:right;"> 47.8 </td> <td style="text-align:right;"> 47.8 </td> </tr> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T2 </td> <td style="text-align:right;"> 41.2 </td> <td style="text-align:right;"> 47.8 </td> </tr> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T3 </td> <td style="text-align:right;"> 40.1 </td> <td style="text-align:right;"> 47.8 </td> </tr> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T4 </td> <td style="text-align:right;"> NA </td> <td style="text-align:right;"> NA </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T1 </td> <td style="text-align:right;"> 52.1 </td> <td style="text-align:right;"> 52.1 </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> EG </td> <td style="text-align:left;"> T2 </td> <td style="text-align:right;"> 46.2 </td> <td style="text-align:right;"> 52.1 </td> </tr> </tbody> </table> -- * N = 66 subjects (*vs.* 49 with RM ANOVA) --- ## The data <br> * How to read data into R ```r read_xlsx("path/to/data.xlsx") read_csv("path/to/data.xlsx") ``` -- ```r d <- read_csv("~/Documents/Projects/lmm_tutorial/example_data.csv") ``` --- ## Packages <br> * We will need some packages to analyse the data. -- * First, we will need to install: ```r install.packages("tidyverse") # General data manipulation and graphs install.packages("readxl") # Read data from excel files install.packages("lmerTest") # Build the linear mixed models install.packages("emmeans") # Calculate the estimated marginal means ``` -- * And then, load them into the R session: ```r library(tidyverse) library(readxl) library(lmerTest) library(emmeans) ``` --- ## Build the model <br> * To build the model we will use the function: ```r lmm <- lmer(formula, data) ``` -- * Where `formula` is: `outcome ~ fix_eff_1 + fix_eff_2 + cov + (1 | random_intercerpt)` -- * And `data` is the name of our dataset, which is `d` -- * Therefore: ```r lmm <- lmer( lean_mass ~ group * time + lean_mass_adjust + (1 | subj), data = d ) ``` --- ## Inspecting the results <br> * We can, then, check the results of the fixed effects ```r anova(model_name, type = 3, test = "F") ``` --- ## Inspecting the results <br> * We can, then, check the results of the fixed effects ```r anova(lmm, type = 3, test = "F") ``` ``` ## Type III Analysis of Variance Table with Satterthwaite's method ## Sum Sq Mean Sq NumDF DenDF F value Pr(>F) ## group 10.7 10.7 1 62.997 2.4113 0.1255 ## time 2818.9 939.6 3 176.553 211.8476 <2e-16 *** ## lean_mass_adjust 10054.1 10054.1 1 62.891 2266.7859 <2e-16 *** ## group:time 25.1 8.4 3 176.508 1.8835 0.1341 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ``` --- ## Inspecting the results <br> * We can also calculate the estimated marginal means ```r emm <- emmeans(model, formula) ``` -- * Where `formula` is: `~ factor` -- * We usually want the marginal means of the interaction term ```r emm <- emmeans(lmm, ~ group:time) ``` --- ## Inspecting the results <br> ```r emm ``` ``` ## group time emmean SE df lower.CL upper.CL ## EG T1 53.3 0.340 216 52.6 54.0 ## CG T1 53.7 0.516 215 52.7 54.7 ## EG T2 47.6 0.340 216 46.9 48.3 ## CG T2 47.3 0.516 215 46.3 48.3 ## EG T3 45.5 0.364 221 44.8 46.2 ## CG T3 44.4 0.516 215 43.4 45.4 ## EG T4 44.8 0.393 227 44.0 45.6 ## CG T4 43.4 0.574 225 42.3 44.5 ## ## Degrees-of-freedom method: kenward-roger ## Confidence level used: 0.95 ``` --- ## Inspecting the results <br> * Finally, we can also get the pairwise comparisons ```r pairs(marginal_means, adjust) ``` --- ## Inspecting the results * Finally, we can also get the pairwise comparisons ```r pairs(emm, adjust = "none") ``` ``` ## contrast estimate SE df t.ratio p.value ## 1 EG T1 - CG T1 -0.380 0.619 215 -0.614 0.54 ## 2 EG T1 - EG T2 5.698 0.439 171 12.974 <.001 ## 3 EG T1 - CG T2 5.975 0.619 215 9.658 <.001 ## 4 EG T1 - EG T3 7.816 0.458 176 17.074 <.001 ## 5 EG T1 - CG T3 8.914 0.619 215 14.407 <.001 ## 6 EG T1 - EG T4 8.481 0.481 181 17.614 <.001 ## 7 EG T1 - CG T4 9.902 0.667 223 14.841 <.001 ## 8 CG T1 - EG T2 6.078 0.619 215 9.823 <.001 ## 9 CG T1 - CG T2 6.355 0.666 171 9.543 <.001 ## 10 CG T1 - EG T3 8.196 0.632 217 12.962 <.001 ## 11 CG T1 - CG T3 9.294 0.666 171 13.955 <.001 ## 12 CG T1 - EG T4 8.861 0.649 220 13.648 <.001 ## 13 CG T1 - CG T4 10.282 0.712 178 14.444 <.001 ## 14 EG T2 - CG T2 0.278 0.619 215 0.449 0.654 ``` --- ## Inspecting the results * Finally, we can also get the pairwise comparisons ```r pairs(emm, adjust = "none") ``` ``` ## contrast estimate SE df t.ratio p.value ## 15 EG T2 - EG T3 2.118 0.458 176 4.628 <.001 ## 16 EG T2 - CG T3 3.216 0.619 215 5.198 <.001 ## 17 EG T2 - EG T4 2.783 0.481 181 5.780 <.001 ## 18 EG T2 - CG T4 4.205 0.667 223 6.302 <.001 ## 19 CG T2 - EG T3 1.840 0.632 217 2.911 0.004 ## 20 CG T2 - CG T3 2.938 0.666 171 4.412 <.001 ## 21 CG T2 - EG T4 2.505 0.649 220 3.859 <.001 ## 22 CG T2 - CG T4 3.927 0.712 178 5.516 <.001 ## 23 EG T3 - CG T3 1.098 0.632 217 1.736 0.084 ## 24 EG T3 - EG T4 0.665 0.495 178 1.343 0.181 ## 25 EG T3 - CG T4 2.087 0.680 224 3.069 0.002 ## 26 CG T3 - EG T4 -0.433 0.649 220 -0.667 0.505 ## 27 CG T3 - CG T4 0.989 0.712 178 1.389 0.167 ## 28 EG T4 - CG T4 1.422 0.696 225 2.044 0.042 ``` --- ## Plots <img src="slides_files/figure-html/unnamed-chunk-33-1.png" width="65%" style="display: block; margin: auto;" /> --- ## Plots ```r ph[28, ] ``` ``` ## contrast estimate SE df t.ratio p.value ## 28 EG T4 - CG T4 1.422 0.696 225 2.044 0.042 ``` -- <img src="slides_files/figure-html/unnamed-chunk-35-1.png" width="50%" style="display: block; margin: auto;" /> --- ## Plots ```r ph[28, ] ``` ``` ## contrast estimate SE df t.ratio p.value ## 28 EG T4 - CG T4 1.422 0.696 225 2.044 0.042 ``` <img src="slides_files/figure-html/unnamed-chunk-37-1.png" width="50%" style="display: block; margin: auto;" /> --- ## Useful links <br> * [Getting started with R and RStudio](https://ourcodingclub.github.io/tutorials/intro-to-r/) * [R for Data Science (book)](https://r4ds.had.co.nz) * [Discovering Statistics Using R (book; specially Chapter 19 - Multilevel linear models)](https://www.discoveringstatistics.com/books/discovering-statistics-using-r/) --- class: center <br> <br> <br> <br> <br> .enormous[**Thank you!**] <br> <br> <br> <br> <svg viewBox="0 0 496 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#1B395E;" xmlns="http://www.w3.org/2000/svg"> <path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"></path></svg> [@verasls](https://github.com/verasls) | <svg viewBox="0 0 512 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#1B395E;" xmlns="http://www.w3.org/2000/svg"> <path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z"></path></svg> [@verasls](https://twitter.com/lucasdsveras) <svg viewBox="0 0 512 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#1B395E;" xmlns="http://www.w3.org/2000/svg"> <path d="M502.3 190.8c3.9-3.1 9.7-.2 9.7 4.7V400c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V195.6c0-5 5.7-7.8 9.7-4.7 22.4 17.4 52.1 39.5 154.1 113.6 21.1 15.4 56.7 47.8 92.2 47.6 35.7.3 72-32.8 92.3-47.6 102-74.1 131.6-96.3 154-113.7zM256 320c23.2.4 56.6-29.2 73.4-41.4 132.7-96.3 142.8-104.7 173.4-128.7 5.8-4.5 9.2-11.5 9.2-18.9v-19c0-26.5-21.5-48-48-48H48C21.5 64 0 85.5 0 112v19c0 7.4 3.4 14.3 9.2 18.9 30.6 23.9 40.7 32.4 173.4 128.7 16.8 12.2 50.2 41.8 73.4 41.4z"></path></svg> [lucasdsveras@gmail.com](mailto:lucasdsveras@gmail.com) <svg viewBox="0 0 496 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#1B395E;" xmlns="http://www.w3.org/2000/svg"> <path d="M336.5 160C322 70.7 287.8 8 248 8s-74 62.7-88.5 152h177zM152 256c0 22.2 1.2 43.5 3.3 64h185.3c2.1-20.5 3.3-41.8 3.3-64s-1.2-43.5-3.3-64H155.3c-2.1 20.5-3.3 41.8-3.3 64zm324.7-96c-28.6-67.9-86.5-120.4-158-141.6 24.4 33.8 41.2 84.7 50 141.6h108zM177.2 18.4C105.8 39.6 47.8 92.1 19.3 160h108c8.7-56.9 25.5-107.8 49.9-141.6zM487.4 192H372.7c2.1 21 3.3 42.5 3.3 64s-1.2 43-3.3 64h114.6c5.5-20.5 8.6-41.8 8.6-64s-3.1-43.5-8.5-64zM120 256c0-21.5 1.2-43 3.3-64H8.6C3.2 212.5 0 233.8 0 256s3.2 43.5 8.6 64h114.6c-2-21-3.2-42.5-3.2-64zm39.5 96c14.5 89.3 48.7 152 88.5 152s74-62.7 88.5-152h-177zm159.3 141.6c71.4-21.2 129.4-73.7 158-141.6h-108c-8.8 56.9-25.6 107.8-50 141.6zM19.3 352c28.6 67.9 86.5 120.4 158 141.6-24.4-33.8-41.2-84.7-50-141.6h-108z"></path></svg> [lveras.com](https://lveras.com)