dataset <- read.csv("data_experiment1.csv",sep=";")
# Percent of trials where the path was left
table(dataset$path_left)/nrow(dataset)
##
## no yes
## 0.92766798 0.07233202
dataset <- subset(dataset,path_left=="no")
dataset$subject_nr <- as.factor(dataset$subject_nr)
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)
))
# 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_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.5556805
## 2 equal right 0.5359645
## 3 unequal left 0.4273087
## 4 unequal right 0.6185367
# 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
## 12785.7 12821.5 -6387.9 12775.7 9383
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.5143 -1.0552 0.7480 0.9041 1.3472
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 0.03493 0.1869
## Number of obs: 9388, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.20837 0.04583 4.547 5.45e-06 ***
## direction1 -0.04879 0.05923 -0.824 0.41
## distance1 -0.50433 0.05959 -8.463 < 2e-16 ***
## direction1:distance1 0.82412 0.08396 9.816 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) drctn1 dstnc1
## direction1 -0.660
## distance1 -0.657 0.508
## drctn1:dst1 0.466 -0.706 -0.710
# 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.2316712 1.1259721 1.3478545 4.5468623 5.445159e-06
## direction1 0.9523775 0.8479638 1.0695833 -0.8237874 4.100604e-01
## distance1 0.6039116 0.5372564 0.6786262 -8.4632635 2.599974e-17
## direction1:distance1 2.2798793 1.9342450 2.6880323 9.8159689 9.611017e-23
# write.table(model_table_baseline_ed,"glmer_table_ed_exp1.csv",sep=";",dec=".")
# 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
## 12785.7 12821.5 -6387.9 12775.7 9383
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.5143 -1.0552 0.7480 0.9041 1.3472
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 0.03493 0.1869
## Number of obs: 9388, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.29596 0.04544 -6.513 7.36e-11 ***
## direction1 0.77533 0.05949 13.033 < 2e-16 ***
## distance1 0.50434 0.05959 8.463 < 2e-16 ***
## direction1:distance1 -0.82414 0.08396 -9.816 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) drctn1 dstnc1
## direction1 -0.651
## distance1 -0.649 0.497
## drctn1:dst1 0.461 -0.709 -0.710
# 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.7438197 0.6802378 0.8130435 -6.513128 7.360195e-11
## direction1 2.1713172 1.9327788 2.4403638 13.032915 7.951047e-39
## distance1 1.6558880 1.4735653 1.8613089 8.463070 2.604297e-17
## direction1:distance1 0.4386106 0.3720193 0.5169976 -9.816130 9.595645e-23
# write.table(model_table_baseline_ud,"glmer_table_ud_exp1.csv",sep=";",dec=".")
# 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.2083772 0.11864677 0.2985140 0.5519066 0.5296269 0.5740792
## 2 Right Equal 0.1595730 0.07141151 0.2480087 0.5398088 0.5178453 0.5616863
## 3 Left Unequal -0.2959607 -0.38531285 -0.2069706 0.4265452 0.4048461 0.4484413
## 4 Right Unequal 0.4793731 0.39008043 0.5693459 0.6175998 0.5963021 0.6386122
# write.table(table_trial_model,"figure_table_exp1.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_exp1.png",width=8.5,height=8.5, unit="cm",dpi=600)
# ggsave("figure_exp1.eps",width=8.5,height=8.5, unit="cm")
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.2992372 ±0.85%
##
## 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: -275.8
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.2059 -0.5668 0.0334 0.5704 2.5803
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 0.002016 0.0449
## Residual 0.014861 0.1219
## Number of obs: 230, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 0.55568 0.01211 224.79000 45.870 <2e-16 ***
## directionright -0.01972 0.01608 114.00000 -1.226 0.223
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## directnrght -0.664
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 : 1.814095e+15 ±0.82%
##
## 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: -188.9
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.43834 -0.75692 0.00566 0.69434 2.43584
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 0.00000 0.0000
## Residual 0.02452 0.1566
## Number of obs: 230, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 0.42731 0.01460 228.00000 29.261 <2e-16 ***
## directionright 0.19123 0.02065 228.00000 9.259 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## directnrght -0.707
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 4580.579
## 2 equal congruent 4535.029
## 3 unequal incongruent 4927.584
## 4 unequal congruent 4266.021
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.628092
## 2 equal congruent 3.624720
## 3 unequal incongruent 3.663636
## 4 unequal congruent 3.594883
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: 82260
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.4567 -0.5565 -0.1414 0.3729 10.2763
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 1624596 1275
## Residual 1814884 1347
## Number of obs: 4746, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 4877.54 122.98 123.00 39.66 <2e-16 ***
## congruency1 -627.19 41.19 5186.00 -15.22 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.200
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, 4646.72 231.78 *** <.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 1116.1901 1457.5478
## .sigma 1320.0558 1374.9389
## (Intercept) 4635.5226 5119.2995
## congruency1 -707.9979 -546.4799
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: 81291.3
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.2690 -0.5225 -0.1322 0.3308 13.2604
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 1628121 1276
## Residual 2178768 1476
## Number of obs: 4642, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 4577.21 122.92 121.00 37.239 <2e-16 ***
## congruency1 -40.04 43.90 6238.00 -0.912 0.362
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.176
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, 4534.41 0.83 .36
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
confint(model_RT_ed, level = .95)
## Computing profile confidence intervals ...
## 2.5 % 97.5 %
## .sig01 1116.3424 1460.21531
## .sigma 1446.0142 1506.83530
## (Intercept) 4335.3486 4818.93310
## congruency1 -126.0836 46.03641
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 : 1.537824e+16 ±0.82%
##
## 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: 3768.4
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.61940 -0.37675 -0.06654 0.31584 2.65742
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 1593417 1262.3
## Residual 210816 459.1
## Number of obs: 230, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 4927.58 125.26 128.10 39.34 <2e-16 ***
## congruency1 -661.56 60.55 116.07 -10.93 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.242
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 : 0.2282974 ±4.03%
##
## 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: 3713.5
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.6583 -0.3768 -0.0478 0.3679 4.7702
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 1670843 1293
## Residual 127483 357
## Number of obs: 230, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 4580.58 125.05 122.37 36.630 <2e-16 ***
## congruency1 -45.55 47.09 116.44 -0.967 0.335
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.188
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: -6979
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -4.2430 -0.6509 -0.0702 0.5808 4.9893
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 0.01620 0.1273
## Residual 0.01217 0.1103
## Number of obs: 4746, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 3.657e+00 1.214e-02 1.200e+02 301.10 <2e-16 ***
## congruency1 -6.363e-02 3.375e-03 4.641e+03 -18.86 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.166
confint(model_logRT_ud,level = .95)
## Computing profile confidence intervals ...
## 2.5 % 97.5 %
## .sig01 0.11156693 0.14540086
## .sigma 0.10810129 0.11259593
## (Intercept) 3.63306662 3.68085306
## congruency1 -0.07025299 -0.05702219
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: -6920.4
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.2266 -0.6362 -0.0656 0.5413 5.8910
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 0.01457 0.1207
## Residual 0.01193 0.1092
## Number of obs: 4642, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 3.628e+00 1.148e-02 1.180e+02 315.923 <2e-16 ***
## congruency1 -2.125e-03 3.249e-03 4.530e+03 -0.654 0.513
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.139
confint(model_logRT_ed,level = .95)
## Computing profile confidence intervals ...
## 2.5 % 97.5 %
## .sig01 0.105770586 0.13793281
## .sigma 0.107004393 0.11150532
## (Intercept) 3.605292795 3.65047872
## congruency1 -0.008493756 0.00424534
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 : 5.410858e+19 ±1.64%
##
## 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: -460.7
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.73360 -0.34127 -0.00776 0.35173 2.75201
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 0.01506 0.12274
## Residual 0.00174 0.04171
## Number of obs: 230, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 3.66364 0.01209 126.41000 303.1 <2e-16 ***
## congruency1 -0.06875 0.00550 114.00000 -12.5 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.228
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 : 0.2115193 ±1.71%
##
## 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: -555.4
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.6424 -0.4453 0.0003 0.4437 2.8307
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 0.0151284 0.1230
## Residual 0.0007784 0.0279
## Number of obs: 230, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 3.628092 0.011761 119.720000 308.486 <2e-16 ***
## congruency1 -0.003372 0.003679 114.000000 -0.916 0.361
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.156
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 594.2839
## 2 congruent 595.0745
# 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: 72877.8
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.6907 -0.4109 -0.0902 0.2009 17.1015
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 106771 326.8
## Residual 363198 602.7
## Number of obs: 4642, groups: subject_nr, 115
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 595.5569 32.9649 132.0000 18.066 <2e-16 ***
## congruency1 0.6324 17.9135 4663.0000 0.035 0.972
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.268
# 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.1493376 ±5.29%
##
## Against denominator:
## mean_initiation_time ~ subject_nr
## ---
## Bayes factor type: BFlinearModel, JZS
hypothesis <- unique(subset(dataset,select=c(subject_nr,hypothesis)))
table(hypothesis$hypothesis)
##
## 0 1
## 101 14
table(hypothesis$hypothesis)/nrow(hypothesis)
##
## 0 1
## 0.8782609 0.1217391
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.5620005
## 2 equal right 0.5420748
## 3 unequal left 0.4233469
## 4 unequal right 0.6263610
# Refactor subject_nr to get rid of non-existing levels
choice_rates_sub$subject_nr <- factor(choice_rates_sub$subject_nr)
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
## 11136.9 11172.0 -5563.4 11126.9 8195
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.5394 -1.0648 0.7376 0.8931 1.3675
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 0.03589 0.1895
## Number of obs: 8200, groups: subject_nr, 101
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.23294 0.04922 4.733 2.21e-06 ***
## direction1 -0.04489 0.06346 -0.707 0.479
## distance1 -0.54633 0.06390 -8.550 < 2e-16 ***
## direction1:distance1 0.87144 0.09002 9.681 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) drctn1 dstnc1
## direction1 -0.660
## distance1 -0.656 0.508
## drctn1:dst1 0.466 -0.705 -0.710
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
## 11136.9 11172.0 -5563.4 11126.9 8195
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.5393 -1.0648 0.7376 0.8931 1.3675
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 0.03589 0.1895
## Number of obs: 8200, groups: subject_nr, 101
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.31340 0.04878 -6.424 1.32e-10 ***
## direction1 0.82655 0.06383 12.949 < 2e-16 ***
## distance1 0.54634 0.06391 8.549 < 2e-16 ***
## direction1:distance1 -0.87145 0.09003 -9.679 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) drctn1 dstnc1
## direction1 -0.649
## distance1 -0.648 0.496
## drctn1:dst1 0.460 -0.709 -0.710
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.296616 ±0.9%
##
## Against denominator:
## percent_right ~ subject_nr
## ---
## Bayes factor type: BFlinearModel, JZS
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 : 3.454584e+14 ±1.25%
##
## Against denominator:
## percent_right ~ subject_nr
## ---
## Bayes factor type: BFlinearModel, JZS
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: 71865
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.4648 -0.5505 -0.1407 0.3726 10.2830
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 1692658 1301
## Residual 1815939 1348
## Number of obs: 4146, groups: subject_nr, 101
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 4802.45 133.87 108.00 35.88 <2e-16 ***
## congruency1 -601.82 44.24 5203.00 -13.60 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.199
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: 70991.1
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.2732 -0.5133 -0.1302 0.3201 12.3961
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 1729778 1315
## Residual 2174857 1475
## Number of obs: 4054, groups: subject_nr, 101
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 4526.93 134.97 105.70 33.541 <2e-16 ***
## congruency1 -53.34 46.92 2277.20 -1.137 0.256
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.171
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 4530.915
## 2 equal congruent 4471.710
## 3 unequal incongruent 4859.326
## 4 unequal congruent 4216.152
# Refactor subject_nr to get rid of non-existing levels
mean_rt_sub$subject_nr <- factor(mean_rt_sub$subject_nr)
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 : 7.68179e+12 ±1.23%
##
## Against denominator:
## mean_rt ~ subject_nr
## ---
## Bayes factor type: BFlinearModel, JZS
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 : 0.3228291 ±15.61%
##
## Against denominator:
## mean_rt ~ subject_nr
## ---
## Bayes factor type: BFlinearModel, JZS
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: -6045.1
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -4.2230 -0.6506 -0.0753 0.5863 4.9647
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 0.0172 0.1312
## Residual 0.0123 0.1109
## Number of obs: 4146, groups: subject_nr, 101
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 3.649e+00 1.335e-02 1.050e+02 273.39 <2e-16 ***
## congruency1 -6.283e-02 3.642e-03 4.053e+03 -17.25 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.164
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: -5994
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.2063 -0.6325 -0.0645 0.5340 5.8518
##
## Random effects:
## Groups Name Variance Std.Dev.
## subject_nr (Intercept) 0.01559 0.1248
## Residual 0.01205 0.1098
## Number of obs: 4054, groups: subject_nr, 101
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 3.621e+00 1.266e-02 1.030e+02 285.960 <2e-16 ***
## congruency1 -2.703e-03 3.494e-03 3.956e+03 -0.774 0.439
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## congruency1 -0.136
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.621526
## 2 equal congruent 3.617408
## 3 unequal incongruent 3.656741
## 4 unequal congruent 3.588046
# Refactor subject_nr to get rid of non-existing levels
mean_logrt_sub$subject_nr <- factor(mean_logrt_sub$subject_nr)
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 : 1.202168e+16 ±2.22%
##
## Against denominator:
## mean_logrt ~ subject_nr
## ---
## Bayes factor type: BFlinearModel, JZS
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 : 0.2456843 ±1.29%
##
## Against denominator:
## mean_logrt ~ subject_nr
## ---
## Bayes factor type: BFlinearModel, JZS