Read in and filter data

dataset <- read.csv("data_experiment2.csv",sep=";")

# Percent of trials where the path was left
table(dataset$path_left)/nrow(dataset)
## 
##         no        yes 
## 0.95296392 0.04703608
dataset <- subset(dataset,path_left=="no")

dataset$subject_nr <- as.factor(dataset$subject_nr)

Load libraries

library(lme4)
library(afex)
library(reshape2)
library(BayesFactor)
library(ggplot2)

# Set ggplot theme
theme_set(theme_classic()+ 
  theme(
    axis.line = element_line(colour = "black"),
    axis.ticks = element_line(colour = "black"),
    axis.text = element_text(colour = "black"),
    panel.border = element_rect(colour = "black", fill=NA)
  ))

Create variables

# Determine choice congruency
dataset$congruency <- ifelse(dataset$response == dataset$direction, 1,0)
dataset$congruency <- factor(dataset$congruency,levels=c(0,1),labels=c("incongruent","congruent"))
contrasts(dataset$congruency) <- c(0,1)

# Calculate logRT
dataset$logRT <- log10(dataset$response_time)

Choice analyses

Choice rates per participant

choice_rates <- dcast(
  dataset,subject_nr+distance+direction~"percent_right",mean,value.var="response_right")

dcast(choice_rates,distance+direction~"percent_right",mean,value.var="percent_right")
##   distance direction percent_right
## 1    equal      left     0.5304062
## 2    equal     right     0.5135616
## 3  unequal      left     0.4406623
## 4  unequal     right     0.5327606

Generalized linear mixed model predicting choice right on trial level

  • Mixed model on trial level predicting probability of saying right
  • Using a binomial link function
  • Specifying a random intercept per participant
  • Dummy coding the effects of direction and distance
  • Baseline condition for direction is always direction left
  • Baseline condition for distance is varied

Baseline: equal distance, direction left

# Set contrasts
contrasts(dataset$direction) <- c(0,1)
contrasts(dataset$distance) <- c(0,1)

# Model results
model_choices_baseline_ed <- glmer(
  response_right~(1|subject_nr)+direction*distance,data=dataset,family="binomial")
summary(model_choices_baseline_ed)
## Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
##  Family: binomial  ( logit )
## Formula: response_right ~ (1 | subject_nr) + direction * distance
##    Data: dataset
## 
##      AIC      BIC   logLik deviance df.resid 
##  10217.4  10252.0  -5103.7  10207.4     7390 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.1055 -1.0348  0.9050  0.9543  1.1889 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 0.01019  0.1009  
## Number of obs: 7395, groups:  subject_nr, 194
## 
## Fixed effects:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)           0.11801    0.04779   2.469   0.0135 *  
## direction1           -0.06244    0.06617  -0.944   0.3453    
## distance1            -0.36078    0.06657  -5.420 5.97e-08 ***
## direction1:distance1  0.44258    0.09346   4.736 2.18e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) drctn1 dstnc1
## direction1  -0.706              
## distance1   -0.701  0.507       
## drctn1:dst1  0.500 -0.708 -0.712
# Odds ratio table
coef_baseline_ed <- summary(model_choices_baseline_ed)$coefficients
ci_coef_baseline_ed <- confint(model_choices_baseline_ed,level = .95)
## Computing profile confidence intervals ...
model_table_baseline_ed <- cbind(
  exp(coef_baseline_ed[,1]),
  exp(ci_coef_baseline_ed[-1,1]),
  exp(ci_coef_baseline_ed[-1,2]),
  coef_baseline_ed[,3:4]
)
colnames(model_table_baseline_ed)<-c("OR","CIl","CIu","z","p")
model_table_baseline_ed
##                             OR       CIl       CIu          z            p
## (Intercept)          1.1252500 1.0246831 1.2359420  2.4691180 1.354465e-02
## direction1           0.9394687 0.8251813 1.0695375 -0.9436893 3.453285e-01
## distance1            0.6971289 0.6117717 0.7941819 -5.4198218 5.965846e-08
## direction1:distance1 1.5567194 1.2962803 1.8698039  4.7357207 2.182781e-06
# write.table(model_table_baseline_ed,"glmer_table_ed_exp2.csv",sep=";",dec=".")

Baseline: unequal distance, direction left

# Set contrasts
contrasts(dataset$direction) <- c(0,1)
contrasts(dataset$distance) <- c(1,0)

# Model results
model_choices_baseline_ud <- glmer(
  response_right~(1|subject_nr)+direction*distance,data=dataset,family="binomial")
summary(model_choices_baseline_ud)
## Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
##  Family: binomial  ( logit )
## Formula: response_right ~ (1 | subject_nr) + direction * distance
##    Data: dataset
## 
##      AIC      BIC   logLik deviance df.resid 
##  10217.4  10252.0  -5103.7  10207.4     7390 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.1055 -1.0348  0.9050  0.9543  1.1889 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 0.01019  0.1009  
## Number of obs: 7395, groups:  subject_nr, 194
## 
## Fixed effects:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)          -0.24278    0.04745  -5.116 3.12e-07 ***
## direction1            0.38014    0.06599   5.760 8.39e-09 ***
## distance1             0.36078    0.06657   5.420 5.97e-08 ***
## direction1:distance1 -0.44258    0.09346  -4.736 2.18e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) drctn1 dstnc1
## direction1  -0.702              
## distance1   -0.696  0.501       
## drctn1:dst1  0.496 -0.706 -0.712
# Odds ratios
coef_baseline_ud <- summary(model_choices_baseline_ud)$coefficients
ci_coef_baseline_ud <- confint(model_choices_baseline_ud,level = .95)
## Computing profile confidence intervals ...
model_table_baseline_ud <- cbind(
  exp(coef_baseline_ud[,1]),
  exp(ci_coef_baseline_ud[-1,1]),
  exp(ci_coef_baseline_ud[-1,2]),
  coef_baseline_ud[,3:4]
)
colnames(model_table_baseline_ud)<-c("OR","CIl","CIu","z","p")
model_table_baseline_ud
##                             OR       CIl       CIu         z            p
## (Intercept)          0.7844438 0.7145839 0.8607686 -5.116044 3.120104e-07
## direction1           1.4624886 1.2852273 1.6646697  5.760432 8.389885e-09
## distance1            1.4344532 1.2591574 1.6345966  5.419802 5.966512e-08
## direction1:distance1 0.6423797 0.5348154 0.7714381 -4.735638 2.183673e-06
# write.table(model_table_baseline_ud,"glmer_table_ud_exp2.csv",sep=";",dec=".")

Figure

# Extract CIs from model using confint
trial_model <- glmer(response_right~(1|subject_nr)+0+interaction(direction,distance),data=dataset,family="binomial")
trial_model_ci <- confint(trial_model)
## Computing profile confidence intervals ...
table_trial_model <- data.frame(
  direction = rep(c("Left","Right"),2),
  distance = rep(c("Equal","Unequal"),each=2),
  logodds = fixef(trial_model),
  logodds_lower = trial_model_ci[-1,1],
  logodds_upper = trial_model_ci[-1,2]
  )

table_trial_model$p <-
  with(table_trial_model,
       exp(logodds)/(1+exp(logodds)))

table_trial_model$p_lower <-
  with(table_trial_model,
       exp(logodds_lower)/(1+exp(logodds_lower)))

table_trial_model$p_upper <-
  with(table_trial_model,
       exp(logodds_upper)/(1+exp(logodds_upper)))

rownames(table_trial_model) <- NULL

table_trial_model
##   direction distance    logodds logodds_lower logodds_upper         p   p_lower   p_upper
## 1      Left    Equal  0.1180024    0.02438337     0.2118335 0.5294664 0.5060955 0.5527612
## 2     Right    Equal  0.0555652   -0.03636509     0.1475669 0.5138877 0.4909097 0.5368249
## 3      Left  Unequal -0.2427832   -0.33605482    -0.1499295 0.4396006 0.4167681 0.4625877
## 4     Right  Unequal  0.1373590    0.04532661     0.2296120 0.5342858 0.5113297 0.5571521
# write.table(table_trial_model,"figure_table_exp2.csv",sep=";",dec=".")

ggplot(table_trial_model,aes(x=direction,y=p,group=distance,linetype=distance))+
  geom_errorbar(aes(ymin=p_lower,ymax=p_upper),stat="identity",width=.15,linetype="solid")+
  geom_line(stat="identity")+
  geom_point(stat="identity",size=2,shape=16)+
  xlab("Direction")+ ylab("Probability of right-side option choices")+
  coord_cartesian(ylim=c(.3,.7))+
  scale_linetype(name="Distance")+
  theme(legend.justification=c(1,0), legend.position=c(.95,.05))

# ggsave("figure_exp2.png",width=8.5,height=8.5, unit="cm",dpi=600)
# ggsave("figure_exp2.eps",width=8.5,height=8.5, unit="cm")

Bayes factors for choice rates

BF of direction in equal distance condition

BF_choice_ed_0 <- lmBF(percent_right ~ subject_nr, whichRandom = "subject_nr",
             data=subset(choice_rates,distance=="equal"))
BF_choice_ed_1 <- lmBF(percent_right ~ direction + subject_nr, whichRandom = "subject_nr",
             data=subset(choice_rates,distance=="equal"))

BF_choice_ed_1/BF_choice_ed_0
## Bayes factor analysis
## --------------
## [1] direction + subject_nr : 0.1833583 ±0.84%
## 
## Against denominator:
##   percent_right ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS
# linear mixed model for choice rates (not reported, just used to check that
# results using choice rates replicate trial level analyses - this is the case)
summary(lmer(percent_right~(1|subject_nr)+direction,
             data=subset(choice_rates,distance=="equal")))
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: percent_right ~ (1 | subject_nr) + direction
##    Data: subset(choice_rates, distance == "equal")
## 
## REML criterion at convergence: -238.8
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.26616 -0.66593 -0.01947  0.64928  2.72321 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 0.003245 0.05696 
##  Residual               0.027619 0.16619 
## Number of obs: 388, groups:  subject_nr, 194
## 
## Fixed effects:
##                 Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)      0.53041    0.01261 381.80000  42.052   <2e-16 ***
## directionright  -0.01684    0.01687 193.00000  -0.998    0.319    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## directnrght -0.669

BF of direction in unequal distance condition

BF_choice_ud_0 <- lmBF(percent_right ~ subject_nr, whichRandom = "subject_nr",
             data=subset(choice_rates,distance=="unequal"))
BF_choice_ud_1 <- lmBF(percent_right ~ direction + subject_nr, whichRandom = "subject_nr",
             data=subset(choice_rates,distance=="unequal"))

BF_choice_ud_1/BF_choice_ud_0
## Bayes factor analysis
## --------------
## [1] direction + subject_nr : 18359.88 ±1.13%
## 
## Against denominator:
##   percent_right ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS
# linear mixed model for choice rates (not reported, just used to check that
# results using choice rates replicate trial level analyses - this is the case)
summary(lmer(percent_right~(1|subject_nr)+direction,
             data=subset(choice_rates,distance=="unequal")))
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: percent_right ~ (1 | subject_nr) + direction
##    Data: subset(choice_rates, distance == "unequal")
## 
## REML criterion at convergence: -198.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.3886 -0.7196 -0.1776  0.7258  2.5327 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 0.00000  0.0000  
##  Residual               0.03403  0.1845  
## Number of obs: 388, groups:  subject_nr, 194
## 
## Fixed effects:
##                 Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)      0.44066    0.01325 386.00000  33.270  < 2e-16 ***
## directionright   0.09210    0.01873 386.00000   4.917  1.3e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## directnrght -0.707

Reaction time analyses

Data aggregation and descriptives

RT

mean_rt <- dcast(
  dataset,subject_nr+distance+congruency~"mean_rt",mean,value.var="response_time")
dcast(mean_rt,distance+congruency~"mean_rt",mean,value.var="mean_rt")
##   distance  congruency  mean_rt
## 1    equal incongruent 5113.881
## 2    equal   congruent 5330.952
## 3  unequal incongruent 5679.273
## 4  unequal   congruent 5085.353

logRT

mean_logrt <- dcast(
  dataset,subject_nr+distance+congruency~"mean_logrt",mean,value.var="logRT")
dcast(mean_logrt,distance+congruency~"mean_logrt",mean,value.var="mean_logrt")
##   distance  congruency mean_logrt
## 1    equal incongruent   3.672509
## 2    equal   congruent   3.688679
## 3  unequal incongruent   3.718912
## 4  unequal   congruent   3.664292

Analyses with untransformed RT

Linear mixed model for trial level RTs

Effect of congruency in unequal distance condition

model_RT_ud <- lmer(response_time~(1|subject_nr)+congruency,
             data=dataset,subset=distance=="unequal")
summary(model_RT_ud)
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: response_time ~ (1 | subject_nr) + congruency
##    Data: dataset
##  Subset: distance == "unequal"
## 
## REML criterion at convergence: 66909.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4945 -0.5117 -0.1161  0.3765 11.9047 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 2855983  1690    
##  Residual               3269222  1808    
## Number of obs: 3721, groups:  subject_nr, 194
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)  5611.32     129.44  222.00  43.350   <2e-16 ***
## congruency1  -540.30      62.12 4610.00  -8.698   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.262
mixed(response_time~(1|subject_nr)+congruency,data=subset(dataset,distance=="unequal"))
## Contrasts set to contr.sum for the following variables: subject_nr, congruency
## Fitting one lmer() model. [DONE]
## Calculating p-values. [DONE]
## Mixed Model Anova Table (Type 3 tests, KR-method)
## 
## Model: response_time ~ (1 | subject_nr) + congruency
## Data: subset
## Data: dataset
## Data: distance == "unequal"
##       Effect         df         F p.value
## 1 congruency 1, 3562.05 75.65 ***  <.0001
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
confint(model_RT_ud, level = .95)
## Computing profile confidence intervals ...
##                 2.5 %    97.5 %
## .sig01      1520.5035 1878.6968
## .sigma      1766.4600 1850.8707
## (Intercept) 5357.0517 5865.4237
## congruency1 -662.1428 -418.5826

Effect of congruency in equal distance condition

model_RT_ed <- lmer(response_time~(1|subject_nr)+congruency,
             data=dataset,subset=distance=="equal")
summary(model_RT_ed)
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: response_time ~ (1 | subject_nr) + congruency
##    Data: dataset
##  Subset: distance == "equal"
## 
## REML criterion at convergence: 65543.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1456 -0.5339 -0.1323  0.3646  8.4034 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 2486577  1577    
##  Residual               2833130  1683    
## Number of obs: 3674, groups:  subject_nr, 194
## 
## Fixed effects:
##             Estimate Std. Error     df t value Pr(>|t|)    
## (Intercept)   5111.9      119.9  215.0  42.625  < 2e-16 ***
## congruency1    196.4       57.0 4991.0   3.446 0.000573 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.234
mixed(response_time~(1|subject_nr)+congruency,data=subset(dataset,distance=="equal"))
## Contrasts set to contr.sum for the following variables: subject_nr, congruency
## Fitting one lmer() model. [DONE]
## Calculating p-values. [DONE]
## Mixed Model Anova Table (Type 3 tests, KR-method)
## 
## Model: response_time ~ (1 | subject_nr) + congruency
## Data: subset
## Data: dataset
## Data: distance == "equal"
##       Effect         df         F p.value
## 1 congruency 1, 3501.00 11.88 ***   .0006
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
confint(model_RT_ed, level = .95)
## Computing profile confidence intervals ...
## Warning in optwrap(optimizer, par = start, fn = function(x) dd(mkpar(npar1, : convergence code 3 from bobyqa: bobyqa --
## a trust region step failed to reduce q
##                  2.5 %    97.5 %
## .sig01      1418.71229 1753.0662
## .sigma      1644.17047 1723.2778
## (Intercept) 4876.32429 5347.3625
## congruency1   84.64866  308.1237

Bayes factors for mean RTs

BF of congruency in unequal distance condition

BF_rt_ud_0 <- lmBF(mean_rt ~ subject_nr, whichRandom = "subject_nr",
             data=subset(mean_rt,distance=="unequal"))
BF_rt_ud_1 <- lmBF(mean_rt ~ congruency + subject_nr, whichRandom = "subject_nr",
             data=subset(mean_rt,distance=="unequal"))

BF_rt_ud_1/BF_rt_ud_0
## Bayes factor analysis
## --------------
## [1] congruency + subject_nr : 484394910889 ±0.84%
## 
## Against denominator:
##   mean_rt ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS
# linear mixed model for mean RTs (not reported, just used to check
# that results on aggregate data replicate trial level analyses - this is the case)
summary(lmer(mean_rt~(1|subject_nr)+congruency,
             data=subset(mean_rt,distance=="unequal")))
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: mean_rt ~ (1 | subject_nr) + congruency
##    Data: subset(mean_rt, distance == "unequal")
## 
## REML criterion at convergence: 6598
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.56262 -0.40750 -0.08059  0.37225  3.15188 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 2800307  1673.4  
##  Residual                447643   669.1  
## Number of obs: 386, groups:  subject_nr, 194
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)  5657.35     129.56  221.78   43.66  < 2e-16 ***
## congruency1  -572.00      68.26  173.42   -8.38 1.75e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.266

BF of congruency in equal distance condition

BF_rt_ed_0 <- lmBF(mean_rt ~ subject_nr, whichRandom = "subject_nr",
             data=subset(mean_rt,distance=="equal"))
BF_rt_ed_1 <- lmBF(mean_rt ~ congruency + subject_nr, whichRandom = "subject_nr",
             data=subset(mean_rt,distance=="equal"))

BF_rt_ed_1/BF_rt_ed_0
## Bayes factor analysis
## --------------
## [1] congruency + subject_nr : 422.8445 ±2.15%
## 
## Against denominator:
##   mean_rt ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS
# linear mixed model for mean RTs (not reported, just used to check
# that results on aggregate data replicate trial level analyses - this is the case)
summary(lmer(mean_rt~(1|subject_nr)+congruency,
             data=subset(mean_rt,distance=="equal")))
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: mean_rt ~ (1 | subject_nr) + congruency
##    Data: subset(mean_rt, distance == "equal")
## 
## REML criterion at convergence: 6500.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1200 -0.4082 -0.0552  0.3652  3.6767 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 2551429  1597.3  
##  Residual                256393   506.4  
## Number of obs: 388, groups:  subject_nr, 194
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)  5113.88     120.31  211.42  42.508  < 2e-16 ***
## congruency1   217.07      51.41  191.77   4.222 3.73e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.214

Analyses with logRT

Linear mixed model for trial level logRTs

Effect of congruency in unequal distance condition

model_logRT_ud <- lmer(logRT~(1|subject_nr)+congruency,
             data=dataset,subset=distance=="unequal")
summary(model_logRT_ud)
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: logRT ~ (1 | subject_nr) + congruency
##    Data: dataset
##  Subset: distance == "unequal"
## 
## REML criterion at convergence: -4481.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8417 -0.6317 -0.0355  0.5857  4.7625 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 0.01853  0.1361  
##  Residual               0.01479  0.1216  
## Number of obs: 3721, groups:  subject_nr, 194
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  3.712e+00  1.023e-02  2.130e+02  362.75   <2e-16 ***
## congruency1 -4.907e-02  4.181e-03  3.551e+03  -11.73   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.223
confint(model_logRT_ud,level = .95)
## Computing profile confidence intervals ...
##                   2.5 %     97.5 %
## .sig01       0.12270756  0.1510711
## .sigma       0.11880407  0.1244812
## (Intercept)  3.69183860  3.7320313
## congruency1 -0.05726597 -0.0408731

Effect of congruency in equal distance condition

model_logRT_ed <- lmer(logRT~(1|subject_nr)+congruency,
             data=dataset,subset=distance=="equal")
summary(model_logRT_ed)
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: logRT ~ (1 | subject_nr) + congruency
##    Data: dataset
##  Subset: distance == "equal"
## 
## REML criterion at convergence: -4645.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7797 -0.6252 -0.0531  0.5770  3.9506 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 0.01731  0.1316  
##  Residual               0.01391  0.1179  
## Number of obs: 3674, groups:  subject_nr, 194
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept) 3.672e+00  9.845e-03 2.090e+02 373.011  < 2e-16 ***
## congruency1 1.496e-02  3.996e-03 3.495e+03   3.744 0.000184 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.200
confint(model_logRT_ed,level = .95)
## Computing profile confidence intervals ...
##                   2.5 %     97.5 %
## .sig01      0.118614232 0.14604553
## .sigma      0.115208792 0.12075196
## (Intercept) 3.653075001 3.69174870
## congruency1 0.007123712 0.02278942

Bayes factors for mean logRTs

BF of congruency in unequal distance condition

BF_logrt_ud_0 <- lmBF(mean_logrt ~ subject_nr, whichRandom = "subject_nr",
             data=subset(mean_logrt,distance=="unequal"))
BF_logrt_ud_1 <- lmBF(mean_logrt ~ subject_nr + congruency, whichRandom = "subject_nr",
             data=subset(mean_logrt,distance=="unequal"))

BF_logrt_ud_1/BF_logrt_ud_0
## Bayes factor analysis
## --------------
## [1] subject_nr + congruency : 1.171341e+17 ±1.32%
## 
## Against denominator:
##   mean_logrt ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS
# linear mixed model for mean logRTs (not reported, just used to check
# that results on aggregate data replicate trial level analyses - this is the case)
summary(lmer(mean_logrt~(1|subject_nr)+congruency,
             data=subset(mean_logrt,distance=="unequal")))
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: mean_logrt ~ (1 | subject_nr) + congruency
##    Data: subset(mean_logrt, distance == "unequal")
## 
## REML criterion at convergence: -678.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.2955 -0.4648 -0.0199  0.4561  2.4056 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 0.017861 0.13365 
##  Residual               0.002459 0.04959 
## Number of obs: 386, groups:  subject_nr, 194
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)   3.71661    0.01025 217.90000  362.72   <2e-16 ***
## congruency1  -0.05232    0.00506 190.72000  -10.34   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.249

BF of congruency in equal distance condition

BF_logrt_ed_0 <- lmBF(mean_logrt ~ subject_nr, whichRandom = "subject_nr",
             data=subset(mean_logrt,distance=="equal"))
BF_logrt_ed_1 <- lmBF(mean_logrt ~ subject_nr+ congruency, whichRandom = "subject_nr",
             data=subset(mean_logrt,distance=="equal"))

BF_logrt_ed_1/BF_logrt_ed_0
## Bayes factor analysis
## --------------
## [1] subject_nr + congruency : 394.3089 ±1.12%
## 
## Against denominator:
##   mean_logrt ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS
# linear mixed model for mean logRTs (not reported, just used to check
# that results replicate trial level analyses - this is the case)
summary(lmer(mean_logrt~(1|subject_nr)+congruency,
             data=subset(mean_logrt,distance=="equal")))
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: mean_logrt ~ (1 | subject_nr) + congruency
##    Data: subset(mean_logrt, distance == "equal")
## 
## REML criterion at convergence: -797.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1464 -0.3797  0.0050  0.3691  3.4095 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 0.017441 0.13207 
##  Residual               0.001431 0.03783 
## Number of obs: 388, groups:  subject_nr, 194
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept) 3.673e+00  9.863e-03 2.082e+02 372.347  < 2e-16 ***
## congruency1 1.617e-02  3.841e-03 1.930e+02   4.209 3.92e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.195

Initiation time analysis in equal distance condition

Data aggregation and descriptives

mean_initiation_time <- dcast(data = subset(dataset,distance=="equal"),
  subject_nr+congruency~"mean_initiation_time",mean,value.var="initiation_time")
dcast(mean_initiation_time,congruency~"mean_initiation_time",mean,value.var="mean_initiation_time")
##    congruency mean_initiation_time
## 1 incongruent             524.1179
## 2   congruent             524.7929

Effect of congruency

# Linear mixed model on trial level
summary(lmer(initiation_time~(1|subject_nr)+congruency,
             data=dataset,subset=distance=="equal"))
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: initiation_time ~ (1 | subject_nr) + congruency
##    Data: dataset
##  Subset: distance == "equal"
## 
## REML criterion at convergence: 56634.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -6.8223 -0.2891 -0.0312  0.1811 21.5144 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 181411   425.9   
##  Residual               252878   502.9   
## Number of obs: 3674, groups:  subject_nr, 194
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  524.866     32.783  221.000  16.010   <2e-16 ***
## congruency1   -2.287     17.023 3513.000  -0.134    0.893    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.256
# Bayes factor for mean initiation times
BF_init_ed_0 <- lmBF(mean_initiation_time ~ subject_nr, whichRandom = "subject_nr",
             data=mean_initiation_time)
BF_init_ed_1 <- lmBF(mean_initiation_time ~ subject_nr + congruency, whichRandom = "subject_nr",
             data=mean_initiation_time)

BF_init_ed_1/BF_init_ed_0
## Bayes factor analysis
## --------------
## [1] subject_nr + congruency : 0.1085665 ±0.75%
## 
## Against denominator:
##   mean_initiation_time ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS

Analyses for subset of participants

Descriptives

hypothesis <- unique(subset(dataset,select=c(subject_nr,hypothesis)))
table(hypothesis$hypothesis)
## 
##   0   1 
## 172  22
table(hypothesis$hypothesis)/nrow(hypothesis)
## 
##         0         1 
## 0.8865979 0.1134021

Choice rates per participant

choice_rates_sub <- dcast(
  subset(dataset,hypothesis==0),subject_nr+distance+direction~"percent_right",mean,value.var="response_right")
dcast(choice_rates_sub,distance+direction~"percent_right",mean,value.var="percent_right")
##   distance direction percent_right
## 1    equal      left     0.5301380
## 2    equal     right     0.5163944
## 3  unequal      left     0.4384459
## 4  unequal     right     0.5294251
# Refactor subject_nr to get rid of non-existing levels
choice_rates_sub$subject_nr <- factor(choice_rates_sub$subject_nr)

Generalized linear mixed model predicting choice right on trial level

Baseline: equal distance, direction left

contrasts(dataset$direction) <- c(0,1)
contrasts(dataset$distance) <- c(0,1)
summary(glmer(response_right~(1|subject_nr)+direction*distance,
              data=dataset,family="binomial",subset=hypothesis==0))
## Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
##  Family: binomial  ( logit )
## Formula: response_right ~ (1 | subject_nr) + direction * distance
##    Data: dataset
##  Subset: hypothesis == 0
## 
##      AIC      BIC   logLik deviance df.resid 
##   9049.5   9083.4  -4519.7   9039.5     6545 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.1225 -1.0350  0.8961  0.9543  1.2203 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 0.01497  0.1223  
## Number of obs: 6550, groups:  subject_nr, 172
## 
## Fixed effects:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)           0.11564    0.05105   2.265   0.0235 *  
## direction1           -0.04908    0.07036  -0.698   0.4854    
## distance1            -0.36878    0.07074  -5.213 1.86e-07 ***
## direction1:distance1  0.42480    0.09936   4.275 1.91e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) drctn1 dstnc1
## direction1  -0.701              
## distance1   -0.698  0.506       
## drctn1:dst1  0.497 -0.708 -0.712

Baseline: unequal distance, direction left

contrasts(dataset$direction) <- c(0,1)
contrasts(dataset$distance) <- c(1,0)
summary(glmer(response_right~(1|subject_nr)+direction*distance,
              data=dataset,family="binomial",subset=hypothesis==0))
## Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
##  Family: binomial  ( logit )
## Formula: response_right ~ (1 | subject_nr) + direction * distance
##    Data: dataset
##  Subset: hypothesis == 0
## 
##      AIC      BIC   logLik deviance df.resid 
##   9049.5   9083.4  -4519.7   9039.5     6545 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.1225 -1.0350  0.8961  0.9543  1.2203 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 0.01496  0.1223  
## Number of obs: 6550, groups:  subject_nr, 172
## 
## Fixed effects:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)          -0.25313    0.05072  -4.991 6.01e-07 ***
## direction1            0.37571    0.07015   5.355 8.53e-08 ***
## distance1             0.36878    0.07075   5.213 1.86e-07 ***
## direction1:distance1 -0.42480    0.09937  -4.275 1.91e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) drctn1 dstnc1
## direction1  -0.699              
## distance1   -0.693  0.501       
## drctn1:dst1  0.493 -0.706 -0.712

Bayes factors for choice rates

BF of direction in equal distance condition

BF_choicerates_ed_0 <- lmBF(percent_right ~ subject_nr, whichRandom = "subject_nr",
             data=subset(choice_rates_sub,distance=="equal"))
BF_choicerates_ed_1 <- lmBF(percent_right ~ subject_nr+ direction, whichRandom = "subject_nr",
             data=subset(choice_rates_sub,distance=="equal"))

BF_choicerates_ed_1/BF_choicerates_ed_0
## Bayes factor analysis
## --------------
## [1] subject_nr + direction : 0.1609907 ±3.95%
## 
## Against denominator:
##   percent_right ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS

BF of direction in unequal distance condition

BF_choicerates_ud_0 <- lmBF(percent_right ~ subject_nr, whichRandom = "subject_nr",
             data=subset(choice_rates_sub,distance=="unequal"))
BF_choicerates_ud_1 <- lmBF(percent_right ~ subject_nr + direction, whichRandom = "subject_nr",
             data=subset(choice_rates_sub,distance=="unequal"))

BF_choicerates_ud_1/BF_choicerates_ud_0
## Bayes factor analysis
## --------------
## [1] subject_nr + direction : 2849.211 ±0.84%
## 
## Against denominator:
##   percent_right ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS

Linear mixed model for trial level RTs

Effect of congruency in unequal distance condition

summary(lmer(response_time~(1|subject_nr)+congruency,
             data=dataset,subset=distance=="unequal"&hypothesis==0))
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: response_time ~ (1 | subject_nr) + congruency
##    Data: dataset
##  Subset: distance == "unequal" & hypothesis == 0
## 
## REML criterion at convergence: 59354.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4656 -0.5033 -0.1149  0.3763 11.7852 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 2923065  1710    
##  Residual               3341063  1828    
## Number of obs: 3297, groups:  subject_nr, 172
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)  5564.29     139.08  196.60  40.008  < 2e-16 ***
## congruency1  -511.21      66.82 2897.90  -7.651 2.71e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.262

Effect of congruency in equal distance condition

summary(lmer(response_time~(1|subject_nr)+congruency,
             data=dataset,subset=distance=="equal"&hypothesis==0))
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: response_time ~ (1 | subject_nr) + congruency
##    Data: dataset
##  Subset: distance == "equal" & hypothesis == 0
## 
## REML criterion at convergence: 58031.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1478 -0.5308 -0.1264  0.3709  8.4019 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 2514939  1586    
##  Residual               2832335  1683    
## Number of obs: 3253, groups:  subject_nr, 172
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)  5071.77     128.04  191.00  39.610  < 2e-16 ***
## congruency1   204.36      60.58 3457.00   3.373 0.000751 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.234

Bayes factors for mean RTs

Aggregate data

mean_rt_sub <- dcast(
  subset(dataset,hypothesis==0),subject_nr+distance+congruency~"mean_rt",mean,value.var="response_time")
dcast(mean_rt_sub,distance+congruency~"mean_rt",mean,value.var="mean_rt")
##   distance  congruency  mean_rt
## 1    equal incongruent 5076.702
## 2    equal   congruent 5302.290
## 3  unequal incongruent 5629.192
## 4  unequal   congruent 5065.919
# Refactor subject_nr to get rid of non-existing levels
mean_rt_sub$subject_nr <- factor(mean_rt_sub$subject_nr)

BF of congruency in unequal distance condition

BF_congr_ud_0 <- lmBF(mean_rt ~ subject_nr, whichRandom = "subject_nr",
             data=subset(mean_rt_sub,distance=="unequal"))
BF_congr_ud_1 <- lmBF(mean_rt ~ subject_nr + congruency, whichRandom = "subject_nr",
             data=subset(mean_rt_sub,distance=="unequal"))

BF_congr_ud_1/BF_congr_ud_0
## Bayes factor analysis
## --------------
## [1] subject_nr + congruency : 5012516271 ±1.88%
## 
## Against denominator:
##   mean_rt ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS

BF of congruency in equal distance condition

BF_congr_ed_0 <- lmBF(mean_rt ~ subject_nr, whichRandom = "subject_nr",
             data=subset(mean_rt_sub,distance=="equal"))
BF_congr_ed_1 <- lmBF(mean_rt ~ subject_nr + congruency, whichRandom = "subject_nr",
             data=subset(mean_rt_sub,distance=="equal"))

BF_congr_ed_1/BF_congr_ed_0
## Bayes factor analysis
## --------------
## [1] subject_nr + congruency : 233.5361 ±1.1%
## 
## Against denominator:
##   mean_rt ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS

Linear mixed model for trial level logRTs

Effect of congruency in unequal distance condition

summary(lmer(logRT~(1|subject_nr)+congruency,
             data=dataset,subset=distance=="unequal"&hypothesis==0))
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: logRT ~ (1 | subject_nr) + congruency
##    Data: dataset
##  Subset: distance == "unequal" & hypothesis == 0
## 
## REML criterion at convergence: -3909.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8111 -0.6314 -0.0306  0.5884  4.7280 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 0.01908  0.1381  
##  Residual               0.01505  0.1227  
## Number of obs: 3297, groups:  subject_nr, 172
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  3.708e+00  1.103e-02  1.886e+02  336.29   <2e-16 ***
## congruency1 -4.750e-02  4.488e-03  3.147e+03  -10.58   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.222

Effect of congruency in equal distance condition

summary(lmer(logRT~(1|subject_nr)+congruency,
             data=dataset,subset=distance=="equal"&hypothesis==0))
## Linear mixed model fit by REML 
## t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
## Formula: logRT ~ (1 | subject_nr) + congruency
##    Data: dataset
##  Subset: distance == "equal" & hypothesis == 0
## 
## REML criterion at convergence: -4059.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7487 -0.6262 -0.0498  0.5845  3.9203 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_nr (Intercept) 0.01771  0.1331  
##  Residual               0.01413  0.1189  
## Number of obs: 3253, groups:  subject_nr, 172
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept) 3.669e+00  1.057e-02 1.851e+02 346.922  < 2e-16 ***
## congruency1 1.508e-02  4.281e-03 3.094e+03   3.524 0.000432 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## congruency1 -0.200

Bayes factors for mean logRTs

Aggregate data

mean_logrt_sub <- dcast(
  subset(dataset,hypothesis==0),subject_nr+distance+congruency~"mean_logrt",mean,value.var="logRT")
dcast(mean_logrt_sub,distance+congruency~"mean_logrt",mean,value.var="mean_logrt")
##   distance  congruency mean_logrt
## 1    equal incongruent   3.668901
## 2    equal   congruent   3.685260
## 3  unequal incongruent   3.714660
## 4  unequal   congruent   3.661454
# Refactor subject_nr to get rid of non-existing levels
mean_logrt_sub$subject_nr <- factor(mean_logrt_sub$subject_nr)

BF of congruency in unequal distance condition

BF_congr_lgrt_ud_0 <- lmBF(mean_logrt ~ subject_nr, whichRandom = "subject_nr",
             data=subset(mean_logrt_sub,distance=="unequal"))
BF_congr_lgrt_ud_1 <- lmBF(mean_logrt ~ subject_nr + congruency, whichRandom = "subject_nr",
             data=subset(mean_logrt_sub,distance=="unequal"))

BF_congr_lgrt_ud_1/BF_congr_lgrt_ud_0
## Bayes factor analysis
## --------------
## [1] subject_nr + congruency : 2.527551e+14 ±0.91%
## 
## Against denominator:
##   mean_logrt ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS

BF of congruency in equal distance condition

BF_congr_lgrt_ed_0 <- lmBF(mean_logrt ~ subject_nr, whichRandom = "subject_nr",
             data=subset(mean_logrt_sub,distance=="equal"))
BF_congr_lgrt_ed_1 <- lmBF(mean_logrt ~ subject_nr + congruency, whichRandom = "subject_nr",
             data=subset(mean_logrt_sub,distance=="equal"))

BF_congr_lgrt_ed_1/BF_congr_lgrt_ed_0
## Bayes factor analysis
## --------------
## [1] subject_nr + congruency : 159.8477 ±1.49%
## 
## Against denominator:
##   mean_logrt ~ subject_nr 
## ---
## Bayes factor type: BFlinearModel, JZS