##Statistical analysis PFOA/GenX library(coda) library(reshape) library(coefplot2) library(ggplot2) library(dplyr) library(data.table) library(lme4) library(lmtest) library(nlme) getwd() setwd("C:/Users/blakebe/Documents/CD1 PFOA GenX/R CSV files") df<-read.csv("Combined maternal and fetal data E11 and E17 with Elmore data points BEB 10192018.csv") #Convert to lowercase col headers names(df)<-tolower(names(df)) names(df) #df$dam.id<-as.factor(df$dam.id) str(df) pf<-read.csv("Fetal placental data E11 and E17 R format BEB updated on 08262019.csv") #pf$dam.id<-as.factor(pf$dam.id) names(pf) str(pf) fet.length<-dplyr::select(pf, timepoint, block, dam.id, obs, fet.l) mat.pf<-merge(df,fet.length, by=c("timepoint","block","dam.id","obs")) n.obs.summary<-mat.pf%>% dplyr::group_by(timepoint, group)%>% dplyr::summarise(n.dams=length(unique(dam.id)), n.obs=length(fet.l), obs.litter=mean(n.obs/n.dams)) n.obs.summary pf.11<-subset(mat.pf, timepoint=="E11.5") pf.17<-subset(mat.pf, timepoint=="E17.5") ####Embryo length analysis ##E11 first hist(pf.11$fet.wt) hist(pf.11$pl.wt) hist(pf.11$fp.rat) hist(pf.11$fet.l) ##Fetal length marginally sig differ among groups at E11.5 m0<-lmer(fet.l~litter.n+(1|dam.id),data=pf.11, REML=F) m1<-lmer(fet.l~group+litter.n+(1|dam.id),data=pf.11,REML=F) anova(m0,m1) ## Group not significantly associated with fetal length f.11<-coefplot2(m1, main="E11.5 Fetus Length (mm)\n") summary(m1) confint(m1) ##Fetal length marginally sig differ among groups at E17.5 m1<-lmer(fet.l~group+litter.n+(1|dam.id),data=pf.17,REML=F) m0<-lmer(fet.l~litter.n+(1|dam.id),data=pf.17,REML=F) anova(m0,m1) ##Group is significantly associated with embryo length summary(m1) confint(m1) f.17<-coefplot2(m1, main="E17.5 Fetus Length (mm)\n")