Data analysis of toddler uncertainty signals study.

Preliminaries.

1 Eyetracker task

Filter unfamiliar trials (parents reported that child did not know word), and kids who performed below chance. Two participants dropped for below-chance performance (109 and 70).

rm(list=ls())
load("data_et.RData")

#remove unfamiliar trials.
#"trans" = gaze switches
d_et_filt <- d_et %>% 
  dplyr::filter(familiarity != 0, trans != 0)

#remove participants who performed at chance.
mss_et_acc <-  d_et_filt
mss_et_acc$acc <- as.numeric(as.character(mss_et_acc$acc))
mss_et_acc <- mss_et_acc %>%
  group_by(ID)%>%
  summarise(acc = mean(acc))%>%
  mutate(drop_acc = acc < .5)

drop_acc <- mss_et_acc$ID[mss_et_acc$drop_acc == TRUE]

d_et_filt <- d_et_filt %>% 
  dplyr::filter(!ID %in% drop_acc)

1.1 Accuracy

Get a dataframe for looking at accuracy by similarity.

mss_et_acc_tt <-  d_et_filt 
mss_et_acc_tt$acc <- as.numeric(as.character(mss_et_acc_tt$acc))

#get mean accuracy by similarity condition.
mss_et_acc_t <- mss_et_acc_tt %>%
  group_by(ID, similar)%>%
  summarise(acc = mean(acc))%>%
  spread(similar, acc)

mss_et_acc_r <- mss_et_acc_tt %>%
  group_by(ID)%>%
  summarise(acc = mean(acc))

accet <- describeBy(mss_et_acc_r$acc)
accet$mean
## [1] 0.8364131
accet$sd
## [1] 0.1258933
accet$min
## [1] 0.5
accet$max
## [1] 1

T-test for effect of similarity on accuracy.

t.test(mss_et_acc_t$similar, 
       mss_et_acc_t$dissimilar, paired = TRUE)
## 
##  Paired t-test
## 
## data:  mss_et_acc_t$similar and mss_et_acc_t$dissimilar
## t = -3.7353, df = 64, p-value = 0.0004015
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.15692094 -0.04756013
## sample estimates:
## mean of the differences 
##              -0.1022405
similar <- psych::describe(mss_et_acc_t$similar)
dissimilar <- psych::describe(mss_et_acc_t$dissimilar)

similar
##    vars  n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 68 0.79 0.18   0.82     0.8 0.22 0.2   1   0.8 -0.61    -0.08 0.02
dissimilar
##    vars  n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 66 0.89 0.14   0.95    0.91 0.07 0.5   1   0.5 -1.13      0.4 0.02
#get effect size
cohensd_acc <- abs((similar$mean - dissimilar$mean)/((similar$sd + dissimilar$sd)/2))
cohensd_acc
## [1] 0.6368231

1.2 Switches

Set up a dataframe with switches averaged by accuracy and similiarity within participants.

mss_et_acc <-  d_et_filt %>%  #filter(d_et_filt, !is.na(first_fix)) to exclude trials with no fixations
  mutate(acc = ifelse(acc == 1, "acc", "inacc")) 

#get average gaze switches for three conditions: accurate-similar, accurate-dissimilar, and inaccurate.
mss_et_inacc <-  mss_et_acc%>%
  group_by(ID, acc)%>%
  summarise(trans = mean(trans))%>%
  spread(acc, trans)%>%
  select(-acc)

mss_et_acc <-  mss_et_acc%>%
  group_by(ID, acc)%>%
  summarise(trans = mean(trans))%>%
  spread(acc, trans)

mss_et_sim <-  d_et_filt %>%
  dplyr::group_by(ID, acc, similar)%>%
  dplyr::summarise(trans = mean(trans))%>%
  dplyr::filter(acc == 1)%>%
  tidyr::spread(similar, trans)%>%
  dplyr::mutate(similar_acc = similar)%>%
  dplyr::mutate(dissimilar_acc = dissimilar)

mss_et_aov <- mss_et_inacc %>%
  left_join(mss_et_sim)%>%
  dplyr::filter(!is.na(similar_acc),
         !is.na(dissimilar_acc),
         !is.na(inacc))%>%
  gather("trial_type", "trans", inacc:dissimilar_acc) %>%
  filter(trial_type != "acc",
         trial_type != "similar",
         trial_type != "dissimilar")


#How often do children answer without fixating on an ROI?

nofix <- d_et_filt %>%
  filter(is.na(first_fix))

length(nofix$ID)
## [1] 0
length(unique(nofix$ID))
## [1] 0

1.2.1 Repeated measures ANOVA

Repeated-measures ANOVA with trial type (similar and accurate, dissimilar and accurate, and inaccurate) as the independent variable.

ET.aov <- with(mss_et_aov,
                   aov(trans ~ trial_type +
                       Error(ID /trial_type))) #add error term for ID for repeated measures
summary(ET.aov)
## 
## Error: ID
##           Df Sum Sq Mean Sq F value Pr(>F)
## Residuals 52  42.26  0.8128               
## 
## Error: ID:trial_type
##             Df Sum Sq Mean Sq F value Pr(>F)  
## trial_type   2   4.74  2.3699   4.763 0.0105 *
## Residuals  104  51.74  0.4975                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ezANOVA(
mss_et_aov
, trans
, ID
, within = trial_type
, within_full = NULL
, within_covariates = NULL
, between = NULL
, between_covariates = NULL
, observed = NULL
, diff = NULL
, reverse_diff = FALSE
, type = 2
, white.adjust = FALSE
, detailed = FALSE
, return_aov = FALSE
)
## $ANOVA
##       Effect DFn DFd        F          p p<.05        ges
## 2 trial_type   2 104 4.763292 0.01048721     * 0.04799922
## 
## $`Mauchly's Test for Sphericity`
##       Effect         W           p p<.05
## 2 trial_type 0.7960008 0.002973679     *
## 
## $`Sphericity Corrections`
##       Effect       GGe     p[GG] p[GG]<.05       HFe      p[HF] p[HF]<.05
## 2 trial_type 0.8305653 0.0155596         * 0.8546072 0.01471085         *
#get means and CIs for plot.
mss_et_aov_p <- mss_et_aov %>%
  group_by(trial_type)%>%
  multi_boot_standard(col = "trans", na.rm = TRUE)

mss_et_aov_p$trial_type <- factor(mss_et_aov_p$trial_type, 
                            levels = c("dissimilar_acc","similar_acc","inacc"))

ggplot(mss_et_aov_p, aes(x = factor(trial_type), y = mean, fill = trial_type)) + geom_bar(stat = "identity") + 
  geom_linerange(aes(ymin = ci_lower, ymax = ci_upper), 
             position = position_dodge(width = .9)) +
  xlab("Trial Type") + 
  ylab("Mean Switch Count")  +  
  theme(panel.grid = element_blank()) + #no gridlines
  scale_fill_grey() #grayscale

1.2.2 T-tests

t.test(subset(mss_et_aov, trial_type=="inacc")$trans, 
       subset(mss_et_aov, trial_type=="similar_acc")$trans, paired = TRUE)
## 
##  Paired t-test
## 
## data:  subset(mss_et_aov, trial_type == "inacc")$trans and subset(mss_et_aov, trial_type == "similar_acc")$trans
## t = 0.38525, df = 52, p-value = 0.7016
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.2526279  0.3726788
## sample estimates:
## mean of the differences 
##              0.06002546
t.test(subset(mss_et_aov, trial_type=="inacc")$trans, 
       subset(mss_et_aov, trial_type=="dissimilar_acc")$trans, paired = TRUE)
## 
##  Paired t-test
## 
## data:  subset(mss_et_aov, trial_type == "inacc")$trans and subset(mss_et_aov, trial_type == "dissimilar_acc")$trans
## t = 2.6703, df = 52, p-value = 0.01009
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.09756006 0.68757022
## sample estimates:
## mean of the differences 
##               0.3925651
t.test(subset(mss_et_aov, trial_type=="similar_acc")$trans, 
       subset(mss_et_aov, trial_type=="dissimilar_acc")$trans, paired = TRUE)
## 
##  Paired t-test
## 
## data:  subset(mss_et_aov, trial_type == "similar_acc")$trans and subset(mss_et_aov, trial_type == "dissimilar_acc")$trans
## t = 3.2552, df = 52, p-value = 0.001996
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.1275508 0.5375286
## sample estimates:
## mean of the differences 
##               0.3325397
#get effect sizes
inacc_et <- psych::describe(subset(mss_et_aov, trial_type=="inacc")$trans) 
sim_acc_et <- psych::describe(subset(mss_et_aov, trial_type=="similar_acc")$trans)
dissim_acc_et <- psych::describe(subset(mss_et_aov, trial_type=="dissimilar_acc")$trans)

cohensd_inacc_sim_acc_et <- abs((inacc_et$mean - sim_acc_et$mean)/((inacc_et$sd + sim_acc_et$sd)/2))
cohensd_inacc_sim_acc_et
## [1] 0.06828084
cohensd_inacc_dissim_acc_et <- abs((inacc_et$mean - dissim_acc_et$mean)/((inacc_et$sd + dissim_acc_et$sd)/2))
cohensd_inacc_dissim_acc_et
## [1] 0.5257557
cohensd_sim_acc_dissim_acc_et <- abs((sim_acc_et$mean - dissim_acc_et$mean)/((sim_acc_et$sd + dissim_acc_et$sd)/2))
cohensd_sim_acc_dissim_acc_et
## [1] 0.5527001

Do the number of transitions differ based on whether the correct one was fixated first? No.

mss_et_ff <-  filter(d_et_filt, !is.na(first_fix))%>%
  group_by(ID, first_fix)%>%
  summarise(trans = mean(trans))%>%
  spread(first_fix, trans)%>%
  filter(!is.na(correct) & !is.na(incorrect))

t.test(mss_et_ff$correct, mss_et_ff$incorrect, paired = TRUE)
## 
##  Paired t-test
## 
## data:  mss_et_ff$correct and mss_et_ff$incorrect
## t = 3.4426, df = 63, p-value = 0.001029
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.1395943 0.5258940
## sample estimates:
## mean of the differences 
##               0.3327442
mss_et_d <-  filter(d_et_filt, !is.na(first_fix))%>%
  group_by(ID, first_fix)%>%
  summarise(trans = mean(trans))

describeBy(mss_et_d$trans, mss_et_d$first_fix)
## $correct
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 65 2.01 0.74      2    1.92 0.59   1   5     4 1.82     4.75 0.09
## 
## $incorrect
##    vars  n mean   sd median trimmed  mad min  max range skew kurtosis   se
## X1    1 68 1.71 0.54   1.62    1.66 0.56   1 3.29  2.29 0.92     0.41 0.07
## 
## attr(,"call")
## by.default(data = x, INDICES = group, FUN = describe, type = type)

Based on trial type?

mss_trans_acc <-  d_et_filt %>%
  mutate(acc = ifelse(acc == 1, "acc", "inacc"))%>%
  filter(!is.na(first_fix))

#get average gaze switches for three conditions: accurate-similar, accurate-dissimilar, and inaccurate.
mss_trans_inacc <-  mss_trans_acc%>%
  filter(!is.na(first_fix))%>%
  group_by(ID, acc, first_fix)%>%
  summarise(trans = mean(trans))%>%
  spread(acc, trans)%>%
  select(-acc)%>%
  spread(first_fix, inacc)%>%
  filter(!is.na(correct), !is.na(incorrect))%>%
  gather("first_fix", "inacc", correct:incorrect)

mss_trans_sim <-  d_et_filt %>%
  group_by(ID, acc, similar, first_fix)%>%
  summarise(trans = mean(trans))%>%
  filter(acc == 1, !is.na(first_fix))%>%
  spread(similar, trans)%>%
  mutate(similar_acc = similar)%>%
  mutate(dissimilar_acc = dissimilar)%>%
  select(-similar, -dissimilar)

mss_trans_sim_acc <- mss_trans_sim %>%
  select(-dissimilar_acc)%>%
  spread(first_fix, similar_acc)%>%
  filter(!is.na(correct), !is.na(incorrect))%>%
  gather("first_fix", "similar_acc", correct:incorrect)

mss_trans_dissim_acc <- mss_trans_sim %>%
  select(-similar_acc)%>%
  spread(first_fix, dissimilar_acc)%>%
  filter(!is.na(correct), !is.na(incorrect))%>%
  gather("first_fix", "dissimilar_acc", correct:incorrect)

mss_trans_aov <- mss_trans_inacc %>%
  inner_join(mss_trans_sim_acc)%>%
  select(-acc)%>%
  inner_join(mss_trans_dissim_acc)%>%
  select(-acc)%>%
  gather("trial_type", "trans", inacc:dissimilar_acc)
mss_trans_aov_p <- mss_trans_aov %>%
  group_by(first_fix, trial_type)%>%
  multi_boot_standard(col = "trans", na.rm = TRUE)

ggplot(mss_trans_aov_p, aes(x = factor(first_fix), y = mean, fill = first_fix)) + geom_bar(stat = "identity") + 
  geom_linerange(aes(ymin = ci_lower, ymax = ci_upper), 
             position = position_dodge(width = .9)) +
  xlab("First Fixation") + 
  ylab("Mean Switch Count")  +  
  facet_grid(~trial_type) +
  theme(panel.grid = element_blank()) + #no gridlines
  scale_fill_grey() #grayscale

library(car)
Anova(lm(trans ~ first_fix * trial_type, data=mss_trans_aov), type=3)
## Anova Table (Type III tests)
## 
## Response: trans
##                      Sum Sq  Df  F value  Pr(>F)    
## (Intercept)          92.470   1 117.6127 < 2e-16 ***
## first_fix             3.372   1   4.2884 0.04052 *  
## trial_type            0.719   2   0.4574 0.63405    
## first_fix:trial_type  1.393   2   0.8858 0.41505    
## Residuals            94.347 120                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(lm(trans ~ first_fix * trial_type, data=mss_trans_aov))
## 
## Call:
## lm(formula = trans ~ first_fix * trial_type, data = mss_trans_aov)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.2619 -0.5817 -0.0984  0.4563  3.7897 
## 
## Coefficients:
##                                          Estimate Std. Error t value
## (Intercept)                               2.09841    0.19349  10.845
## first_fixincorrect                       -0.56667    0.27364  -2.071
## trial_typeinacc                           0.16349    0.27364   0.597
## trial_typesimilar_acc                    -0.09524    0.27364  -0.348
## first_fixincorrect:trial_typeinacc        0.51508    0.38698   1.331
## first_fixincorrect:trial_typesimilar_acc  0.26032    0.38698   0.673
##                                          Pr(>|t|)    
## (Intercept)                                <2e-16 ***
## first_fixincorrect                         0.0405 *  
## trial_typeinacc                            0.5513    
## trial_typesimilar_acc                      0.7284    
## first_fixincorrect:trial_typeinacc         0.1857    
## first_fixincorrect:trial_typesimilar_acc   0.5024    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8867 on 120 degrees of freedom
## Multiple R-squared:  0.08683,    Adjusted R-squared:  0.04878 
## F-statistic: 2.282 on 5 and 120 DF,  p-value: 0.0507

2 Touchscreen task

filter fast and slow RTs, missing data, unfamiliar trials, and kids who performed below chance. Two participants dropped for chance performance (70 and 89).

load("data_ts.RData")

#filter fast and slow RTs, missing data, and unfamiliar trials.
top_bound <- mean(log(d_ts$RT)) + 3*sd(log(d_ts$RT))
bottom_bound <- mean(log(d_ts$RT)) - 3*sd(log(d_ts$RT))

d_filt_rt <- d_ts %>%
  dplyr::filter(log(RT) < top_bound, 
         log(RT) > bottom_bound,
         familiarity != 0)

#remove participants who performed below chance.
mss_ts_acc <-  d_filt_rt
mss_ts_acc$acc <- as.numeric(as.character(mss_ts_acc$acc))
mss_ts_acc <- mss_ts_acc %>%
  group_by(ID)%>%
  summarise(acc = mean(acc))%>%
  mutate(drop_acc = acc < .5)

drop_acc_ts <- mss_ts_acc$ID[mss_ts_acc$drop_acc == TRUE]

d_filt_rt <- d_filt_rt %>% 
  dplyr::filter(!ID %in% drop_acc_ts)

2.1 Accuracy

Get a dataframe for looking at accuracy by similarity.

mss_ts_acc_tt <-  d_filt_rt%>%
  group_by(ID, similar)

mss_ts_acc_tt$acc <- as.numeric(as.character(mss_ts_acc_tt$acc))

mss_ts_acc_t <- mss_ts_acc_tt %>%
  summarise(acc = mean(acc))%>%
  spread(similar, acc)

mss_ts_acc_r <- mss_ts_acc_tt %>%
  group_by(ID)%>%
  summarise(acc = mean(acc))

accts <- describeBy(mss_ts_acc_r$acc)
accts$mean
## [1] 0.7793548
accts$sd
## [1] 0.1304892
accts$min
## [1] 0.5
accts$max
## [1] 0.95

T-test for effect of similarity on accuracy.

t.test(mss_ts_acc_t$similar, 
       mss_ts_acc_t$dissimilar, paired = TRUE)
## 
##  Paired t-test
## 
## data:  mss_ts_acc_t$similar and mss_ts_acc_t$dissimilar
## t = -7.1675, df = 70, p-value = 6.178e-10
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.17142088 -0.09678838
## sample estimates:
## mean of the differences 
##              -0.1341046
similar <- psych::describe(mss_ts_acc_t$similar)
dissimilar <- psych::describe(mss_ts_acc_t$dissimilar)
similar
##    vars  n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 71 0.71 0.17   0.75    0.72 0.22 0.4 0.9   0.5 -0.45    -1.13 0.02
dissimilar
##    vars  n mean   sd median trimmed  mad  min max range  skew kurtosis
## X1    1 71 0.85 0.14   0.89    0.86 0.16 0.43   1  0.57 -0.73    -0.21
##      se
## X1 0.02
#get effect size.
cohensd_acc <- abs((similar$mean - dissimilar$mean)/((similar$sd + dissimilar$sd)/2))
cohensd_acc
## [1] 0.8777602

2.2 RTs

Set up a dataframe with RTs averaged by accuracy and similiarity within participants.

mss_ts_acc <-  d_filt_rt

mss_ts_acc <- mss_ts_acc %>% 
  mutate(acc = ifelse(acc == 1, "acc", "inacc")) 

#get average RTs for three conditions: accurate-similar, accurate-dissimilar, and inaccurate.
mss_ts_inacc <-  mss_ts_acc%>%
  group_by(ID, acc)%>%
  summarise(RT = mean(RT))%>%
  spread(acc, RT)%>%
  select(-acc)

mss_ts_acc <-  mss_ts_acc%>%
  group_by(ID, acc)%>%
  summarise(RT = mean(RT))%>%
  spread(acc, RT)

mss_ts_sim <-  d_filt_rt %>%
  dplyr::group_by(ID, acc, similar)%>%
  dplyr::summarise(RT = mean(RT))%>%
  dplyr::filter(acc == 1)%>%
  tidyr::spread(similar, RT)%>%
  dplyr::mutate(similar_acc = similar)%>%
  dplyr::mutate(dissimilar_acc = dissimilar)

mss_ts_aov <- mss_ts_inacc %>%
  left_join(mss_ts_sim)%>%
  dplyr::filter(!is.na(similar_acc),
         !is.na(dissimilar_acc),
         !is.na(inacc))%>%
  gather("trial_type", "RT", inacc:dissimilar_acc) %>%
  filter(trial_type != "acc",
         trial_type != "similar",
         trial_type != "dissimilar")

2.2.1 Repeated-measures ANOVA

Repeated-measures ANOVA with trial type (similar and accurate, dissimilar and accurate, and inaccurate) as the independent variable.

TS.aov <- with(mss_ts_aov,
                   aov(RT ~ trial_type +
                       Error(ID /trial_type))) #add error term for ID for repeated measures
summary(TS.aov)
## 
## Error: ID
##           Df    Sum Sq Mean Sq F value Pr(>F)
## Residuals 70 381085269 5444075               
## 
## Error: ID:trial_type
##             Df    Sum Sq  Mean Sq F value   Pr(>F)    
## trial_type   2  40290557 20145279   13.68 3.75e-06 ***
## Residuals  140 206196345  1472831                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ezANOVA(
mss_ts_aov
, RT
, ID
, within = trial_type
, within_full = NULL
, within_covariates = NULL
, between = NULL
, between_covariates = NULL
, observed = NULL
, diff = NULL
, reverse_diff = FALSE
, type = 2
, white.adjust = FALSE
, detailed = FALSE
, return_aov = FALSE
)
## $ANOVA
##       Effect DFn DFd        F            p p<.05        ges
## 2 trial_type   2 140 13.67793 3.750577e-06     * 0.06420068
## 
## $`Mauchly's Test for Sphericity`
##       Effect         W           p p<.05
## 2 trial_type 0.8189084 0.001015358     *
## 
## $`Sphericity Corrections`
##       Effect       GGe        p[GG] p[GG]<.05       HFe        p[HF]
## 2 trial_type 0.8466744 1.590695e-05         * 0.8654191 1.332696e-05
##   p[HF]<.05
## 2         *

2.2.2 T-tests

t.test(subset(mss_ts_aov, trial_type=="inacc")$RT, 
       subset(mss_ts_aov, trial_type=="similar_acc")$RT, paired = TRUE)
## 
##  Paired t-test
## 
## data:  subset(mss_ts_aov, trial_type == "inacc")$RT and subset(mss_ts_aov, trial_type == "similar_acc")$RT
## t = 4.4631, df = 70, p-value = 3.017e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   546.6119 1429.8130
## sample estimates:
## mean of the differences 
##                988.2125
t.test(subset(mss_ts_aov, trial_type=="inacc")$RT, 
       subset(mss_ts_aov, trial_type=="dissimilar_acc")$RT, paired = TRUE)
## 
##  Paired t-test
## 
## data:  subset(mss_ts_aov, trial_type == "inacc")$RT and subset(mss_ts_aov, trial_type == "dissimilar_acc")$RT
## t = 3.6944, df = 70, p-value = 0.0004336
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   385.946 1291.573
## sample estimates:
## mean of the differences 
##                838.7598
t.test(subset(mss_ts_aov, trial_type=="similar_acc")$RT, 
       subset(mss_ts_aov, trial_type=="dissimilar_acc")$RT, paired = TRUE)
## 
##  Paired t-test
## 
## data:  subset(mss_ts_aov, trial_type == "similar_acc")$RT and subset(mss_ts_aov, trial_type == "dissimilar_acc")$RT
## t = -0.96687, df = 70, p-value = 0.3369
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -457.7405  158.8351
## sample estimates:
## mean of the differences 
##               -149.4527
inacc_ts <- psych::describe(subset(mss_ts_aov, trial_type=="inacc")$RT) 
sim_acc_ts <- psych::describe(subset(mss_ts_aov, trial_type=="similar_acc")$RT)
dissim_acc_ts <- psych::describe(subset(mss_ts_aov, trial_type=="dissimilar_acc")$RT)

#get effect sizes.
cohensd_inacc_sim_acc_ts <- abs((inacc_ts$mean - sim_acc_ts$mean)/((inacc_ts$sd + sim_acc_ts$sd)/2))
cohensd_inacc_sim_acc_ts
## [1] 0.5932835
cohensd_inacc_dissim_acc_ts <- abs((inacc_ts$mean - dissim_acc_ts$mean)/((inacc_ts$sd + dissim_acc_ts$sd)/2))
cohensd_inacc_dissim_acc_ts
## [1] 0.4536602
cohensd_sim_acc_dissim_acc_ts <- abs((sim_acc_ts$mean - dissim_acc_ts$mean)/((sim_acc_ts$sd + dissim_acc_ts$sd)/2))
cohensd_sim_acc_dissim_acc_ts
## [1] 0.1113044

3 Accuracy across ET and TS tasks for plot

4 Does accuracy on a given trial in the TS task predict accuracy on the same trial in the ET task?

#get matrix with trial-level accuracy for both tasks
accmat <- mss_et_acc_tt %>%
  select(ID, acc, trial)%>%
  mutate(acc_et = acc)%>%
  select(ID, trial, acc_et)%>%
  left_join(mss_ts_acc_tt)%>%
  mutate(acc_ts = acc)%>%
  select(ID, trial, acc_et, acc_ts)

summary(glmer(acc_et ~ acc_ts + 
                (1|ID) + 
                (1|trial), #behavior item
              data = accmat, 
              family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: acc_et ~ acc_ts + (1 | ID) + (1 | trial)
##    Data: accmat
## 
##      AIC      BIC   logLik deviance df.resid 
##    620.3    638.5   -306.1    612.3      697 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.7514  0.3436  0.3813  0.4231  0.7516 
## 
## Random effects:
##  Groups Name        Variance Std.Dev.
##  ID     (Intercept) 0.09798  0.3130  
##  trial  (Intercept) 0.08428  0.2903  
## Number of obs: 701, groups:  ID, 60; trial, 20
## 
## Fixed effects:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)   1.0632     0.2256   4.713 2.44e-06 ***
## acc_ts        0.8470     0.2385   3.551 0.000384 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## acc_ts -0.765

5 Correlations with age

Are the differences between condition means correlated with age in months?

#Get age in months from raw data.
ids_et <- d_et%>%
  select(ID, age_months)
ids_ts <- d_ts%>%
  select(ID, age_months)

#Get dataframes with difference scores for conditions.
et_diff <- spread(mss_et_aov, trial_type, trans)%>%
  mutate(dacc_inacc = dissimilar_acc - inacc,
         sacc_inacc = similar_acc - inacc,
         dacc_sacc = dissimilar_acc - similar_acc)%>%
  left_join(ids_et)%>%
  unique

ts_diff <- spread(mss_ts_aov, trial_type, RT)%>%
  mutate(dacc_inacc = dissimilar_acc - inacc,
         sacc_inacc = similar_acc - inacc,
         dacc_sacc = dissimilar_acc - similar_acc)%>%
  left_join(ids_ts)%>%
  unique

#Get correlations of age in months with difference scores.
rcorr(et_diff$age_months, et_diff$dacc_inacc)
##       x     y
## x  1.00 -0.05
## y -0.05  1.00
## 
## n= 53 
## 
## 
## P
##   x      y     
## x        0.6973
## y 0.6973
rcorr(et_diff$age_months, et_diff$sacc_inacc)
##       x     y
## x  1.00 -0.04
## y -0.04  1.00
## 
## n= 53 
## 
## 
## P
##   x      y     
## x        0.7603
## y 0.7603
rcorr(et_diff$age_months, et_diff$dacc_sacc)
##       x     y
## x  1.00 -0.01
## y -0.01  1.00
## 
## n= 53 
## 
## 
## P
##   x      y     
## x        0.9249
## y 0.9249
rcorr(ts_diff$age_months, ts_diff$dacc_inacc)
##      x    y
## x 1.00 0.03
## y 0.03 1.00
## 
## n= 71 
## 
## 
## P
##   x      y     
## x        0.7921
## y 0.7921
rcorr(ts_diff$age_months, ts_diff$sacc_inacc)
##      x    y
## x 1.00 0.07
## y 0.07 1.00
## 
## n= 71 
## 
## 
## P
##   x      y     
## x        0.5806
## y 0.5806
rcorr(ts_diff$age_months, ts_diff$dacc_sacc)
##       x     y
## x  1.00 -0.05
## y -0.05  1.00
## 
## n= 71 
## 
## 
## P
##   x      y     
## x        0.6864
## y 0.6864

Are the average number of switches correlated with overall accuracy?

acc_et_ms <- d_et_filt%>%
  group_by(ID)%>%
  summarise(acc = mean(acc))

sw_et_ms <- d_et_filt%>%
  group_by(ID)%>%
  summarise(trans = mean(trans))

ids <- left_join(acc_et_ms, sw_et_ms)

rcorr(ids$acc, ids$trans)
##       x     y
## x  1.00 -0.12
## y -0.12  1.00
## 
## n= 69 
## 
## 
## P
##   x      y     
## x        0.3274
## y 0.3274