rm(list=ls()) # clears memory # setwd("[Insert File Path Here]") # set working directory dat<-read.csv("2b_BehavData_GoatCrossModalRecognHumans.csv",header=T,stringsAsFactors = F) # load data file head(dat, 10)# view the first 10 observations ## To install and load relevant packages # install.packages("glmmTMB", dep=T) library(glmmTMB) ## Setting factors and checking their levels dat$goat.id <- as.factor(dat$goat.id) levels(dat$goat.id) dat$goat.sex <- as.factor(dat$goat.sex) levels(dat$goat.sex) dat$trial <- ordered(dat$trial) levels(dat$trial) dat$year <- as.factor(dat$year) levels(dat$year) dat$congruency <- as.factor(dat$congruency) levels(dat$congruency) dat$human.gender <- as.factor(dat$human.gender) levels(dat$human.gender) dat$photo <- as.factor(dat$photo) levels(dat$photo) dat$responsi.photo <- as.factor(dat$responsi.photo) levels(dat$responsi.photo) dat$voice <- as.factor(dat$voice) levels(dat$voice) dat$responsi.voice <- as.factor(dat$responsi.voice) levels(dat$responsi.voice) dat$pb.no <- as.factor(dat$pb.no) levels(dat$pb.no) str(dat) # to check factors have been coded appropriately ############################################################################################# ### GENERAL EXCLUSIONS ## Excluding instances where goats are already looking before onset of playbacks dat2 <- subset(dat, lat!=0) ## Excluding goats which did not look for at least one congruent and one incongruent ## trial dat3 <- subset(dat2, goat.id!= "Glenda") ############################################################################################# ### LATENCY ANALYSIS ## Excluding instances where goats did not respond following playbacks dat4 <-subset(dat3, lat!=10) ## Excluding goats which did not look for at least one congruent and one incongruent ## trial dat5<-subset(dat4, goat.id!="Davey" & goat.id!="Natalie") ## Full model lat.m1<-glmmTMB(lat ~ congruency + pb.no + year + goat.sex + human.gender + responsi.photo + responsi.voice + (1|goat.id/trial) + (1|voice), data=dat5, family=lognormal(link="log")) summary(lat.m1) ## Basic model basic_lat.m1<-glmmTMB(lat ~ congruency + pb.no + (1|goat.id/trial), data=dat5, family=lognormal(link="log")) summary(basic_lat.m1) ############################################################################################# ### DURATION ANALYSIS ## Full model dur.m1 <- glmmTMB(dur ~ congruency + pb.no + year + goat.sex + human.gender + responsi.photo + responsi.voice + (1|goat.id/trial) + (1|voice), data=dat3, family=tweedie) summary(dur.m1) ## Basic model basic_dur.m1 <- glmmTMB(dur ~ congruency + pb.no + (1|goat.id/trial), data=dat3, family=tweedie) summary(basic_dur.m1) #############################################################################################