Load Required Libraries

## Loading required package: Matrix
## Loading required package: Rcpp
## 
## Attaching package: 'dplyr'
## 
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## 
## Loading required package: quadprog
## Loading required package: DBI
## 
## Attaching package: 'RMySQL'
## 
## The following objects are masked from 'package:RSQLite':
## 
##     dbBuildTableDefinition, isIdCurrent, safe.write

Load Database

Load WG productive/receptive data

wg.vocab.words <- as.data.frame(select(
  wg.table,basetable_ptr_id,col_baabaa:col_some))
names(wg.vocab.words)[1] <- "id"

wg.bykid.longform <- melt(wg.vocab.words,id.vars="id",
                       variable.name = "word",
                       value.name="produces") %>%
  mutate(understands = produces >= 1,
         produces = produces == 2)

wg.scores <- wg.bykid.longform %>%
  group_by(id) %>%
  summarise(productive = sum(produces),
            receptive = sum(understands))

Load WS productive data

ws.vocab.words <- as.data.frame(select(
  ws.table,basetable_ptr_id,col_baabaa:col_connthen))
names(ws.vocab.words)[1] <- "id"

ws.bykid.longform <- melt(ws.vocab.words,id.vars="id",
                       variable.name = "word",
                       value.name="produces")

ws.scores <- ws.bykid.longform %>%
  group_by(id) %>%
  summarise(productive = sum(produces))

Load child-specific data

admins <- as.data.frame(select(admin.table,data_id,child_id,age,source_id))
children <- as.data.frame(select(child.table,id,gender,mom_ed,birth_order))

child.data <- merge(children,admins,by.y="child_id",by.x = "id")
wg.word.data <- merge(child.data,wg.bykid.longform)
wg.child.scores <- merge(child.data,wg.scores)

ws.word.data <- merge(child.data,ws.bykid.longform)
ws.child.scores <- merge(child.data,ws.scores)

Compute crosstabs

wg.age.gender.data <- wg.child.scores %>%
  gather(measure,score,c(receptive,productive)) %>%
  group_by(age,gender,measure) %>%
  summarise(
    mean = mean(score),
    ci.l = ci.low(score),
    ci.h = ci.high(score),
    n = n())

#Show WG table
wg.age.gender.data
## Source: local data frame [44 x 7]
## Groups: age, gender
## 
##    age gender    measure    mean    ci.l    ci.h  n
## 1    8      F  receptive  44.094 19.3453 21.3781 32
## 2    8      F productive   2.375  1.0938  1.3758 32
## 3    8      M  receptive  41.800 13.7436 17.8721 35
## 4    8      M productive   1.657  0.8000  0.9429 35
## 5    9      F  receptive  44.688 10.1885 11.5630 48
## 6    9      F productive   2.375  0.8130  0.8542 48
## 7    9      M  receptive  32.902  9.2488  9.6104 41
## 8    9      M productive   1.512  0.6104  0.6341 41
## 9   10      F  receptive  63.328 12.5473 16.8914 64
## 10  10      F productive   5.219  1.6723  2.1098 64
## 11  10      M  receptive  49.167  9.7920 10.0014 72
## 12  10      M productive   3.208  0.8337  0.8476 72
## 13  11      F  receptive  95.267 23.1589 27.9372 45
## 14  11      F productive  11.844  6.3778 10.4250 45
## 15  11      M  receptive  60.840 13.5830 13.0210 50
## 16  11      M productive   5.200  1.9205  2.5010 50
## 17  12      F  receptive  92.709 11.0142 10.7725 79
## 18  12      F productive  10.544  2.2165  2.3560 79
## 19  12      M  receptive  77.064 11.5385 12.3247 78
## 20  12      M productive   9.821  2.7311  3.0519 78
## 21  13      F  receptive 129.263 18.2303 21.0553 57
## 22  13      F productive  17.912  3.6145  3.4390 57
## 23  13      M  receptive 106.733 19.3779 19.3904 60
## 24  13      M productive  13.267  4.7842  6.1854 60
## 25  14      F  receptive 157.655 20.3047 22.5267 58
## 26  14      F productive  28.414  8.9147  9.0207 58
## 27  14      M  receptive 149.170 21.4920 21.0953 53
## 28  14      M productive  25.057  7.2642 10.0014 53
## 29  15      F  receptive 172.857 28.9832 29.8429 49
## 30  15      F productive  57.388 19.9597 23.5005 49
## 31  15      M  receptive 164.477 26.5017 28.3489 44
## 32  15      M productive  36.795 13.7977 17.0256 44
## 33  16      F  receptive 218.571 28.4107 28.9048 42
## 34  16      F productive  85.262 22.1946 23.8929 42
## 35  16      M  receptive 165.643 21.9917 20.3595 42
## 36  16      M productive  35.095  8.3345  9.5512 42
## 37  17      F  receptive 224.818 23.5212 23.0386 33
## 38  17      F productive  71.212 20.3348 23.8303 33
## 39  17      M  receptive 199.634 23.6732 21.4244 41
## 40  17      M productive  59.073 17.9518 20.3921 41
## 41  18      F  receptive 261.027 29.7595 30.8797 37
## 42  18      F productive 104.514 24.0838 27.5405 37
## 43  18      M  receptive 241.138 29.5759 27.8284 29
## 44  18      M productive  63.345 18.1397 18.1750 29
ws.age.gender.data <- ws.child.scores %>%
  group_by(age,gender) %>%
  filter(age>= 16, age <= 30) %>%
  summarise(
    mean = mean(productive),
    ci.l = ci.low(productive),
    ci.h = ci.high(productive),
    n = n())

#Show WS table
ws.age.gender.data
## Source: local data frame [30 x 6]
## Groups: age
## 
##    age gender   mean  ci.l  ci.h   n
## 1   16      F  73.02 15.00 16.71  95
## 2   16      M  53.32 14.44 15.79  93
## 3   17      F  84.63 19.60 21.74  70
## 4   17      M  66.19 14.32 15.44  63
## 5   18      F 135.95 17.76 18.48 153
## 6   18      M 100.88 13.45 14.17 180
## 7   19      F 173.41 22.71 22.50 126
## 8   19      M 134.07 21.48 21.93 101
## 9   20      F 194.89 28.50 28.46  88
## 10  20      M 162.16 28.36 28.57  88
## 11  21      F 201.06 41.38 42.93  53
## 12  21      M 188.00 34.30 36.78  61
## 13  22      F 290.69 42.69 42.71  62
## 14  22      M 238.18 47.63 49.97  49
## 15  23      F 304.98 44.02 42.70  66
## 16  23      M 303.04 33.59 34.33  71
## 17  24      F 359.43 23.30 22.99 195
## 18  24      M 284.81 22.31 22.64 208
## 19  25      F 394.01 30.10 27.63 114
## 20  25      M 302.84 29.38 27.18 109
## 21  26      F 430.46 43.62 38.84  65
## 22  26      M 348.49 43.00 42.12  69
## 23  27      F 433.86 42.33 40.20  65
## 24  27      M 380.00 39.50 38.23  73
## 25  28      F 455.77 34.42 36.03  48
## 26  28      M 381.53 48.75 44.75  55
## 27  29      F 480.96 44.48 44.06  54
## 28  29      M 420.16 41.49 41.10  64
## 29  30      F 538.16 21.05 18.91 113
## 30  30      M 500.30 25.04 22.57 115

Plot WG

quartz(width=7,height=4)
ggplot(wg.age.gender.data, 
       aes(x=age, y=mean,colour=gender,linetype=measure,
           group=interaction(gender,measure)))+
  geom_pointrange(aes(ymin = mean-ci.l,
                      ymax = mean+ci.h),
                  size = .8,
                  show_guide = FALSE) +
  geom_line(size=1) +
  scale_x_continuous(breaks=seq(8,18,1),
                     name = "Age (months)")+
  scale_y_continuous(name = "Vocabulary Size (words)") +
  theme_bw(base_size=14) +
  scale_color_manual(values = c("#e41a1c","#377eb8"))

plot of chunk unnamed-chunk-7

Plot WS

quartz(width=6,height=4)
ggplot(ws.age.gender.data, 
       aes(x=age, y=mean,colour=gender,label=gender))+
  geom_pointrange(aes(ymin = mean-ci.l,
                      ymax = mean+ci.h),
                  size = .8,
                  show_guide = FALSE) +
  geom_line(size=1) +
  scale_x_continuous(breaks=seq(16,30,1),limits=c(16,30.5),
                     name = "Age (months)")+
  scale_y_continuous(name = "Vocabulary Size (words)",limits=c(0,680)) +
  theme_bw(base_size=14) +
  theme(legend.position="none") +
  geom_dl(method=list("last.qp",cex=1,hjust=-.5)) +
  scale_color_manual(values = c("#e41a1c","#377eb8"))
## Loading required package: proto

plot of chunk unnamed-chunk-8