Published

June 14, 2024

Display code
pacman::p_load(dplyr,purrr,tidyr,ggplot2, here, patchwork, conflicted, knitr,grateful)
conflict_prefer_all("dplyr", quiet = TRUE)
#source(here::here("R/read_24.R"))

#https://fonts.google.com/specimen/Manrope
# ~/Library/Fonts
theme_nice <- function() {
  theme_minimal(base_family = "Manrope") +
    theme(
      panel.grid.minor = element_blank(),
      plot.title = element_text(family = "Manrope Extrabold", face = "plain", size = rel(1.25)),
      plot.subtitle = element_text(family = "Manrope Medium", face = "plain", size = rel(1.15)),
      axis.title = element_text(family = "Manrope SemiBold", face = "plain", size = rel(1)),
      axis.title.x = element_text(hjust = .5),
      axis.title.y = element_text(hjust = .5),
      axis.text = element_text(family = "Manrope Light", face = "plain", size = rel(0.8)),
      strip.text = element_text(
        family = "Manrope", face = "bold",
        size = rel(.75), hjust = 0
      ),
      strip.background = element_rect(fill = "grey90", color = NA)
    )
}

theme_nice_dist <- function() {
  theme_nice() +
    theme(
      panel.grid = element_blank(),
      panel.spacing.x = unit(10, units = "pt"),
      axis.ticks.x = element_line(linewidth = 0.25),
      axis.text.y = element_blank()
    )
}

theme_set(theme_nice())
Display code
library(dplyr)
library(tidyr)
library(readr)
library(stringr)
library(forcats)
library(purrr)
library(ggplot2)
library(ggthemes)
library(glue)
library(knitr)

set.seed(42)

knitr::opts_template$set(
  code = list(echo = TRUE, eval = FALSE)
)

# load font for plots
.font <- "Source Sans Pro"
if (!(.font %in% sysfonts::font_families()))
  sysfonts::font_add_google(.font, .font)
showtext::showtext_auto()

# set custom plot theme
theme_set(theme_bw(base_size = 14, base_family = .font))
theme_update(panel.grid = element_blank(),
             strip.background = element_blank(),
             legend.key = element_blank(),
             panel.border = element_blank(),
             axis.line = element_line(),
             strip.text = element_text(face = "bold"))

# set options for default color and fill scales
options("ggplot2.discrete.colour"   = ggthemes::scale_colour_ptol   )
options("ggplot2.continuous.colour" =  viridis::scale_colour_viridis)
options("ggplot2.discrete.fill"     = ggthemes::scale_fill_ptol     )
options("ggplot2.continuous.fill"   =  viridis::scale_fill_viridis  )

# solarized colors for individual elements (like reference lines)
pal <- list(
  grey   = "#93a1a1",
  red    = "#dc322f",
  blue   = "#268bd2",
  purple = "#6c71c4"
)

# from https://bookdown.org/yihui/rmarkdown-cookbook/font-color.html
colorize <- function(x, color) {
  if (knitr::is_latex_output()) {
    glue("\\textcolor{<color>}{<x>}", .open = "<", .close = ">")
  } else if (knitr::is_html_output()) {
    glue("<span style='color: var(--{stringr::str_sub(color, 2)});'>{x}</span>")
  } else x
}

Hu & Nosofsky 2022 (exp 2)

Subjects

  • 89 undergraduates from Indiana University.
  • Participation as partial fulfillment of an introductory psychology course requirement.
  • Random assignment to conditions: 43 in REP, 46 in NREP.
  • Normal or corrected-to-normal vision.

Procedure

Learning Phase

  • Task: Classify dot patterns into three categories: A, B, and C.
  • Trial Structure:
    • Pattern presented on screen.
    • Subject classifies pattern by pressing a corresponding button.
    • Immediate feedback provided.
  • Conditions:
    • Repeating Condition (REP):
      • 15 unique learning patterns (5 per category).
      • Patterns repeated across 15 blocks (225 trials total).
    • Nonrepeating Condition (NREP):
      • 75 unique learning patterns (5 per category per block).
      • No repetitions (225 trials total).

Transfer Phase

  • Task: Continue classifying patterns into the same three categories.
  • Transfer Patterns:
    • 15 old distortions (5 per category).
    • 3 prototypes (one per category).
    • 15 low-level distortions (5 per category).
    • 15 new medium-level distortions (5 per category).
    • 15 high-level distortions (5 per category).
  • Trial Structure:
    • Each pattern presented once (63 trials total).
    • Random order of presentation for each subject.
Display code
pacman::p_load(dplyr,purrr,tidyr,ggplot2, here, patchwork, conflicted, viridis, gghalves,grateful)
conflict_prefer_all("dplyr", quiet = TRUE)


source(here::here("R/read_22.R"))
source(here::here("R/fun_plot.R"))
#lmc22 <- readRDS(here("data","lmc22.rds"))

#theme_set(theme_bw())

dcp <- merge(dCatAvg2,sbjTrainAvg,by=c("id","condit","Condition"))


dc <- dCatAvg2 %>% select(id,condit,Condition,Pattern.Type2,Category,propCor) %>% 
  pivot_wider(names_from = "Pattern.Type2",values_from = "propCor") %>%
  mutate(EndTrain.Minus.HighDistort= End.Training-New.High,
         MedDistort.Minus.HighDistort=New.Med-New.High,
         LowDistort.Minus.HighDistort=New.Low-New.High,
         TrainedItem.Minus.HighDistort=Trained.Med-New.High,
         Prototype.Minus.HighDistort=Prototype-New.High) 

dc <- merge(dc,sbjTrainAvg,by=c("id","condit","Condition"))
dc2 <- dc %>% group_by(id,condit,Condition,cq) %>% summarise(End.Training=mean(End.Training),New.High=mean(New.High)) %>% as.data.frame()
  • the learning phase consisted of 15 blocks, each of which had 15 trials (225 trials total).

Experiment 2

Testing - Splitting Peformance by End of Training

Display code
##| column: page-inset-right

library(gghalves)

ps <- dcp  %>% ggplot(aes(x=Pattern.Type2,y=propCor,fill=Condition))+
  stat_summary(geom="bar",fun=mean,position=position_dodge())+
  stat_summary(geom="errorbar",fun.data=mean_se,position=position_dodge())+facet_wrap(~cq)+
   geom_hline(yintercept = .33,linetype="dashed")+
  xlab("Pattern-Type")+ylab("Proportion Correct")+ggtitle("Low vs High Performers (median split within condition - final training block) - Performance x Pattern Type")

hd<- dcp  %>% filter(Pattern.Type2=="New-High")%>% ggplot(aes(x=Pattern.Type2,y=propCor,fill=Condition))+
  geom_boxplot(outlier.shape=NA)+geom_jitter(alpha=.5)+facet_wrap(~cq)+xlab("Pattern-Type")+
  ggtitle("Low vs High Performers (median split within condition) - High Distortion Performance")+ylab("Proportion Correct")


# dcp  %>% filter(Pattern.Type2=="New-High") %>% ggplot(aes(x=Pattern.Type2,y=propCor,fill=Condition))+
#   geom_half_violin()+
#   geom_jitter(alpha=.5)+
#   facet_wrap(~cq)+ggtitle("Low vs High Performers (median split within condition) - High Distortion Performance")

#ps
#gridExtra::grid.arrange(ps,hd)


p7<- dcp  %>% filter(endTrain>.75) %>% ggplot(aes(x=Pattern.Type2,y=propCor,fill=Condition))+
  stat_summary(geom="bar",fun=mean,position=position_dodge())+
  stat_summary(geom="errorbar",fun.data=mean_se,position=position_dodge())+
   geom_hline(yintercept = .33,linetype="dashed")+
  xlab("Pattern-Type")+ylab("Proportion Correct")+ggtitle("Performance x Pattern Type - Only retaining sbjs with >75% accuracy in final training block")

p5 <-  dcp  %>% filter(endTrain>.50) %>% ggplot(aes(x=Pattern.Type2,y=propCor,fill=Condition))+
  stat_summary(geom="bar",fun=mean,position=position_dodge())+
  stat_summary(geom="errorbar",fun.data=mean_se,position=position_dodge())+
   geom_hline(yintercept = .33,linetype="dashed")+
  xlab("Pattern-Type")+ylab("Proportion Correct")+ggtitle("Performance x Pattern Type - Only retaining sbjs with >50% accuracy in final training block")


gridExtra::grid.arrange(ps,p7,p5)

Display code
# dCatAvg2  %>% ggplot(aes(x=Pattern.Type2,y=propCor,fill=Condition))+
#   stat_summary(geom="bar",fun=mean,position=position_dodge())+
#   stat_summary(geom="errorbar",fun.data=mean_se,position=position_dodge())+facet_wrap(~cq)+
#   stat_summary(geom="point")
#    geom_hline(yintercept = .33,linetype="dashed")+
#  ggtitle("")+ylab("Proportion Correct")

# dCatAvg2 %>% filter() %>% ggplot(aes(x=Pattern.Type2,y=propCor,fill=Pattern.Type2))+
#   stat_summary(geom="bar",fun=mean,position=position_dodge())+
#   stat_summary(geom="errorbar",fun.data=mean_se,position=position_dodge())+facet_wrap(~condit)+
#    geom_hline(yintercept = .33,linetype="dashed")+
#  ggtitle("")+ylab("Proportion Correct")
# 
# 
# dCatAvg3 %>% filter() %>% ggplot(aes(x=Pattern.Type2,y=propCor,fill=Pattern.Type2))+
#   stat_summary(geom="bar",fun=mean,position=position_dodge())+
#   stat_summary(geom="errorbar",fun.data=mean_se,position=position_dodge())+facet_wrap(~condit)+
#    geom_hline(yintercept = .33,linetype="dashed")+
#  ggtitle("")+ylab("Proportion Correct")

Controlling for End of Training Performace

Display code
library(rstatix)
library(ggpubr)
library(emmeans)
library(cowplot)


# dc2 %>% filter() %>% ggplot(aes(x=End.Training,y=New.High,color=condit))+geom_point()+geom_smooth(method="lm")
# dc2 %>% filter(End.Training>.33, New.High>.33) %>% ggplot(aes(x=End.Training,y=New.High,color=condit))+geom_point()+geom_smooth(method="lm")

(at1 <- dc2 %>% anova_test(dv=New.High,between=Condition,covariate = End.Training,wid=id,type=3))
ANOVA Table (type III tests)

        Effect DFn DFd       F        p p<.05   ges
1 End.Training   1  86 128.607 9.21e-19     * 0.599
2    Condition   1  86  12.249 7.40e-04     * 0.125
Display code
(at2 <- dc2 %>% filter(End.Training>.33) %>% anova_test(dv=New.High,between=Condition,covariate = End.Training,wid=id,type=3))
ANOVA Table (type III tests)

        Effect DFn DFd       F        p p<.05   ges
1 End.Training   1  84 103.961 2.36e-16     * 0.553
2    Condition   1  84  12.573 6.43e-04     * 0.130
Display code
(at3 <- dc2 %>% filter(End.Training>.88) %>% anova_test(dv=New.High,between=Condition,covariate = End.Training,wid=id,type=3))
ANOVA Table (type III tests)

        Effect DFn DFd      F        p p<.05   ges
1 End.Training   1  49 13.847 0.000511     * 0.220
2    Condition   1  49 13.131 0.000689     * 0.211
Display code
#dc2 %>% anova_test(New.High ~condit*End.Training) # no sig. interaction
pwc1 <- dc2 %>% emmeans_test(New.High ~ Condition,covariate=End.Training,p.adjust.method="bonferroni")%>% add_xy_position(x = "condit", fun = "mean_se")
get_emmeans(pwc1)
# A tibble: 2 × 8
  End.Training Condition emmean     se    df conf.low conf.high method      
         <dbl> <fct>      <dbl>  <dbl> <dbl>    <dbl>     <dbl> <chr>       
1        0.830 rep        0.673 0.0198    86    0.634     0.713 Emmeans test
2        0.830 nrep       0.772 0.0191    86    0.734     0.810 Emmeans test
Display code
pwc2 <- dc2 %>% filter(End.Training>.33) %>% emmeans_test(New.High ~ Condition,covariate=End.Training,p.adjust.method="bonferroni")%>% add_xy_position(x = "condit", fun = "mean_se")
pwc3 <- dc2 %>% filter(End.Training>.88) %>% emmeans_test(New.High ~ Condition,covariate=End.Training,p.adjust.method="bonferroni")%>% add_xy_position(x = "condit", fun = "mean_se")



ep1<-ggline(get_emmeans(pwc1), x = "Condition", y = "emmean") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2) + 
  stat_pvalue_manual(pwc1, hide.ns = TRUE, tip.length = FALSE) +
  labs(subtitle = get_test_label(at1, detailed = TRUE),caption = get_pwc_label(pwc1),title="Estimated Marginal Means from ANCOVA - All Sbj. (n=89)" )

ep2<-ggline(get_emmeans(pwc2), x = "Condition", y = "emmean") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2) + 
  stat_pvalue_manual(pwc2, hide.ns = TRUE, tip.length = FALSE) +
  labs(subtitle = get_test_label(at2, detailed = TRUE),caption = get_pwc_label(pwc2), title= "Estimated Marginal Means from ANCOVA - Only above chance sbj (>.33,n=87)")

ep3<-ggline(get_emmeans(pwc3), x = "Condition", y = "emmean") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2) + 
  stat_pvalue_manual(pwc3, hide.ns = TRUE, tip.length = FALSE) +
  labs(subtitle = get_test_label(at3, detailed = TRUE),caption = get_pwc_label(pwc3), title= "Estimated Marginal Means from ANCOVA - Only strong learners (>.88; n=52)")



gg.ac1 <- ggscatter(dc2,x="End.Training",y="New.High",color="Condition",add="reg.line",add.params = list(size=.3))+
  stat_regline_equation(aes(label=paste(..eq.label.., ..rr.label..,sep="~~~~"),color=Condition))+
  ggtitle("Including All Subjects (n=89)")+ylab("High Distortions - Proportion Correct")+xlab("End of Training - Proportion Correct")

gg.ac2 <- dc2 %>% filter(End.Training>.33) %>% ggscatter(.,x="End.Training",y="New.High",color="Condition",add="reg.line",add.params = list(size=.3))+
  stat_regline_equation(aes(label=paste(..eq.label.., ..rr.label..,sep="~~~~"),color=Condition))+
  ggtitle("Retain Sbj's above chance (>.33) at train end (n=87). ")+ylab("High Distortions - Proportion Correct")+xlab("End of Training - Proportion Correct")

gg.ac3 <- dc2 %>% filter(End.Training>.88) %>% ggscatter(.,x="End.Training",y="New.High",color="Condition",add="reg.line",add.params = list(size=.3))+
  stat_regline_equation(aes(label=paste(..eq.label.., ..rr.label..,sep="~~~~"),color=Condition))+
  ggtitle("Retain only stronger learners (>.88) at train end (n=52). ")+ylab("High Distortions - Proportion Correct")+xlab("End of Training - Proportion Correct")



gtitle=" Hu & Nosofsky 2020 - Experiment 2. Effect of Condition on High Distortions - Controlling for End of Training Performance"
title = ggdraw()+draw_label(gtitle,fontface = 'bold',x=0,hjust=0)+theme(plot.margin = margin(0, 0, 0, 7))

plot_grid(title,NULL,gg.ac1,ep1,gg.ac2,ep2,gg.ac3,ep3,ncol=2,rel_heights=c(.1,1,1,1))

Individual Learning Curves

Display code
###| column: screen-inset-right


dCatTrainAvg %>% filter(condit=="rep") %>% ggplot(aes(x=Block,y=propCor,col=condit))+
  stat_summary(shape=0,geom="point",fun="mean")+
  stat_summary(geom="line",fun="mean",col="red")+facet_wrap(~id)+ylim(c(0,1))+
  geom_hline(yintercept = .33,linetype="dashed")+
  ggtitle("Hu & Nosofsky Experiment 2 - Learning. Rep Subjects - Average Accuracy Per Block.")+
  xlab("Training Block")+ylab("Proportion Correct")+scale_x_continuous(breaks=seq(1,15))

Display code
dCatTrainAvg %>% filter(condit=="nrep") %>% ggplot(aes(x=Block,y=propCor,col=condit))+
  stat_summary(shape=2, geom="point",fun="mean",col="lightblue")+
  stat_summary(geom="line",fun="mean",col="lightblue")+facet_wrap(~id)+ylim(c(0,1))+
  geom_hline(yintercept = .33,linetype="dashed")+
  facet_wrap(~id)+ggtitle("Hu & Nosofsky Experiment 2 - Learning. NRep Subjects - Average Accuracy Per Block.")+
  xlab("Training Block")+ylab("Proportion Correct")+scale_x_continuous(breaks=seq(1,15))

Experiment 2 - separate category - learning curves

Display code
##| column: screen-inset-right
 
dCatTrainAvg2 %>% filter(condit=="rep") %>% ggplot(aes(x=Block,y=propCor,col=Category,shape=Category))+
  stat_summary(geom="point",fun="mean")+
  stat_summary(geom="line",fun="mean")+facet_wrap(~id)+ylim(c(0,1))+
  geom_hline(yintercept = .33,linetype="dashed")+
  ggtitle("Hu & Nosofsky Experiment 2 - Learning Curves. Rep Subjects - Separated Categories.")+
  xlab("Training Block")+ylab("Proportion Correct")+scale_x_continuous(breaks=seq(1,15))

Display code
dCatTrainAvg2 %>% filter(condit=="nrep") %>% ggplot(aes(x=Block,y=propCor,col=Category,shape=Category))+
  stat_summary(geom="point",fun="mean")+
  stat_summary(geom="line",fun="mean")+facet_wrap(~id)+ylim(c(0,1))+
  geom_hline(yintercept = .33,linetype="dashed")+
  facet_wrap(~id)+ggtitle("Hu & Nosofsky Experiment 2 - Learning Curves. NRep Subjects - Separated Categories.")+
  xlab("Training Block")+ylab("Proportion Correct")+scale_x_continuous(breaks=seq(1,15))

Experiment 2 - 3 Training Stages + Transfer Patterns

Display code
dCatAvg %>% filter(condit=="rep") %>% ggplot(aes(x=Stage,y=propCor,fill=Pattern.Type))+
  stat_summary(geom="bar",fun=mean,position=position_dodge())+
  stat_summary(geom="errorbar",fun.data=mean_se,position=position_dodge())+facet_wrap(~id)+
   geom_hline(yintercept = .33,linetype="dashed")+
 ggtitle("REP - 3 training bins (75 trials each) + Transfer Patterns")+ylab("Proportion Correct")

Display code
dCatAvg %>% filter(condit=="nrep") %>% ggplot(aes(x=Stage,y=propCor,fill=Pattern.Type))+
  stat_summary(geom="bar",fun=mean,position=position_dodge())+
  stat_summary(geom="errorbar",fun.data=mean_se,position=position_dodge())+facet_wrap(~id)+
   geom_hline(yintercept = .33,linetype="dashed")+
 ggtitle("NREP - 3 training bins (75 trials each) + Transfer Patterns")+ylab("Proportion Correct")

Display code
# 
# dCatAvg %>% filter() %>% ggplot(aes(x=Stage,y=propCor,fill=Pattern.Type))+
#   stat_summary(geom="bar",fun=mean,position=position_dodge())+
#   stat_summary(geom="errorbar",fun.data=mean_se,position=position_dodge())+facet_wrap(~condit)+ggtitle("nrep")
# 
# dCatAvg %>% filter() %>% ggplot(aes(x=Pattern.Type,y=propCor,fill=condit))+
#   stat_summary(geom="bar",fun=mean,position=position_dodge())+
#   stat_summary(geom="errorbar",fun.data=mean_se,position=position_dodge())+facet_wrap(~Stage)+ggtitle("")
# 
# dCatAvg %>% filter() %>% ggplot(aes(x=Pattern.Type,y=propCor,col=condit))+
#   geom_boxplot(position=position_dodge())+facet_wrap(~Stage)

Experiment 2 - Separate Categories x stage

Display code
dCatAvg2 %>% filter(condit=="rep") %>% ggplot(aes(x=Category,y=propCor,fill=Pattern.Type2))+
  stat_summary(geom="bar",fun=mean,position=position_dodge())+
  stat_summary(geom="errorbar",fun.data=mean_se,position=position_dodge())+facet_wrap(~id)+
   geom_hline(yintercept = .33,linetype="dashed")+
 ggtitle("REP - End of Training vs. Testing Performance Per Category")+ylab("Proportion Correct")

Display code
dCatAvg2 %>% filter(condit=="nrep") %>% ggplot(aes(x=Category,y=propCor,fill=Pattern.Type2))+
  stat_summary(geom="bar",fun=mean,position=position_dodge())+
  stat_summary(geom="errorbar",fun.data=mean_se,position=position_dodge())+facet_wrap(~id)+
   geom_hline(yintercept = .33,linetype="dashed")+
 ggtitle("NREP - End of Training vs. Testing Performance Per Category")+ylab("Proportion Correct")

Display code
dc %>% ggplot(aes(x=condit,y=EndTrain.Minus.HighDistort))+stat_summary(geom="bar",fun=mean)+
  stat_summary(geom="errorbar",fun.data=mean_se)

Display code
dc %>% ggplot(aes(x=condit,y=MedDistort.Minus.HighDistort))+stat_summary(geom="bar",fun=mean)+
  stat_summary(geom="errorbar",fun.data=mean_se)

Display code
dc %>% ggplot(aes(x=condit,y=LowDistort.Minus.HighDistort))+stat_summary(geom="bar",fun=mean)+
  stat_summary(geom="errorbar",fun.data=mean_se)

Display code
dc %>% ggplot(aes(x=condit,y=TrainedItem.Minus.HighDistort))+stat_summary(geom="bar",fun=mean)+
  stat_summary(geom="errorbar",fun.data=mean_se)

Display code
# dc %>% filter(condit=="rep") %>% ungroup() %>% select(End.Training,`New-High`) %>% cor
# dc %>% filter(condit=="nrep") %>% ungroup() %>% select(End.Training,`New-High`) %>% cor()
Display code
library(afex)

# aov_ez("id",data=dc,"New.High",between="condit")
# aov_ez("id",data=dCatAvg2,"propCor",between="condit",within = c("Pattern.Type2"))
# aov_ez("id",data=dCatAvg,"propCor",between="condit",within = c("Pattern.Type"))



hd <- dcp %>% filter(Pattern.Type2=="New-High")
hd2 <- dcp %>% filter(Pattern.Type2=="New-High") %>% group_by(id,condit,cq) %>% summarise(propCor=mean(propCor))
# aov_ez("id",data=hd2,"propCor",between=c("condit","cq"))
# aov_ez("id",data=hd,"propCor",between=c("condit","cq"),within=c("Category"))
# aov_ez("id",data=dc,"New-High",between=c("condit","cq"),within=c("Category"))

lme4::lmer(New.High~condit + (1|id),data=dc) %>% anova()
Analysis of Variance Table
       npar     Sum Sq    Mean Sq F value
condit    1 0.00016768 0.00016768  0.0032
Display code
lme4::lmer(New.High~condit*cq + (1|id),data=dc) %>% anova()
Analysis of Variance Table
          npar  Sum Sq Mean Sq F value
condit       1 0.00024 0.00024  0.0046
cq           1 1.72159 1.72159 33.1171
condit:cq    1 0.26717 0.26717  5.1394
Display code
lme4::lmer(New.High~condit + (1|id),data=dc) %>% anova()
Analysis of Variance Table
       npar     Sum Sq    Mean Sq F value
condit    1 0.00016768 0.00016768  0.0032
Display code
lme4::lmer(New.High~End.Training + (1|id),data=dc) %>% anova()
Analysis of Variance Table
             npar Sum Sq Mean Sq F value
End.Training    1 5.5257  5.5257  113.08
Display code
lme4::lmer(New.High~End.Training+condit + (1|id),data=dc) %>% anova()
Analysis of Variance Table
             npar Sum Sq Mean Sq  F value
End.Training    1 6.1051  6.1051 124.2796
condit          1 0.4780  0.4780   9.7304
Display code
dc %>% lme4::lmer(New.High~End.Training+(condit*cq) + (1|Category)+(1|id),data=.) %>% anova()
Analysis of Variance Table
             npar Sum Sq Mean Sq  F value
End.Training    1 6.1051  6.1051 125.3150
condit          1 0.4780  0.4780   9.8115
cq              1 0.0587  0.0587   1.2045
condit:cq       1 0.1459  0.1459   2.9950
Display code
dc2%>% aov(New.High~End.Training+(condit*cq),data=.) %>% anova()
Analysis of Variance Table

Response: New.High
             Df  Sum Sq Mean Sq  F value    Pr(>F)    
End.Training  1 1.86129 1.86129 116.8075 < 2.2e-16 ***
condit        1 0.19593 0.19593  12.2961 0.0007313 ***
cq            1 0.00032 0.00032   0.0201 0.8877224    
condit:cq     1 0.03676 0.03676   2.3070 0.1325511    
Residuals    84 1.33851 0.01593                       
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Display code
dCatAvg4 <- dCatAvg2 %>% ungroup() %>% group_by(condit)%>% mutate(r=ntile(propCor,3)) %>% group_by(id,condit,Pattern.Type2,r) %>% 
  dplyr::summarise(propCor=mean(propCor)) %>% ungroup() 






typeCounts <- dCat %>% group_by(id,Phase2,Pattern.Type) %>% summarise(n=n())
typeCategoryCounts <- dCat %>% group_by(id,Phase2,Category,Pattern.Type) %>% summarise(n.trials=n())

typeCounts2 <- typeCounts %>% group_by(Phase2,Pattern.Type) %>% summarise(N.Trials=mean(n),TrialsPerCategory=as.integer(N.Trials/3))
typeCategoryCounts2 <- typeCategoryCounts %>% group_by(Phase2,Category,Pattern.Type) %>% summarise(N.Trials=mean(n.trials))
Display code
distGradient <- dc %>% pivot_longer(cols=c(EndTrain.Minus.HighDistort,TrainedItem.Minus.HighDistort,
                                           MedDistort.Minus.HighDistort,LowDistort.Minus.HighDistort,
                                           Prototype.Minus.HighDistort),
                                    names_to = "Distortion.Level",values_to="PropCor")




# Performance correlation matrices
dc %>% ungroup() %>% select(End.Training,New.Low,Prototype,New.Med,New.High) %>% cor()
             End.Training   New.Low Prototype   New.Med  New.High
End.Training    1.0000000 0.6842711 0.4752937 0.5952417 0.5587956
New.Low         0.6842711 1.0000000 0.6294063 0.6484626 0.5262712
Prototype       0.4752937 0.6294063 1.0000000 0.4275736 0.3852402
New.Med         0.5952417 0.6484626 0.4275736 1.0000000 0.5572554
New.High        0.5587956 0.5262712 0.3852402 0.5572554 1.0000000
Display code
dc %>% filter(condit=="rep") %>% ungroup() %>% select(End.Training,New.Low,Prototype,New.Med,New.High) %>% cor()
             End.Training   New.Low Prototype   New.Med  New.High
End.Training    1.0000000 0.7012169 0.3939172 0.5389309 0.4508624
New.Low         0.7012169 1.0000000 0.6079447 0.6352102 0.5155579
Prototype       0.3939172 0.6079447 1.0000000 0.4089649 0.3719640
New.Med         0.5389309 0.6352102 0.4089649 1.0000000 0.5973629
New.High        0.4508624 0.5155579 0.3719640 0.5973629 1.0000000
Display code
dc %>% filter(condit=="nrep") %>% ungroup() %>% select(End.Training,New.Low,Prototype,New.Med,New.High) %>% cor()
             End.Training   New.Low Prototype   New.Med  New.High
End.Training    1.0000000 0.7045843 0.5727802 0.6739761 0.6771628
New.Low         0.7045843 1.0000000 0.6494747 0.6597156 0.5359835
Prototype       0.5727802 0.6494747 1.0000000 0.4440815 0.3972409
New.Med         0.6739761 0.6597156 0.4440815 1.0000000 0.5248269
New.High        0.6771628 0.5359835 0.3972409 0.5248269 1.0000000
Display code
# High Distortion decrement correlation matrices

dc %>% filter(condit=="rep") %>% ungroup() %>% select(End.Training,Prototype.Minus.HighDistort,
                                                      TrainedItem.Minus.HighDistort,
                                                      LowDistort.Minus.HighDistort,
                                                      MedDistort.Minus.HighDistort,
                                                      EndTrain.Minus.HighDistort) %>% cor()
                              End.Training Prototype.Minus.HighDistort
End.Training                    1.00000000                 -0.01759351
Prototype.Minus.HighDistort    -0.01759351                  1.00000000
TrainedItem.Minus.HighDistort   0.12254319                  0.58985522
LowDistort.Minus.HighDistort    0.15338793                  0.66697504
MedDistort.Minus.HighDistort    0.01379446                  0.46875984
EndTrain.Minus.HighDistort      0.21672813                  0.54029033
                              TrainedItem.Minus.HighDistort
End.Training                                      0.1225432
Prototype.Minus.HighDistort                       0.5898552
TrainedItem.Minus.HighDistort                     1.0000000
LowDistort.Minus.HighDistort                      0.7991283
MedDistort.Minus.HighDistort                      0.6459330
EndTrain.Minus.HighDistort                        0.8663125
                              LowDistort.Minus.HighDistort
End.Training                                     0.1533879
Prototype.Minus.HighDistort                      0.6669750
TrainedItem.Minus.HighDistort                    0.7991283
LowDistort.Minus.HighDistort                     1.0000000
MedDistort.Minus.HighDistort                     0.6620865
EndTrain.Minus.HighDistort                       0.7824071
                              MedDistort.Minus.HighDistort
End.Training                                    0.01379446
Prototype.Minus.HighDistort                     0.46875984
TrainedItem.Minus.HighDistort                   0.64593302
LowDistort.Minus.HighDistort                    0.66208649
MedDistort.Minus.HighDistort                    1.00000000
EndTrain.Minus.HighDistort                      0.64185369
                              EndTrain.Minus.HighDistort
End.Training                                   0.2167281
Prototype.Minus.HighDistort                    0.5402903
TrainedItem.Minus.HighDistort                  0.8663125
LowDistort.Minus.HighDistort                   0.7824071
MedDistort.Minus.HighDistort                   0.6418537
EndTrain.Minus.HighDistort                     1.0000000
Display code
dc %>% filter(condit=="nrep") %>% ungroup() %>% select(End.Training,Prototype.Minus.HighDistort,
                            TrainedItem.Minus.HighDistort,
                            LowDistort.Minus.HighDistort,
                            MedDistort.Minus.HighDistort,
                            EndTrain.Minus.HighDistort) %>% cor()
                              End.Training Prototype.Minus.HighDistort
End.Training                    1.00000000                 -0.06037152
Prototype.Minus.HighDistort    -0.06037152                  1.00000000
TrainedItem.Minus.HighDistort   0.02130414                  0.58942862
LowDistort.Minus.HighDistort   -0.06243181                  0.69043480
MedDistort.Minus.HighDistort   -0.06469949                  0.49881760
EndTrain.Minus.HighDistort      0.17029832                  0.61756432
                              TrainedItem.Minus.HighDistort
End.Training                                     0.02130414
Prototype.Minus.HighDistort                      0.58942862
TrainedItem.Minus.HighDistort                    1.00000000
LowDistort.Minus.HighDistort                     0.73266175
MedDistort.Minus.HighDistort                     0.62544765
EndTrain.Minus.HighDistort                       0.77968497
                              LowDistort.Minus.HighDistort
End.Training                                   -0.06243181
Prototype.Minus.HighDistort                     0.69043480
TrainedItem.Minus.HighDistort                   0.73266175
LowDistort.Minus.HighDistort                    1.00000000
MedDistort.Minus.HighDistort                    0.67863741
EndTrain.Minus.HighDistort                      0.70853227
                              MedDistort.Minus.HighDistort
End.Training                                   -0.06469949
Prototype.Minus.HighDistort                     0.49881760
TrainedItem.Minus.HighDistort                   0.62544765
LowDistort.Minus.HighDistort                    0.67863741
MedDistort.Minus.HighDistort                    1.00000000
EndTrain.Minus.HighDistort                      0.67384579
                              EndTrain.Minus.HighDistort
End.Training                                   0.1702983
Prototype.Minus.HighDistort                    0.6175643
TrainedItem.Minus.HighDistort                  0.7796850
LowDistort.Minus.HighDistort                   0.7085323
MedDistort.Minus.HighDistort                   0.6738458
EndTrain.Minus.HighDistort                     1.0000000
Display code
dc %>% ungroup() %>% select(End.Training,Prototype.Minus.HighDistort,
                            TrainedItem.Minus.HighDistort,
                            LowDistort.Minus.HighDistort,
                            MedDistort.Minus.HighDistort,
                            EndTrain.Minus.HighDistort) %>% cor()
                              End.Training Prototype.Minus.HighDistort
End.Training                    1.00000000                 -0.04086973
Prototype.Minus.HighDistort    -0.04086973                  1.00000000
TrainedItem.Minus.HighDistort   0.10015867                  0.58340126
LowDistort.Minus.HighDistort    0.03552709                  0.67869557
MedDistort.Minus.HighDistort   -0.03324146                  0.48412413
EndTrain.Minus.HighDistort      0.24223066                  0.55722730
                              TrainedItem.Minus.HighDistort
End.Training                                      0.1001587
Prototype.Minus.HighDistort                       0.5834013
TrainedItem.Minus.HighDistort                     1.0000000
LowDistort.Minus.HighDistort                      0.7614572
MedDistort.Minus.HighDistort                      0.6256669
EndTrain.Minus.HighDistort                        0.8262874
                              LowDistort.Minus.HighDistort
End.Training                                    0.03552709
Prototype.Minus.HighDistort                     0.67869557
TrainedItem.Minus.HighDistort                   0.76145723
LowDistort.Minus.HighDistort                    1.00000000
MedDistort.Minus.HighDistort                    0.66984464
EndTrain.Minus.HighDistort                      0.72897715
                              MedDistort.Minus.HighDistort
End.Training                                   -0.03324146
Prototype.Minus.HighDistort                     0.48412413
TrainedItem.Minus.HighDistort                   0.62566692
LowDistort.Minus.HighDistort                    0.66984464
MedDistort.Minus.HighDistort                    1.00000000
EndTrain.Minus.HighDistort                      0.63059545
                              EndTrain.Minus.HighDistort
End.Training                                   0.2422307
Prototype.Minus.HighDistort                    0.5572273
TrainedItem.Minus.HighDistort                  0.8262874
LowDistort.Minus.HighDistort                   0.7289771
MedDistort.Minus.HighDistort                   0.6305955
EndTrain.Minus.HighDistort                     1.0000000

Link to preprocessing code

Display code
# dRecAvg %>% ggplot(aes(x=Block,y=propCor,col=condit))+
#   stat_summary(geom="point",fun="mean")+stat_summary(geom="line",fun="mean")+facet_wrap(~id)

dRecAvg %>% filter(condit=="rep") %>% ggplot(aes(x=Block,y=propCor,col=condit))+
  stat_summary(shape=0,geom="point",fun="mean")+
  stat_summary(geom="line",fun="mean",col="red")+facet_wrap(~id)+ylim(c(0,1))+
  ggtitle("Hu & Nosofsky Experiment 1 - Learning. Rep Subjects.")

dRecAvg %>% filter(condit=="nrep") %>% ggplot(aes(x=Block,y=propCor,col=condit))+
  stat_summary(shape=2, geom="point",fun="mean",col="lightblue")+
  stat_summary(geom="line",fun="mean",col="lightblue")+facet_wrap(~id)+ylim(c(0,1))+
  facet_wrap(~id)+ggtitle("Hu & Nosofsky Experiment 1 - Learning. NRep Subjects.")

R packages used

Display code
##| eval: false
# grateful::cite_packages(output = "paragraph",pkgs="Session",
#                         out.dir = "assets", cite.tidyverse=TRUE)
pkgs <- grateful::cite_packages(output = "table",pkgs="Session",
                        out.dir = here::here("assets"), cite.tidyverse=TRUE, omit=c("colorout","viridis"))

# read in assets/grateful-refs.bib file
# ref_file <- here::here("assets","grateful-refs.bib")
# load file
#bib <- bibtex::read.bib(ref_file)

#pkgs <- scan_packages()
knitr::kable(pkgs)
Package Version Citation
afex 1.3.1 Singmann et al. (2024)
base 4.4.0 R Core Team (2024)
cowplot 1.1.3 Wilke (2024)
data.table 1.15.4 Barrett et al. (2024)
emmeans 1.10.2 Lenth (2024)
gghalves 0.1.4 Tiedemann (2022)
ggpubr 0.6.0 Kassambara (2023a)
grateful 0.2.4 Francisco Rodriguez-Sanchez & Connor P. Jackson (2023)
here 1.0.1 Müller (2020)
knitr 1.47 Xie (2014); Xie (2015); Xie (2024)
lme4 1.1.35.3 Bates et al. (2015)
Matrix 1.7.0 Bates et al. (2024)
patchwork 1.2.0 Pedersen (2024)
rstatix 0.7.2 Kassambara (2023b)
tidyverse 2.0.0 Wickham et al. (2019)
usedthese 0.4.0 Goodwin (2023)
viridisLite 0.4.2 Garnier et al. (2023)
Display code
usedthese::used_here()
Package Function
Matrix mean[11]
afex, lme4 lmer[6]
base as.data.frame[2], as.integer[1], as.numeric[2], c[23], cut[2], factor[4], floor[1], function[3], if[3], jitter[4], library[16], list[5], max[1], merge[2], nrow[4], options[4], paste[3], rank[1], seq[4], set.seed[5], source[2], subset[8], sum[2], unique[2]
conflicted conflict_prefer_all[2]
cowplot draw_label[1], ggdraw[1], plot_grid[1]
data.table set[1]
dplyr arrange[1], filter[31], group_by[12], mutate[7], n[2], ntile[1], select[7], summarise[9], ungroup[10]
gghalves geom_half_boxplot[8], geom_half_violin[8]
ggplot2 aes[56], element_blank[7], element_line[2], element_rect[1], element_text[8], facet_wrap[22], geom_boxplot[1], geom_errorbar[3], geom_hline[11], geom_jitter[1], geom_point[8], ggplot[26], ggtitle[21], labs[3], margin[1], position_dodge[14], position_nudge[16], rel[5], scale_x_continuous[8], stat_summary[42], theme[3], theme_bw[1], theme_minimal[1], theme_set[2], theme_update[1], xlab[11], ylab[15], ylim[10]
ggpubr ggline[3], ggscatter[3], stat_pvalue_manual[3], stat_regline_equation[3]
grateful cite_packages[1]
grid unit[1]
gridExtra grid.arrange[1]
here here[3]
knitr is_html_output[1], is_latex_output[1], kable[1]
pacman p_load[2]
rstatix add_xy_position[3], anova_test[3], emmeans_test[3], get_emmeans[4], get_pwc_label[3], get_test_label[3]
showtext showtext_auto[1]
stats anova[7], aov[1], cor[6], end[2], var[1]
stringr str_sub[1]
sysfonts font_add_google[1], font_families[1]
tidyr pivot_longer[1], pivot_wider[1]
usedthese used_here[1]
utils sessionInfo[1]
viridis scale_color_viridis[4], scale_fill_viridis[4]
Display code
R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Indiana/Indianapolis
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] cowplot_1.1.3     emmeans_1.10.2    ggpubr_0.6.0      usedthese_0.4.0  
 [5] rstatix_0.7.2     afex_1.3-1        lme4_1.1-35.3     Matrix_1.7-0     
 [9] readr_2.1.5       data.table_1.15.4 gghalves_0.1.4    viridis_0.6.5    
[13] viridisLite_0.4.2 grateful_0.2.4    knitr_1.47        conflicted_1.2.0 
[17] patchwork_1.2.0   here_1.0.1        ggplot2_3.5.1     tidyr_1.3.1      
[21] purrr_1.0.2       dplyr_1.1.4       colorout_1.3-0.2 

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.1    farver_2.1.2        fastmap_1.2.0      
 [4] pacman_0.5.1        digest_0.6.35       estimability_1.5.1 
 [7] lifecycle_1.0.4     magrittr_2.0.3      compiler_4.4.0     
[10] rlang_1.1.4         tools_4.4.0         utf8_1.2.4         
[13] yaml_2.3.8          ggsignif_0.6.4      labeling_0.4.3     
[16] htmlwidgets_1.6.4   bit_4.0.5           xml2_1.3.6         
[19] plyr_1.8.9          abind_1.4-5         withr_3.0.0        
[22] numDeriv_2016.8-1.1 grid_4.4.0          fansi_1.0.6        
[25] xtable_1.8-4        colorspace_2.1-0    scales_1.3.0       
[28] MASS_7.3-60.2       cli_3.6.2           mvtnorm_1.2-5      
[31] crayon_1.5.2        rmarkdown_2.27      generics_0.1.3     
[34] rstudioapi_0.16.0   reshape2_1.4.4      tzdb_0.4.0         
[37] polynom_1.4-1       minqa_1.2.7         cachem_1.1.0       
[40] stringr_1.5.1       splines_4.4.0       parallel_4.4.0     
[43] vctrs_0.6.5         boot_1.3-30         jsonlite_1.8.8     
[46] carData_3.0-5       car_3.1-2           hms_1.1.3          
[49] bit64_4.0.5         systemfonts_1.1.0   glue_1.7.0         
[52] nloptr_2.0.3        stringi_1.8.4       gtable_0.3.5       
[55] lmerTest_3.1-3      munsell_0.5.1       tibble_3.2.1       
[58] pillar_1.9.0        htmltools_0.5.8.1   R6_2.5.1           
[61] rprojroot_2.0.4     kableExtra_1.4.0    vroom_1.6.5        
[64] evaluate_0.23       lattice_0.22-6      highr_0.11         
[67] backports_1.5.0     memoise_2.0.1       broom_1.0.6        
[70] Rcpp_1.0.12         svglite_2.1.3       coda_0.19-4.1      
[73] gridExtra_2.3       nlme_3.1-164        mgcv_1.9-1         
[76] xfun_0.44           pkgconfig_2.0.3    

References

Barrett, T., Dowle, M., Srinivasan, A., Gorecki, J., Chirico, M., & Hocking, T. (2024). data.table: Extension of data.frame. https://CRAN.R-project.org/package=data.table
Bates, D., Mächler, M., Bolker, B., & Walker, S. (2015). Fitting linear mixed-effects models using lme4. Journal of Statistical Software, 67(1), 1–48. https://doi.org/10.18637/jss.v067.i01
Bates, D., Maechler, M., & Jagan, M. (2024). Matrix: Sparse and dense matrix classes and methods. https://CRAN.R-project.org/package=Matrix
Francisco Rodriguez-Sanchez, & Connor P. Jackson. (2023). grateful: Facilitate citation of r packages. https://pakillo.github.io/grateful/
Garnier, Simon, Ross, Noam, Rudis, Robert, Camargo, Pedro, A., Sciaini, Marco, Scherer, & Cédric. (2023). viridis(Lite) - colorblind-friendly color maps for r. https://doi.org/10.5281/zenodo.4678327
Goodwin, C. (2023). Summarise package & function usage with usedthese. https://cgoo4.github.io/usedthese/
Kassambara, A. (2023a). ggpubr: ggplot2 based publication ready plots. https://CRAN.R-project.org/package=ggpubr
Kassambara, A. (2023b). rstatix: Pipe-friendly framework for basic statistical tests. https://CRAN.R-project.org/package=rstatix
Lenth, R. V. (2024). emmeans: Estimated marginal means, aka least-squares means. https://CRAN.R-project.org/package=emmeans
Müller, K. (2020). here: A simpler way to find your files. https://CRAN.R-project.org/package=here
Pedersen, T. L. (2024). patchwork: The composer of plots. https://CRAN.R-project.org/package=patchwork
R Core Team. (2024). R: A language and environment for statistical computing. R Foundation for Statistical Computing. https://www.R-project.org/
Singmann, H., Bolker, B., Westfall, J., Aust, F., & Ben-Shachar, M. S. (2024). afex: Analysis of factorial experiments. https://CRAN.R-project.org/package=afex
Tiedemann, F. (2022). gghalves: Compose half-half plots using your favourite geoms. https://CRAN.R-project.org/package=gghalves
Wickham, H., Averick, M., Bryan, J., Chang, W., McGowan, L. D., François, R., Grolemund, G., Hayes, A., Henry, L., Hester, J., Kuhn, M., Pedersen, T. L., Miller, E., Bache, S. M., Müller, K., Ooms, J., Robinson, D., Seidel, D. P., Spinu, V., … Yutani, H. (2019). Welcome to the tidyverse. Journal of Open Source Software, 4(43), 1686. https://doi.org/10.21105/joss.01686
Wilke, C. O. (2024). cowplot: Streamlined plot theme and plot annotations for ggplot2. https://CRAN.R-project.org/package=cowplot
Xie, Y. (2014). knitr: A comprehensive tool for reproducible research in R. In V. Stodden, F. Leisch, & R. D. Peng (Eds.), Implementing reproducible computational research. Chapman; Hall/CRC.
Xie, Y. (2015). Dynamic documents with R and knitr (2nd ed.). Chapman; Hall/CRC. https://yihui.org/knitr/
Xie, Y. (2024). knitr: A general-purpose package for dynamic report generation in r. https://yihui.org/knitr/