--- output: html_document: default pdf_document: default --- ```{r setup, include=FALSE, cache=FALSE} options( scipen = 1, digits = 3) #set to two decimal ``` ```{r load packages, message=FALSE, warning=FALSE, include=FALSE} #LIBRERIE library(tidyverse) library(ggplot2) library(BayesFactor) library(afex) library(psych) library("plyr") # detach(package:plyr) library(emmeans) library("EnvStats") # library('Cairo') library("nparLD") library("coin") library(rstatix) library(dplyr) library(rcompanion) library(polycor) library("Hmisc") library("readxl") library(lsr) library('ggpattern') library(stringr) library("pwr") library(knitr) ``` ```{r read data and plotting, echo=FALSE, message=FALSE, warning=FALSE} # non spatial ---------------------------- df <- read_excel("ordinal_nospatial_D26-L26.xlsx") df <- df%>%filter(is.na(subjectID)==FALSE) df1 <- df%>%gather(exp,percent,-subjectID, -hatch_condition) df1[c('test', 'choice')] <- str_split_fixed(df1$exp, '_', 2) df1$test <- mapvalues(df1$test, from = unique(df1$test), to = c('sagittal',"FP binocular","FP left","FP right")) test_choice <- ddply(df1, c("test","hatch_condition","choice"), summarise, Mean = mean(percent), sd = sd(percent), n = sum(!is.na(percent)), se = sd / sqrt (n)) test_choice$test <- factor(test_choice$test, levels = c('sagittal',"FP binocular","FP left","FP right")) test_choice$choice <- factor(test_choice$choice, levels = c(1:10,"1L","2L","3L","4L","5L", "5R","4R","3R","2R","1R")) # windowsFonts(Times=windowsFont("Arial")) ggplot(test_choice, aes(x=choice, y=Mean, colour = hatch_condition)) + geom_hline(yintercept=10, color='grey', size=0.4,lty=5) + geom_line(aes(group = hatch_condition)) + facet_wrap(~test,scales='free_x',ncol=2)+ geom_point(size = 1) + ylim(0,45) + geom_pointrange(aes(ymin=(Mean-se), ymax=(Mean+se)), width=0.2, position=position_dodge(0)) + labs(title = "Without spatial information", x = "Positions", y="First choice - Percentage (%)") + theme(legend.position="right")+ # guides(shape=FALSE)+ theme_classic() + scale_color_manual(values=c("#4b0ffb","#fc7e0f"),name="Hatch Condition")+ theme(text = element_text(size=14, family="Arial"), panel.background = element_rect(fill = "transparent", color = "black"), plot.background = element_rect(fill = "transparent")) + theme(axis.text.x = element_text(size = 10), axis.text.y = element_text(size = 12), strip.text.x = element_text(size = 12), strip.text.y = element_text(size = 12), legend.text = element_text(size = 12)) # ggsave("plot/exp2AnonSpatialN.tiff", plot = last_plot(), # # path = "C:/Users/aeo/Desktop/ordinal data/flavia", # width = 8, height = 5, device='tiff', dpi=300) # spatial ------------------------------- df2 <- read_csv("ordinal_spatial_D24-L24.csv") df2 <- df2%>%gather(exp,percent,-subjectID, -hatch_condition) df2[c('test', 'choice')] <- str_split_fixed(df2$exp, '_', 2) # unique(df2$test) df2$test <- mapvalues(df2$test, from = unique(df2$test), to = c("FP binocular","FP right","FP left",'sagittal')) test_choice2 <- ddply(df2, c("test","hatch_condition","choice"), summarise, Mean = mean(percent), sd = sd(percent), n = sum(!is.na(percent)), se = sd / sqrt (n)) test_choice2$test <- factor(test_choice2$test, levels = c('sagittal',"FP binocular","FP left","FP right")) test_choice2$choice <- factor(test_choice2$choice, levels = c(1:10,"1L","2L","3L","4L","5L", "5R","4R","3R","2R","1R")) ggplot(test_choice2, aes(x=choice, y=Mean, colour = hatch_condition)) + geom_hline(yintercept=10, color='grey', size=0.4,lty=5) + geom_line(aes(group = hatch_condition)) + facet_wrap(~test,scales='free_x',ncol=2)+ geom_point(size = 1) + ylim(0,45) + geom_pointrange(aes(ymin=(Mean-se), ymax=(Mean+se)), width=0.2, position=position_dodge(0)) + labs(title = "With spatial information", x = "Positions", y="First choice - Percentage (%)") + theme(legend.position="right")+ # guides(shape=FALSE)+ theme_classic() + scale_color_manual(values=c("#4b0ffb","#fc7e0f"),name="Hatch Condition")+ theme(text = element_text(size=14, family="Arial"), panel.background = element_rect(fill = "transparent", color = "black"), plot.background = element_rect(fill = "transparent")) + theme(axis.text.x = element_text(size = 10), axis.text.y = element_text(size = 12), strip.text.x = element_text(size = 12), strip.text.y = element_text(size = 12), legend.text = element_text(size = 12)) # ggsave("plot/exp1WithSpatialN.tiff", plot = last_plot(), # # path = "C:/Users/aeo/Desktop/ordinal data/flavia", # width = 8, height = 5, device='tiff', dpi=300) ``` ```{r chance level tests, message=FALSE, warning=FALSE, include=FALSE} # chance level --------- for (hatchC in c('light','dark')) { for (thistest in unique(df1$test)) { for (thisposition in unique(df1$choice[df1$test==thistest])) { tmp <-t.test(df1$percent[df1$test==thistest&df1$choice==thisposition&df1$hatch_condition==hatchC], mu = 10, alternative = c("greater"), conf.level = 0.95) tmp<-wilcox.test(df1$percent[df1$test==thistest&df1$choice==thisposition&df1$hatch_condition==hatchC], mu = 10,alternative ="greater") test_choice$r[test_choice$test==thistest&test_choice$choice==thisposition&test_choice$hatch_condition==hatchC] <- wilcoxonOneSampleR(x=df1$percent[df1$test==thistest&df1$choice==thisposition&df1$hatch_condition==hatchC], mu=10) test_choice$p[test_choice$test==thistest&test_choice$choice==thisposition&test_choice$hatch_condition==hatchC] <- tmp['p.value'] test_choice$p.adj[test_choice$test==thistest&test_choice$choice==thisposition&test_choice$hatch_condition==hatchC] <- p.adjust(tmp['p.value'], method = "bonferroni", n = 10) bf <- ttestBF( x = df1$percent[df1$test==thistest&df1$choice==thisposition&df1$hatch_condition==hatchC]-10, mu = 0,nullInterval = c(0,Inf)) test_choice$bf[test_choice$test==thistest&test_choice$choice==thisposition&test_choice$hatch_condition==hatchC] <- extractBF(bf)$bf[1] # df_1$con_int[i] <- tmp['conf.int'] # df_1$chance[i] <- chance*100 # test_choice$cohenH[test_choice$test==thistest&test_choice$choice==thisposition&test_choice$hatch_condition==hatchC] <- test_choice$ES.h[test_choice$test==thistest&test_choice$choice==thisposition&test_choice$hatch_condition==hatchC] <- ES.h(df1$percent[test_choice$test==thistest&test_choice$choice==thisposition&test_choice$hatch_condition==hatchC]/100,0.10) # df_1$power[i] <- pwr.p.test(h=df_1$cohen_h[i], # n=df_1$N[i], # sig.level=0.05,alternative="greater") } } } test_choice$p.sig <- ifelse (test_choice$p<0.05,'*','ns') test_choice$p.sig[test_choice$p>=0.001&test_choice$p<0.01] <- '**' test_choice$p.sig[test_choice$p<0.001] <- '***' test_choice$p.adj.sig <- ifelse (test_choice$p.adj<0.05,'*','ns') test_choice$p.adj.sig[test_choice$p.adj>=0.001&test_choice$p.adj<0.01] <- '**' test_choice$p.adj.sig[test_choice$p.adj<0.001] <- '***' test_choice$bf_cat[test_choice$bf>1] <- 'Anecdotal' test_choice$bf_cat[test_choice$bf>3] <- 'Moderate' test_choice$bf_cat[test_choice$bf>10] <- 'Strong' test_choice$bf_cat[test_choice$bf>30] <- 'Very Strong' test_choice$bf_cat[test_choice$bf>100] <- 'Extreme' df11 <- apply(test_choice,2,as.character) # write.csv(df11, file='output20240704/summary_nonSpatial.csv') for (hatchC in c('light','dark')) { for (thistest in unique(df2$test)) { for (thisposition in unique(df2$choice[df2$test==thistest])) { tmp <-t.test(df2$percent[df2$test==thistest&df2$choice==thisposition&df2$hatch_condition==hatchC], mu = 10, alternative = c("greater"), conf.level = 0.95) tmp<-wilcox.test(df2$percent[df2$test==thistest&df2$choice==thisposition&df2$hatch_condition==hatchC], mu = 10,alternative ="greater") test_choice2$r[test_choice2$test==thistest&test_choice2$choice==thisposition&test_choice2$hatch_condition==hatchC] <- wilcoxonOneSampleR(x=df2$percent[df2$test==thistest&df2$choice==thisposition&df2$hatch_condition==hatchC], mu=10) test_choice2$p[test_choice2$test==thistest&test_choice2$choice==thisposition&test_choice2$hatch_condition==hatchC] <- tmp['p.value'] test_choice2$p.adj[test_choice2$test==thistest&test_choice2$choice==thisposition&test_choice2$hatch_condition==hatchC] <- p.adjust(tmp['p.value'], method = "bonferroni", n = 10) bf <- ttestBF(x = df2$percent[df2$test==thistest&df2$choice==thisposition&df2$hatch_condition==hatchC]-10, mu = 0,nullInterval = c(0,Inf)) test_choice2$bf[test_choice2$test==thistest&test_choice2$choice==thisposition&test_choice2$hatch_condition==hatchC] <- extractBF(bf)$bf[1] # df_1$con_int[i] <- tmp['conf.int'] # df_1$chance[i] <- chance*100 # test_choice2$cohenH[test_choice2$test==thistest&test_choice2$choice==thisposition&test_choice2$hatch_condition==hatchC] <- test_choice2$ES.h[test_choice2$test==thistest&test_choice2$choice==thisposition&test_choice2$hatch_condition==hatchC] <- ES.h(df2$percent[test_choice2$test==thistest&test_choice2$choice==thisposition&test_choice2$hatch_condition==hatchC]/100,0.10) # df_1$power[i] <- pwr.p.test(h=df_1$cohen_h[i], # n=df_1$N[i], # sig.level=0.05,alternative="greater") } } } test_choice2$p.sig <- ifelse (test_choice2$p<0.05,'*','ns') test_choice2$p.sig[test_choice2$p>=0.001&test_choice2$p<0.01] <- '**' test_choice2$p.sig[test_choice2$p<0.001] <- '***' test_choice2$p.adj.sig <- ifelse (test_choice2$p.adj<0.05,'*','ns') test_choice2$p.adj.sig[test_choice2$p.adj>=0.001&test_choice2$p.adj<0.01] <- '**' test_choice2$p.adj.sig[test_choice2$p.adj<0.001] <- '***' test_choice2$bf_cat[test_choice2$bf>1] <- 'Anecdotal' test_choice2$bf_cat[test_choice2$bf>3] <- 'Moderate' test_choice2$bf_cat[test_choice2$bf>10] <- 'Strong' test_choice2$bf_cat[test_choice2$bf>30] <- 'Very Strong' test_choice2$bf_cat[test_choice2$bf>100] <- 'Extreme' test_choice2 ``` ```{r organize before analysis, message=FALSE, warning=FALSE, include=FALSE} df21 <- apply(test_choice2,2,as.character) # write.csv(df21, file='output20240704/summary_Spatial2.csv') library(afex) df2$spatial <-'spatial' df1$spatial <-'NONspatial' df <- rbind(df1,df2) df.acc <- df%>%filter(choice%in% c('4R','4L','4')) df.acc$hatch_condition <- factor(df.acc$hatch_condition,levels = c('dark','light')) df.acc$choice <- factor(df.acc$choice,levels = c('4R','4L','4')) df.acc$spatial <- factor(df.acc$spatial,levels = c('NONspatial','spatial')) df.accNON <- df.acc %>% subset(spatial=='NONspatial') df.accSpatial <- df.acc %>% subset(spatial=='spatial') df.acc$sideCode[df.acc$choice=='4L'] <- 1 df.acc$sideCode[df.acc$choice=='4R'] <- 0 df.acc$exp[df.acc$exp=="sagittal_4"] <- "sag_4" sum1 <- ddply(df.acc, c("spatial","test","choice"), summarise, Mean = mean(percent), sd = sd(percent), n = sum(!is.na(percent)), se = sd / sqrt (n)) # sum12 <- apply(sum1,2,as.character) ``` # Analysis ## Experiment 1 With spatial cues ### 1 Sagittal ```{r exp1 sag, echo=FALSE, message=FALSE, warning=FALSE} lm1 <- lm(percent ~ hatch_condition, data = df.accSpatial%>%subset(test=='sagittal')) summary(lm1) # Anova(lm1,type='III') lmBF(percent ~ hatch_condition, data = df.accSpatial%>%subset(test=='sagittal')) ``` ### 1 FP binocular ```{r exp1 FP bin, echo=FALSE, message=FALSE, warning=FALSE} lm2 <- lm(percent ~ hatch_condition + choice, data = df.accSpatial%>%subset(test=='FP binocular')) summary(lm2) lm2 <- lm(percent ~ hatch_condition * choice, data = df.accSpatial%>%subset(test=='FP binocular')) # lm2 <- lmer(percent ~ hatch_condition * choice +(1|subjectID), data = df.accSpatial%>%subset(test=='FP binocular')) summary(lm2) # Anova(lm2,type='III') lm2.emm <- emmeans(lm2, ~ choice*hatch_condition) pairs(lm2.emm, simple = "hatch_condition",adjust="bonferroni",paired=F) pairs(lm2.emm, simple = "choice",adjust="bonferroni",paired=TRUE) anovaBF(percent ~ hatch_condition * choice+ hatch_condition + choice, data = df.accSpatial%>%subset(test=='FP binocular')) lmBF(percent ~ hatch_condition * choice+ hatch_condition + choice, data = df.accSpatial%>%subset(test=='FP binocular'))/lmBF(percent ~ hatch_condition + choice, data = df.accSpatial%>%subset(test=='FP binocular')) ``` ### 1 FP left ```{r exp1 FP left, echo=FALSE, message=FALSE, warning=FALSE} lm3 <- lm(percent ~ hatch_condition+ choice, data = df.accSpatial%>%subset(test=='FP left')) summary(lm3) lm3 <- lm(percent ~ hatch_condition* choice, data = df.accSpatial%>%subset(test=='FP left')) summary(lm3) # Anova(lm3,type='III') lm3.emm <- emmeans(lm3, ~ choice*hatch_condition) pairs(lm3.emm, simple = "hatch_condition",adjust="bonferroni",paired=F) pairs(lm3.emm, simple = "choice",adjust="bonferroni",paired=TRUE) anovaBF(percent ~ hatch_condition * choice+ hatch_condition + choice, data = df.accSpatial%>%subset(test=='FP left')) lmBF(percent ~ hatch_condition * choice+ hatch_condition + choice, data = df.accSpatial%>%subset(test=='FP left'))/lmBF(percent ~ hatch_condition + choice, data = df.accSpatial%>%subset(test=='FP left')) ``` ### 1 FP right ```{r exp1 FP right, echo=FALSE, message=FALSE, warning=FALSE} lm4 <- lm(percent ~ hatch_condition + choice, data = df.accSpatial%>%subset(test=='FP right')) summary(lm4) lm4 <- lm(percent ~ hatch_condition * choice, data = df.accSpatial%>%subset(test=='FP right')) summary(lm4) # Anova(lm4,type='III') lm4.emm <- emmeans(lm4, ~ choice*hatch_condition) pairs(lm4.emm, simple = "hatch_condition",adjust="bonferroni",paired=F) pairs(lm4.emm, simple = "choice",adjust="bonferroni",paired=TRUE) anovaBF(percent ~ hatch_condition * choice+ hatch_condition + choice, data = df.accSpatial%>%subset(test=='FP right')) lmBF(percent ~ hatch_condition * choice+ hatch_condition + choice, data = df.accSpatial%>%subset(test=='FP right'))/lmBF(percent ~ hatch_condition + choice, data = df.accSpatial%>%subset(test=='FP right')) ``` ## Experiment 2 (without spatial cues) ### 2 sagittal ```{r exp2 sag, echo=FALSE, message=FALSE, warning=FALSE} lm1 <- lm(percent ~ hatch_condition, data = df.accNON%>%subset(test=='sagittal')) summary(lm1) # Anova(lm1,type='III') lm1 <- lmBF(percent ~ hatch_condition, data = df.accNON%>%subset(test=='sagittal')) summary(lm1) ``` ### 2 FP binocular ```{r exp2 FP bin, echo=FALSE, message=FALSE, warning=FALSE} lm2 <- lm(percent ~ hatch_condition + choice, data = df.accNON%>%subset(test=='FP binocular')) # lm2 <- lmer(percent ~ hatch_condition * choice +(1|subjectID), data = df.accNON%>%subset(test=='FP binocular')) summary(lm2) lm2 <- lm(percent ~ hatch_condition * choice, data = df.accNON%>%subset(test=='FP binocular')) # lm2 <- lmer(percent ~ hatch_condition * choice +(1|subjectID), data = df.accNON%>%subset(test=='FP binocular')) summary(lm2) lm2.emm <- emmeans(lm2, ~ choice*hatch_condition) pairs(lm2.emm, simple = "hatch_condition",adjust="bonferroni",paired=F) pairs(lm2.emm, simple = "choice",adjust="bonferroni",paired=TRUE) anovaBF(percent ~ hatch_condition * choice+ hatch_condition + choice, data = df.accNON%>%subset(test=='FP binocular')) lmBF(percent ~ hatch_condition * choice+ hatch_condition + choice, data = df.accNON%>%subset(test=='FP binocular'))/lmBF(percent ~ hatch_condition + choice, data = df.accNON%>%subset(test=='FP binocular')) # lm2 <- lmer(percent ~ hatch_condition * choice +(1|subjectID), data = df.accNON%>%subset(test=='FP binocular')) # Anova(lm2,type='III') ``` ### 2 FP left ```{r exp2 FP left, echo=FALSE, message=FALSE, warning=FALSE} lm3 <- lm(percent ~ hatch_condition+ choice, data = df.accNON%>%subset(test=='FP left')) summary(lm3) lm3 <- lm(percent ~ hatch_condition* choice, data = df.accNON%>%subset(test=='FP left')) summary(lm3) lm3.emm <- emmeans(lm3, ~ choice*hatch_condition) pairs(lm3.emm, simple = "hatch_condition",adjust="bonferroni",paired=F) pairs(lm3.emm, simple = "choice",adjust="bonferroni",paired=TRUE) anovaBF(percent ~ hatch_condition * choice+ hatch_condition + choice, data = df.accNON%>%subset(test=='FP left')) lmBF(percent ~ hatch_condition * choice+ hatch_condition + choice, data = df.accNON%>%subset(test=='FP left'))/lmBF(percent ~ hatch_condition + choice, data = df.accNON%>%subset(test=='FP left')) # Anova(lm3,type='III') ``` ### 2 FP right ```{r exp2 FP right, echo=FALSE, message=FALSE, warning=FALSE} lm4 <- lm(percent ~ hatch_condition + choice, data = df.accNON%>%subset(test=='FP right')) summary(lm4) # Anova(lm4,type='III') lm4 <- lm(percent ~ hatch_condition * choice, data = df.accNON%>%subset(test=='FP right')) summary(lm4) lm4.emm <- emmeans(lm4, ~ choice*hatch_condition) pairs(lm4.emm, simple = "hatch_condition",adjust="bonferroni",paired=F) pairs(lm4.emm, simple = "choice",adjust="bonferroni",paired=TRUE) anovaBF(percent ~ hatch_condition * choice+ hatch_condition + choice, data = df.accNON%>%subset(test=='FP right')) lmBF(percent ~ hatch_condition * choice+ hatch_condition + choice, data = df.accNON%>%subset(test=='FP right'))/lmBF(percent ~ hatch_condition + choice, data = df.accNON%>%subset(test=='FP right')) ``` ```{r 12 plot, eval=FALSE, message=FALSE, warning=FALSE, include=FALSE} # compare exp1 with exp2 --------------- exp1exp2 <- ddply(df.acc, c("test","hatch_condition","spatial",'choice'), summarise, Mean = mean(percent), sd = sd(percent), n = sum(!is.na(percent)), se = sd / sqrt (n)) exp1exp2$test <- factor(exp1exp2$test, levels = c('sagittal',"FP binocular","FP left","FP right")) exp1exp2$choice <- factor(exp1exp2$choice, levels = c(4,"4L","4R")) exp1exp2$condition <- paste(exp1exp2$hatch_condition,exp1exp2$spatial,sep = '.') ggplot(exp1exp2, aes(x=choice, fill=condition, y=Mean)) + facet_wrap(~test,scales='free_x',ncol=2)+ geom_hline(yintercept=10, color='grey', size=0.4) + geom_bar(stat="identity", color="black", position=position_dodge(),width=0.5) + geom_errorbar(aes(ymin=Mean, ymax=(Mean+se)), width=0.2, position=position_dodge(.5)) + theme(legend.position="right")+ # scale_fill_grey(start = 0, end = 1, name = "Condition") + ylim(0,50)+ scale_fill_manual(values=c("#d44000","#ffc93c", "#0061a8", "#8ab6d6"),name="condition")+ labs(title = "", x = "Positions", y="First choice - Percentage (%)") + theme_classic() + theme(text = element_text(size=14, family="Times"), panel.background = element_rect(fill = "transparent", color = "black"), plot.background = element_rect(fill = "transparent")) + theme(axis.text.x = element_text(size = 8), axis.text.y = element_text(size = 10), strip.text.x = element_text(size = 10), legend.text = element_text(size = 10)) # ggsave("plot/exp1exp2.tiff", plot = last_plot(), # # path = "C:/Users/aeo/Desktop/ordinal data/flavia", # width = 8, height = 6, device='tiff', dpi=300) ### compare 12 sagittal lm1 <- lm(percent ~ hatch_condition + spatial, data = df.acc%>%subset(test=='sagittal')) summary(lm1) lm1 <- lm(percent ~ hatch_condition * spatial, data = df.acc%>%subset(test=='sagittal')) summary(lm1) # Anova(lm1,type='III') ### compare 12 FP bin lm2 <- lm(percent ~ hatch_condition + choice+ spatial, data = df.acc%>%subset(test=='FP binocular')) summary(lm2) lm2 <- lm(percent ~ hatch_condition * choice* spatial, data = df.acc%>%subset(test=='FP binocular')) summary(lm2) # Anova(lm2,type='III') lm2.emm <- emmeans(lm2, ~ choice*hatch_condition* spatial) pairs(lm2.emm, simple = "each",adjust="bonferroni",paired=F) pairs(lm2.emm, simple = "hatch_condition",adjust="bonferroni",paired=F) pairs(lm2.emm, simple = "choice",adjust="bonferroni",paired=TRUE) ### compare 12 FP left lm3 <- lm(percent ~ hatch_condition+ choice, data = df.accSpatial%>%subset(test=='FP left')) summary(lm3) lm3 <- lm(percent ~ hatch_condition* choice, data = df.accSpatial%>%subset(test=='FP left')) summary(lm3) # Anova(lm3,type='III') lm3.emm <- emmeans(lm3, ~ choice*hatch_condition) pairs(lm3.emm, simple = "hatch_condition",adjust="bonferroni",paired=F) pairs(lm3.emm, simple = "choice",adjust="bonferroni",paired=TRUE) ### compare 12 FP right lm4 <- lm(percent ~ hatch_condition + choice, data = df.accSpatial%>%subset(test=='FP right')) summary(lm4) lm4 <- lm(percent ~ hatch_condition * choice, data = df.accSpatial%>%subset(test=='FP right')) summary(lm4) # Anova(lm4,type='III') lm4.emm <- emmeans(lm4, ~ choice*hatch_condition) pairs(lm4.emm, simple = "hatch_condition",adjust="bonferroni",paired=F) pairs(lm4.emm, simple = "choice",adjust="bonferroni",paired=TRUE) ``` ## t tests ### 4L vs. 4R 4L - 4R ```{r 4L vs. 4R, echo=FALSE, message=FALSE, warning=FALSE} t_side <- data.frame() for (i in unique(df.acc$spatial)) { for (j in unique(df.acc$hatch_condition)) { for (k in c( "FP binocular", "FP left", "FP right")) { df.tmp <- df.acc %>% subset(spatial==i&hatch_condition==j&test==k) runTest <- t.test(df.tmp$percent[df.tmp$choice=='4L'],df.tmp$percent[df.tmp$choice=='4R'],paired = T) runbf <- ttestBF(df.tmp$percent[df.tmp$choice=='4L'],df.tmp$percent[df.tmp$choice=='4R'],paired = T) t_side <- rbind(t_side, c(i,j,k,extractBF(runbf)['bf'][[1]], unlist(runTest[c(1,3,4,5)]))) }}} names(t_side) <- c('spatialCue','lateralization','test','bf','t','p','CI_lower','CI_upper','mean_difference') t_side[c(4:9)] <- as.numeric(unlist(t_side[c(4:9)] )) kable(t_side, digits = 3) ``` ### strong vs. weak lateralized strong - weak ```{r strong vs. weak lateralized, echo=FALSE, message=FALSE, warning=FALSE} t_lateralization <- data.frame() df.acc$hatch_condition <- factor(df.acc$hatch_condition, levels = c('light','dark')) for (i in unique(df.acc$spatial)) { for (j in unique(df.acc$exp)) { df.tmp <- df.acc %>% subset(spatial==i&exp==j) runTest <- t.test(percent ~ hatch_condition, df.tmp) # runTest <- t.test(df.tmp$percent[df.tmp$hatch_condition=='light'],df.tmp$percent[df.tmp$hatch_condition=='dark'],paired = F) runbf <- ttestBF(df.tmp$percent[df.tmp$hatch_condition=='light'],df.tmp$percent[df.tmp$hatch_condition=='dark'],paired = F) t_lateralization <- rbind(t_lateralization, c(i,j,extractBF(runbf)['bf'][[1]], unlist(runTest[c(1,3,4,5)]))) }} names(t_lateralization) <- c('spatialCue','test_choice','bf','t','p','CI_lower','CI_upper','mean_strong','mean_weak') t_lateralization[c(3:9)] <- as.numeric(unlist(t_lateralization[c(3:9)] )) kable(t_lateralization, digits = 3) ``` ### spatial vs. non spatial spatial - non spatial ```{r spatial vs. non spatial, echo=FALSE, message=FALSE, warning=FALSE} t_space <- data.frame() df.acc$spatial <- factor(df.acc$spatial, levels = c('spatial','NONspatial')) for (i in unique(df.acc$hatch_condition)) { for (j in unique(df.acc$exp)) { df.tmp <- df.acc %>% subset(hatch_condition==i&exp==j) runTest <- t.test(percent ~ spatial, df.tmp) # runTest <- t.test(df.tmp$percent[df.tmp$hatch_condition=='light'],df.tmp$percent[df.tmp$hatch_condition=='dark'],paired = F) runbf <- ttestBF(df.tmp$percent[df.tmp$spatial=='spatial'],df.tmp$percent[df.tmp$spatial=='NONspatial'],paired = F) t_space <- rbind(t_space, c(i,j,extractBF(runbf)['bf'][[1]], unlist(runTest[c(1,3,4,5)]))) }} names(t_space) <- c('lateralization','test_choice','bf','t','p','CI_lower','CI_upper','mean_spatial','mean_nonspatial') t_space[c(3:9)] <- as.numeric(unlist(t_space[c(3:9)] )) kable(t_space, digits = 3) ``` ### chance exp1 ```{r print chance level tests1, echo=FALSE, message=FALSE, warning=FALSE} test_choice2 ``` ### chance exp2 ```{r print chance level tests2, echo=FALSE, message=FALSE, warning=FALSE} test_choice ```