library(readr)
library(dplyr)
## 
## 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
library(ggplot2)
library(langcog)
## 
## Attaching package: 'langcog'
## 
## The following object is masked from 'package:base':
## 
##     scale
library(magrittr)
library(stringr)

rm(list=ls())
theme_set(theme_bw())

1 Cognitive tasks

Read data. Note that there is one sitting file for the battery and one for each of the sub-tests, in case the battery crashed and failed to save data for that participant.

sittings.raw <- bind_rows(
  read_csv("data/fall 2015/b301_09.28.15_14.56.34_sittings.csv"),
  read_csv("data/fall 2015/b299_09.28.15_18.57.40_sittings.csv"),
  read_csv("data/fall 2015/b300_09.28.15_18.57.49_sittings.csv"),
  read_csv("data/fall 2015/b302_09.28.15_18.57.55_sittings.csv"))
## Warning: 202 problems parsing 'data/fall 2015/
## b301_09.28.15_14.56.34_sittings.csv'. See problems(...) for more details.
## Warning: 5 problems parsing 'data/fall 2015/
## b299_09.28.15_18.57.40_sittings.csv'. See problems(...) for more details.
## Warning: 25 problems parsing 'data/fall 2015/
## b300_09.28.15_18.57.49_sittings.csv'. See problems(...) for more details.
## Warning: 22 problems parsing 'data/fall 2015/
## b302_09.28.15_18.57.55_sittings.csv'. See problems(...) for more details.
sittings <- sittings.raw %>% 
  mutate(subid = str_trim(toupper(misc), side = "both"),
         sitting_id = id) %>%
  filter(str_detect(subid, "[Ss][12]-")) %>%
  mutate(grade = ifelse(str_detect(subid, "[Ss][1]"), 
                        "first grade", 
                        "second grade")) %>%
  select(subid, sitting_id, grade, battery_id, test_order, num_completed) 

gonogo.raw <- bind_rows(read_csv("data/fall 2015/b301_t463_09.28.15_00.36.59.csv"),
                        read_csv("data/fall 2015/b299_t463_09.28.15_18.57.41.csv"))
## Warning: 65404 problems parsing 'data/fall 2015/
## b301_t463_09.28.15_00.36.59.csv'. See problems(...) for more details.
## Warning: 3984 problems parsing 'data/fall 2015/
## b299_t463_09.28.15_18.57.41.csv'. See problems(...) for more details.
ravens.raw <- bind_rows(read_csv("data/fall 2015/b301_t464_09.28.15_00.36.59.csv"),
                        read_csv("data/fall 2015/b300_t464_09.28.15_18.57.50.csv"))
## Warning: 3604 problems parsing 'data/fall 2015/
## b301_t464_09.28.15_00.36.59.csv'. See problems(...) for more details.
## Warning: 572 problems parsing 'data/fall 2015/
## b300_t464_09.28.15_18.57.50.csv'. See problems(...) for more details.
swm.raw <- bind_rows(read_csv("data/fall 2015/b301_t467_09.28.15_00.37.00.csv"),
                     read_csv("data/fall 2015/b302_t467_09.28.15_18.57.56.csv"))
## Warning: 5190 problems parsing 'data/fall 2015/
## b301_t467_09.28.15_00.37.00.csv'. See problems(...) for more details.
## Warning: 660 problems parsing 'data/fall 2015/
## b302_t467_09.28.15_18.57.56.csv'. See problems(...) for more details.

1.1 Go / No-Go Task

gonogo <- gonogo.raw %>%
  filter(sitting_id %in% sittings$sitting_id) %>%
  left_join(sittings, by = "sitting_id") %>%
  select(subid, grade, trial, stim, correct, rt, accuracy, responseAssign, rtCall)

Accuracy.

gonogo.summary <- gonogo %>%
  group_by(subid, grade) %>%
  summarise(accuracy = mean(accuracy, na.rm=TRUE))
  
ms <- gonogo.summary %>%
  group_by(grade) %>%
  summarise(accuracy = mean(accuracy))

gonogo.summary %>%
  ggplot(aes(x=accuracy)) + 
  geom_histogram(binwidth = .05) +
  facet_grid(.~grade) + 
  geom_vline(xintercept = .5, lty = 3) +
  xlim(c(0,1)) + 
  geom_vline(data = ms, aes(xintercept = accuracy), 
             col = "red", lty = 2)

RT.

ms <- gonogo %>%
  filter(rt > 0 & accuracy == 1) %>%
  group_by(subid, grade) %>%
  summarise(rt = mean(rt, na.rm=TRUE)) %>%
  group_by(grade) %>%
  summarise(rt = mean(rt))

gonogo %>%
  filter(rt > 0 & accuracy == 1) %>%
  group_by(subid, grade) %>%
  summarise(rt = mean(rt, na.rm=TRUE)) %>%
  ggplot(aes(x=rt)) + 
  geom_histogram(binwidth = 50) +
  facet_grid(.~grade) + 
  geom_vline(data = ms, aes(xintercept = rt), 
             col = "red", lty = 2)

1.2 Spatial WM

Data processing.

swm <- swm.raw %>%
  filter(sitting_id %in% sittings$sitting_id,
         type == "test") %>%
  left_join(sittings, by = "sitting_id") %>%
  filter(type == "test") %>%
  select(subid, grade, trial, capacity, correct)

Mean level (same measure as in Zenith study).

swm.summary <- swm %>%
  group_by(subid, grade) %>%
  summarise(capacity = mean(capacity, na.rm=TRUE))
  
ms <- swm.summary %>%
  group_by(grade) %>%
  summarise(capacity = mean(capacity))
  
swm.summary %>%
  ggplot(aes(x=capacity)) + 
  geom_histogram(binwidth = .5) +
  facet_grid(.~grade) +
  xlim(c(1,8)) +
  geom_vline(data = ms, aes(xintercept = capacity), 
             col = "red", lty = 2)

1.3 Raven’s

Actually a matrix reasoning equivalent.

ravens <- ravens.raw %>%
  filter(sitting_id %in% sittings$sitting_id,
         type == "test") %>%
  left_join(sittings, by = "sitting_id") %>%
  filter(type == "test") %>%
  select(subid, grade, trial, correct)

Mean level (same measure as in Zenith study).

ravens.summary <- ravens %>% 
  group_by(subid, grade) %>%
    summarise(correct = sum(correct, na.rm=TRUE))

ms <- ravens.summary %>%
  group_by(grade) %>%
  summarise(correct = mean(correct))
  
ravens.summary %>%
  ggplot(aes(x=correct)) + 
  geom_histogram(binwidth = 1) +
  facet_grid(.~grade) +
  geom_vline(data = ms, aes(xintercept = correct), 
             col = "red", lty = 2)

1.4 Individuals

subs <- ravens.summary %>% 
  left_join(gonogo.summary) %>%
  left_join(swm.summary) %>%
  rename(ravens = correct, 
         gonogo = accuracy,
         swm = capacity) %>%
  filter(!is.na(ravens) & !is.na(gonogo) & !is.na(swm))
## Joining by: c("subid", "grade")
## Joining by: c("subid", "grade")
subs
## Source: local data frame [177 x 5]
## Groups: subid [177]
## 
##       subid       grade ravens    gonogo      swm
##       (chr)       (chr)  (int)     (dbl)    (dbl)
## 1  S1-02-02 first grade      6 0.5769231 2.956522
## 2  S1-02-03 first grade      3 0.8153846 1.833333
## 3  S1-02-08 first grade      4 0.7615385 1.625000
## 4  S1-02-17 first grade      5 0.4307692 1.500000
## 5  S1-04-01 first grade      9 0.9307692 4.375000
## 6  S1-04-03 first grade      7 0.7384615 3.437500
## 7  S1-04-04 first grade      6 0.7230769 2.416667
## 8  S1-04-08 first grade      8 0.8692308 2.750000
## 9  S1-04-11 first grade      8 0.7538462 1.416667
## 10 S1-04-17 first grade     17 0.5384615 4.117647
## ..      ...         ...    ...       ...      ...

Correlation plot.

ggcorplot(subs %>% select(ravens, gonogo, swm))

Correlations.

kable(cor(subs %>% ungroup %>% select(ravens, gonogo, swm)), digits = 2)
ravens gonogo swm
ravens 1.00 0.26 0.2
gonogo 0.26 1.00 0.4
swm 0.20 0.40 1.0
cor.test(subs$ravens, subs$gonogo)
## 
##  Pearson's product-moment correlation
## 
## data:  subs$ravens and subs$gonogo
## t = 3.6062, df = 175, p-value = 0.0004051
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1201645 0.3951741
## sample estimates:
##       cor 
## 0.2630035
cor.test(subs$ravens, subs$swm)
## 
##  Pearson's product-moment correlation
## 
## data:  subs$ravens and subs$swm
## t = 2.6393, df = 175, p-value = 0.009058
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.04958677 0.33353141
## sample estimates:
##       cor 
## 0.1956563
cor.test(subs$gonogo, subs$swm)
## 
##  Pearson's product-moment correlation
## 
## data:  subs$gonogo and subs$swm
## t = 5.8332, df = 175, p-value = 2.573e-08
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2721602 0.5200179
## sample estimates:
##       cor 
## 0.4034642

2 Math tasks

Read in data.

pv <- read.csv("data/fall 2015/2015_PVNumerals.csv") %>%
  select(subnum, pvAvg) %>%
  rename(subid = subnum)
wg <- read.csv("data/fall 2015/2015_WGArith.csv") %>%
  select(subnum, arithmeticTotal, arithmeticAverage) %>%
  rename(subid = subnum)
wj <- read.csv("data/fall 2015/2015_WOODCOCK.csv") %>%
  select(subnum, woodcockTotal) %>%
  rename(subid = subnum)

Merge with sub data.

d <- left_join(subs, pv) %>% 
  left_join(wg) %>% 
  left_join(wj)
## Joining by: "subid"
## Warning in left_join_impl(x, y, by$x, by$y): joining factor and character
## vector, coercing into character vector
## Joining by: "subid"
## Warning in left_join_impl(x, y, by$x, by$y): joining factor and character
## vector, coercing into character vector
## Joining by: "subid"
## Warning in left_join_impl(x, y, by$x, by$y): joining factor and character
## vector, coercing into character vector

Now plot each task individually.

2.1 Place value.

pv.summary <- d %>% 
  group_by(subid, grade) %>%
    summarise(correct = sum(pvAvg, na.rm=TRUE))

ms <- pv.summary %>%
  group_by(grade) %>%
  summarise(correct = mean(correct))
  
pv.summary %>%
  ggplot(aes(x=correct)) + 
  geom_histogram(binwidth = .1) +
  facet_grid(.~grade) +
  geom_vline(data = ms, aes(xintercept = correct), 
             col = "red", lty = 2) + 
  ggtitle("Place Value Accuracy") + 
  xlab("Proportion correct")

2.2 Arithmetic

wg.summary <- d %>% 
  group_by(subid, grade) %>%
    summarise(correct = sum(arithmeticTotal, na.rm=TRUE))

ms <- wg.summary %>%
  group_by(grade) %>%
  summarise(correct = mean(correct))
  
wg.summary %>%
  ggplot(aes(x=correct)) + 
  geom_histogram(binwidth = 1) +
  facet_grid(.~grade) +
  geom_vline(data = ms, aes(xintercept = correct), 
             col = "red", lty = 2) + 
  ggtitle("Arithmetic Accuracy") + 
  xlab("Total Problems Correct")

2.3 Woodcock-Johnson III

wj.summary <- d %>% 
  group_by(subid, grade) %>%
    summarise(correct = sum(woodcockTotal, na.rm=TRUE))

ms <- wj.summary %>%
  group_by(grade) %>%
  summarise(correct = mean(correct))
  
wj.summary %>%
  ggplot(aes(x=correct)) + 
  geom_histogram(binwidth = 1) +
  facet_grid(.~grade) +
  geom_vline(data = ms, aes(xintercept = correct), 
             col = "red", lty = 2) + 
  ggtitle("Woodcock-Johnson III Accuracy") + 
  xlab("Total Problems Correct")

2.4 Relations between math measures

Plots.

ggcorplot(d %>% select(woodcockTotal, arithmeticTotal, pvAvg))

Correlations.

kable(cor(d %>% ungroup %>% 
            select(woodcockTotal, arithmeticTotal, pvAvg)), digits = 2)
woodcockTotal arithmeticTotal pvAvg
woodcockTotal 1.00 0.75 0.62
arithmeticTotal 0.75 1.00 0.66
pvAvg 0.62 0.66 1.00
cor.test(d$woodcockTotal, d$arithmeticTotal)
## 
##  Pearson's product-moment correlation
## 
## data:  d$woodcockTotal and d$arithmeticTotal
## t = 14.932, df = 175, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.6755959 0.8069196
## sample estimates:
##       cor 
## 0.7485072
cor.test(d$woodcockTotal, d$pvAvg)
## 
##  Pearson's product-moment correlation
## 
## data:  d$woodcockTotal and d$pvAvg
## t = 10.329, df = 175, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5146463 0.6994376
## sample estimates:
##       cor 
## 0.6154293
cor.test(d$arithmeticTotal, d$pvAvg)
## 
##  Pearson's product-moment correlation
## 
## data:  d$arithmeticTotal and d$pvAvg
## t = 11.468, df = 175, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5618107 0.7318242
## sample estimates:
##       cor 
## 0.6550306

3 Relations between all measures.

kable(cor(d %>% ungroup %>% 
            select(ravens, gonogo, swm, 
                   woodcockTotal, arithmeticTotal, pvAvg)), digits = 2)
ravens gonogo swm woodcockTotal arithmeticTotal pvAvg
ravens 1.00 0.26 0.20 0.26 0.27 0.34
gonogo 0.26 1.00 0.40 0.28 0.39 0.31
swm 0.20 0.40 1.00 0.23 0.38 0.32
woodcockTotal 0.26 0.28 0.23 1.00 0.75 0.62
arithmeticTotal 0.27 0.39 0.38 0.75 1.00 0.66
pvAvg 0.34 0.31 0.32 0.62 0.66 1.00
cor.test(d$ravens, d$woodcockTotal)
## 
##  Pearson's product-moment correlation
## 
## data:  d$ravens and d$woodcockTotal
## t = 3.6212, df = 175, p-value = 0.0003839
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1212426 0.3960969
## sample estimates:
##       cor 
## 0.2640216
cor.test(d$ravens, d$arithmeticTotal)
## 
##  Pearson's product-moment correlation
## 
## data:  d$ravens and d$arithmeticTotal
## t = 3.7745, df = 175, p-value = 0.0002193
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1322249 0.4054656
## sample estimates:
##       cor 
## 0.2743743
cor.test(d$ravens, d$pvAvg)
## 
##  Pearson's product-moment correlation
## 
## data:  d$ravens and d$pvAvg
## t = 4.7257, df = 175, p-value = 4.693e-06
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1987715 0.4610329
## sample estimates:
##      cor 
## 0.336409
cor.test(d$swm, d$woodcockTotal)
## 
##  Pearson's product-moment correlation
## 
## data:  d$swm and d$woodcockTotal
## t = 3.1745, df = 175, p-value = 0.001774
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.08890637 0.36817537
## sample estimates:
##       cor 
## 0.2333469
cor.test(d$swm, d$arithmeticTotal)
## 
##  Pearson's product-moment correlation
## 
## data:  d$swm and d$arithmeticTotal
## t = 5.4907, df = 175, p-value = 1.39e-07
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2499835 0.5024395
## sample estimates:
##      cor 
## 0.383349
cor.test(d$swm, d$pvAvg)
## 
##  Pearson's product-moment correlation
## 
## data:  d$swm and d$pvAvg
## t = 4.4026, df = 175, p-value = 1.857e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1764955 0.4426583
## sample estimates:
##       cor 
## 0.3157754
cor.test(d$gonogo, d$woodcockTotal)
## 
##  Pearson's product-moment correlation
## 
## data:  d$gonogo and d$woodcockTotal
## t = 3.9222, df = 175, p-value = 0.0001259
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1427440 0.4143856
## sample estimates:
##       cor 
## 0.2842596
cor.test(d$gonogo, d$arithmeticTotal)
## 
##  Pearson's product-moment correlation
## 
## data:  d$gonogo and d$arithmeticTotal
## t = 5.5334, df = 175, p-value = 1.13e-07
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2527773 0.5046656
## sample estimates:
##       cor 
## 0.3858901
cor.test(d$gonogo, d$pvAvg)
## 
##  Pearson's product-moment correlation
## 
## data:  d$gonogo and d$pvAvg
## t = 4.3796, df = 175, p-value = 2.043e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1748956 0.4413300
## sample estimates:
##       cor 
## 0.3142885