library(plyr) library(ggplot2) library(sciplot) library(reshape2) library(ordinal) LU<-function(x){length(unique(x))} # Import data: NIdata <- read.csv("https://semanticsarchive.net/Archive/2NiMmI4N/McHughCremers-NegationInquisitivenessData.csv") ####################### # Filter participants ####################### NIdata$Correct <- NA NIdata$Correct[NIdata$Value=="true"] <- ifelse(NIdata$Answer[NIdata$Value=="true"]>4,1,0) NIdata$Correct[NIdata$Value=="false"] <- ifelse(NIdata$Answer[NIdata$Value=="false"]<4,1,0) SubjectErrorRates <- aggregate(Correct~Participant,FUN=mean,data=NIdata) table(SubjectErrorRates$Correct) aggregate(Correct~Value,FUN=mean,na.rm=T,data=NIdata) # Participants at chance on the false filler. Possibly ambiguity of the antecedent. Only use the true filler to filter participants. excluded <- unique(NIdata$Participant[NIdata$Answer<=4&NIdata$Value=="true"]) length(excluded) NIdata <- subset(NIdata,!Participant%in%excluded) ################## # Barplot (Fig 4) ################## NIdata$Sentence<-factor(NIdata$Value,levels=c('false','target','control','true','target2'),labels=c('False','T1/T2', 'Control','True','T3')) NIdata$Sentence <- as.character(NIdata$Sentence) NIdata$Sentence[NIdata$Sentence=='T1/T2'&NIdata$TargetType=="T1"] <- "T1" NIdata$Sentence[NIdata$Sentence=='T1/T2'&NIdata$TargetType=="T2"] <- "T2" NIdata$Sentence <- factor(NIdata$Sentence,levels=c('False','T1','T2','T3', 'Control','True')) plot.data<-ddply(subset(NIdata,!Participant%in%excluded),c("Sentence"),function(df)c(response=mean(df$Answer,na.rm=T)-4,se=se(df$Answer))) quartz(height=5,width=10) fill=rgb(.2,0,1,.7) Colors<-c(rgb(1,.3,.3),rgb(1,.5,.2),rgb(1,.5,.2),rgb(1,.5,.2),rgb(.3,.5,1),rgb(.4,.9,.55)) p<-ggplot(data= plot.data,aes(x=Sentence,y=response,fill=Sentence)) + geom_bar(position=position_dodge(), stat="identity") + theme( strip.background=element_rect(fill='white',colour='black'), strip.text.x = element_text(size = 14, colour = "black", angle = 0), strip.text.y = element_text(size = 12, colour = "black", angle = 270), axis.title.y = element_text(size=16), axis.text.y=element_text(size = 14), axis.text.x=element_text(size = 14), axis.ticks.x=element_blank(), axis.ticks.y=element_line(colour='gray'), legend.title=element_text(size=16), legend.text=element_text(size=12), panel.background=element_rect(fill='white'), panel.grid.minor=element_blank(), panel.grid.major.y=element_line(colour='gray',linetype='dashed'), panel.grid.major.x=element_line(colour=rgb(.8,.8,.8,.3)) ) + geom_errorbar(aes(ymin=response-se, ymax=response+se), width=.2, position=position_dodge(.9))+ #geom_hline(yintercept=0,color='gray')+ xlab("") + ylab("Mean acceptability (SE)") + scale_fill_manual(values=Colors) + scale_y_continuous(breaks=(1:7)-4, labels=(1:7),limits=c(2.8,7.2)-4) print(p) ##################### # Boxplot for details ##################### boxplot.data<-ddply(subset(NIdata,!Participant%in%excluded),c("TargetType","Value","Participant"),function(df)c(response=mean(df$Answer,na.rm=T)-4)) boxplot.data$TargetType <- factor(boxplot.data$TargetType,levels=c("T1","T2"),labels=c("Not neither up (T1)","Disjunction (T2)")) boxplot.data$Sentence<-factor(boxplot.data$Value,levels=c('false','target','control','true','target2'),labels=c('False','T1/T2', 'Control','True','T3')) quartz(height=5,width=10) fill=rgb(.2,0,1,.7) Colors<-c(rgb(1,.3,.3),rgb(.3,.5,1),rgb(.6,.8,1),rgb(.4,.9,.55), rgb(.3,.3,.3)) p<-ggplot(data= boxplot.data,aes(x=Sentence,y=response,color=Sentence)) + facet_grid(.~TargetType,scales="free") + geom_boxplot(outlier.shape = NA,position=position_dodge(width=.8)) + geom_point(size=1.65,position=position_jitterdodge(jitter.height=.15,jitter.width=.3,dodge.width=.8),alpha=.65,stroke=0) + theme( strip.background=element_rect(fill='white',colour='black'), strip.text.x = element_text(size = 14, colour = "black", angle = 0), strip.text.y = element_text(size = 12, colour = "black", angle = 270), axis.title.y = element_text(size=16), axis.text.y=element_text(size = 14), axis.text.x=element_text(size = 14), axis.ticks.x=element_blank(), axis.ticks.y=element_line(colour='gray'), legend.title=element_text(size=16), legend.text=element_text(size=12), panel.background=element_rect(fill='white'), panel.grid.minor=element_blank(), panel.grid.major.y=element_line(colour='gray',linetype='dashed'), panel.grid.major.x=element_line(colour=rgb(.8,.8,.8,.3)) ) + xlab("") + ylab("Acceptability") + scale_fill_manual(values=Colors) + scale_color_manual(values=Colors) + scale_y_continuous(breaks=(1:7)-4, labels=(1:7),limits=c(0.8,7.2)-4) print(p) ######################## # Barplot with position # to see order effects ######################## plot.data3 <-ddply(subset(NIdata,!Participant%in%excluded),c("Sentence","Position"),function(df)c(response=mean(df$Answer,na.rm=T)-4,se=se(df$Answer))) quartz(height=5,width=10) fill=rgb(.2,0,1,.7) Colors<-c(rgb(1,.3,.3),rgb(1,.5,.2),rgb(1,.5,.2),rgb(1,.5,.2),rgb(.3,.5,1),rgb(.4,.9,.55)) plot.data3 <- subset(plot.data3,!is.na(plot.data3$Position)) p<-ggplot(data= plot.data3,aes(x=Sentence,y=response,fill=Sentence,group=Position)) + geom_bar(position=position_dodge(), stat="identity") + #facet_grid(. ~TargetType,scales="free") + theme( strip.background=element_rect(fill='white',colour='black'), strip.text.x = element_text(size = 14, colour = "black", angle = 0), strip.text.y = element_text(size = 12, colour = "black", angle = 270), axis.title.y = element_text(size=16), axis.text.y=element_text(size = 14), axis.text.x=element_text(size = 14), axis.ticks.x=element_blank(), axis.ticks.y=element_line(colour='gray'), legend.title=element_text(size=16), legend.text=element_text(size=12), panel.background=element_rect(fill='white'), panel.grid.minor=element_blank(), panel.grid.major.y=element_line(colour='gray',linetype='dashed'), panel.grid.major.x=element_line(colour=rgb(.8,.8,.8,.3)) ) + geom_errorbar(aes(ymin=response-se, ymax=response+se), width=.2, position=position_dodge(.9))+ #geom_hline(yintercept=0,color='gray')+ xlab("") + ylab("Acceptability") + scale_fill_manual(values=Colors) + scale_y_continuous(breaks=(1:7)-4, labels=(1:7),limits=c(0.8,7.2)-4) print(p) ######## # Stats ######## stat.data <- subset(NIdata,Value%in%c('target','target2','control')) stat.data$Sentence <- as.character(stat.data$Value) stat.data$Sentence[stat.data$Sentence=="target2"] <- "T3" stat.data$Sentence[stat.data$Sentence=="target"&stat.data$TargetType=="T1"] <- "T1" stat.data$Sentence[stat.data$Sentence=="target"&stat.data$TargetType=="T2"] <- "T2" stat.data$Sentence <- factor(stat.data$Sentence, levels=c('control', 'T1','T2','T3')) stat.data$Answer <- factor(stat.data$Answer) mainModel <- clmm(Answer~Sentence+(1|Participant),data=stat.data) summary(mainModel) postHocT13 <- clmm(Answer~Sentence+(1|Participant),data=subset(stat.data,Sentence%in%c("T1","T3")&TargetType=="T1")) summary(postHocT13)