knitr::opts_chunk$set(echo = TRUE, comment = "#>", collapse = TRUE)
knitr::opts_knit$set(root.dir = "../../../")
library("L2TDatabase")
library("dplyr")

# Connect to dat-base
cnf_file <- file.path(getwd(), "inst/l2t_db.cnf")
l2t <- l2t_connect(cnf_file, "backend")

# Combine EVT and Child tables to get LateTalker/Implant status
evts <- tbl(l2t, "EVT") %>% 
  left_join("ChildStudy" %from% l2t) %>% 
  left_join("Child" %from% l2t)

# Ready data-frame
d <- evts %>% 
  collect() %>% 
  filter(!is.na(EVT_GSV)) %>% 
  select(ChildID, EVT_Age, EVT_GSV, LateTalker, CImplant) %>% 
  mutate(Group = ifelse(LateTalker, "Late Talker", "TD"),
         Group = ifelse(CImplant, "Cochlear Implant", Group))

d %>% count()
d %>% count(Group)

# Plot quadratic growth curve
library("ggplot2")
ggplot(d) + 
  aes(x = EVT_Age, y = EVT_GSV) + 
  geom_line(aes(group = ChildID), alpha = .4) + 
  facet_grid(~ Group) + 
  stat_smooth(method = "lm", formula = y ~ poly(x, 2))


LearningToTalk/L2TDatabase documentation built on June 24, 2020, 3:45 a.m.