--- title: "18-11-2021_Generation effect controlling for family random effect (Mix model analysis)" author: "Githal_Arachchige" date: "18/11/2021" output: html_document --- ```{r} pacman::p_load(readxl, sjstats, openxlsx, writexl, lme4, lmerTest, MuMIn, tidyverse, sjPlot, car, forcats, dplyr, lmerTest) ``` ```{r} All_results <- read.xlsx("../Results_ALL_NA_removed.xlsx",sheet="New") NA_removed <- na.omit(All_results) NA_removed %>% group_by(Compound) %>% filter(!(abs(Concentration - median(Concentration)) > 3*sd(Concentration))) ``` ```{r} # Model 1 Model 1: Level 1 of Sex=”Female”, Level1 of Suffix=”Child” (default values); Female Child is baseline # Sex Male: Female child vs Male Child # SuffixParent: Female child vs Female Adult. fm1 <- lmer(log(Concentration) ~ Sex*Suffix +(1|Family_ID) , REML=FALSE, data=NA_removed, subset=Compound=="retinol") summary(fm1) coef(summary(fm1)) vcov(fm1) ``` ```{r} # Model 2: Level 1 of Sex= “Male”, level 1 of suffix=”Parent” (after changing defaults of both variables); Male Adult is baseline # Sex Female: Male Adult vs Female Adult # SuffixChild: Male Adult vs Male Child NA_removed_Sex_Generation <- na.omit(All_results) NA_removed_Sex_Generation$Sex <- factor(NA_removed_Sex_Generation$Sex, levels = c("Male", "Female")) NA_removed_Sex_Generation$Suffix <- factor(NA_removed_Sex_Generation$Suffix, levels = c("Parent", "Child")) fm1 <- lmer(log(Concentration) ~ Sex*Suffix +(1|Family_ID) , REML=FALSE, data=NA_removed_Sex_Generation, subset=Compound=="retinol") summary(fm1) coef(summary(fm1)) vcov(fm1) ``` ```{r} # Model 1 Model 1: Level 1 of Sex=”Female”, Level1 of Suffix=”Child” (default values); Female Child is baseline # Sex Male: Female child vs Male Child # SuffixParent: Female child vs Female Adult. fm1 <- lmer(log(Concentration) ~ Sex*Suffix +(1|Family_ID) , REML=FALSE, data=NA_removed, subset=Compound=="retinoic_acid") summary(fm1) coef(summary(fm1)) vcov(fm1) ``` ```{r} # Model 2: Level 1 of Sex= “Male”, level 1 of suffix=”Parent” (after changing defaults of both variables); Male Adult is baseline # Sex Female: Male Adult vs Female Adult # SuffixChild: Male Adult vs Male Child NA_removed_Sex_Generation <- na.omit(All_results) NA_removed_Sex_Generation$Sex <- factor(NA_removed_Sex_Generation$Sex, levels = c("Male", "Female")) NA_removed_Sex_Generation$Suffix <- factor(NA_removed_Sex_Generation$Suffix, levels = c("Parent", "Child")) fm1 <- lmer(log(Concentration) ~ Sex*Suffix +(1|Family_ID) , REML=FALSE, data=NA_removed_Sex_Generation, subset=Compound=="retinoic_acid") summary(fm1) coef(summary(fm1)) vcov(fm1) ``` ```{r} # Model 1 to test for the additive effect of Sex and Generation fm1 <- lmer(log(Concentration) ~ Sex*Suffix +(1|Family_ID) , REML=FALSE, data=NA_removed, subset=Compound=="25-OH-D3") summary(fm1) coef(summary(fm1)) vcov(fm1) ``` ```{r} # Model 1 Model 1: Level 1 of Sex=”Female”, Level1 of Suffix=”Child” (default values); Female Child is baseline # Sex Male: Female child vs Male Child # SuffixParent: Female child vs Female Adult. fm1 <- lmer(log(Concentration) ~ Sex*Suffix +(1|Family_ID) , REML=FALSE, data=NA_removed, subset=Compound=="α-tocopherol") summary(fm1) coef(summary(fm1)) vcov(fm1) ``` ```{r} # Model 2: Level 1 of Sex= “Male”, level 1 of suffix=”Parent” (after changing defaults of both variables); Male Adult is baseline # Sex Female: Male Adult vs Female Adult # SuffixChild: Male Adult vs Male Child NA_removed_Sex_Generation <- na.omit(All_results) NA_removed_Sex_Generation$Sex <- factor(NA_removed_Sex_Generation$Sex, levels = c("Male", "Female")) NA_removed_Sex_Generation$Suffix <- factor(NA_removed_Sex_Generation$Suffix, levels = c("Parent", "Child")) fm1 <- lmer(log(Concentration) ~ Sex*Suffix +(1|Family_ID) , REML=FALSE, data=NA_removed_Sex_Generation, subset=Compound=="α-tocopherol") summary(fm1) coef(summary(fm1)) vcov(fm1) ``` ```{r} # Model 1 to test for the additive effect of Sex and Generation fm1 <- lmer(log(Concentration) ~ Sex*Suffix +(1|Family_ID) , REML=FALSE, data=NA_removed, subset=Compound=="γ-tocopherol") summary(fm1) coef(summary(fm1)) vcov(fm1) ``` ```{r} # Model 1 to test for the additive effect of Sex and Generation fm1 <- lmer(log(Concentration) ~ Sex*Suffix +(1|Family_ID) , REML=FALSE, data=NA_removed, subset=Compound=="α-tocotrienol") summary(fm1) coef(summary(fm1)) vcov(fm1) ```