## This script analyzes the normalized responses of H.chrysoscelis subjects to conspecific calls of varying call duration. # By running this script, you will be able to make figures used in Figure5 and perform statistical analysis associated with this figure. # Read packages library("dplyr") library("ggplot2") library("lme4") library("lmerTest") library("binom") ## Read data data_CallDur <- read.csv("Figure5_CallDurationPreference.csv",header = T, check.names=F) # full data ## Plot and Statistical Analysis # Plot and psychometric curve in Fig. 5 data_CallDur_grp <- data_CallDur %>% group_by(Call_duration) summary_CallDur <- data_CallDur_grp %>% summarize(Mean =mean(Normalized_responses), N = n(), CI = 1.96*(sd(Normalized_responses)/sqrt(N))) CD <- summary_CallDur$Call_duration Mean <- summary_CallDur$Mean df <- data.frame(CD,Mean) p2 <- nls(Mean ~ SSlogis(CD, Asym, xmid, scal), data = df) pframe2 <- data.frame(CD=10^seq(log10(5),log10(40), length.out=100)) pp <- data.frame(pframe2, Mean = predict(p2,pframe2), wts =FALSE) ggplot(summary_CallDur, aes(x =CD, y =Mean)) + geom_point(aes(y =Mean),size = 4, shape = 16) + geom_errorbar(width=.5, aes(ymin=Mean-CI, ymax=Mean+CI)) + theme_classic() + ylab("Normalized responses (%)") + scale_x_continuous("Pulse number (Pulses/call)",breaks = c(5,10,15,20,25,30,35,40), labels = paste0(c(5,10,15,20,25,30,35,40))) + geom_line(data =pp, aes(linetype=wts), size=1) + scale_y_continuous(breaks=seq(0,150,25)) + theme(axis.title.x=element_text(size=16), axis.title.y=element_text(size=16), axis.text.x=element_text(size=14),axis.text.y=element_text(size=14),legend.title=element_blank(),legend.position="none",panel.spacing.x=unit(1, "lines")) # Statistical analysis for Fig. 5 data_CallDur$Call_duration <- factor(data_CallDur$Call_duration, levels = c(30,5,10,20,40)) lmer.1 <- lmer(Normalized_responses ~ 1 + Call_duration + (1|Frog_id), data_CallDur, REML = FALSE) lmer.2 <- lmer(Normalized_responses ~ 1 + (1|Frog_id), data_CallDur, REML = FALSE) anova(lmer.1,lmer.2) summary(lmer.1)