# Supplementary Material for: # "Constitutive gene expression differs in three brain regions important # for cognition in neophobic and non-neophobic house sparrows (Passer # domesticus)" # Christine R. Lattin, Tosha R. Kelly, Morgan W. Kelly, Kevin M. Johnson # Cox Proportional Hazard Models & Kaplan-Meier Survival Curves # using coxme and survminer packages # Started: 13 April 2020 # Finalized: 15 Sept 2021 # THIS SCRIPT IS TO INVESTIGATE EFFECT OF OBJECTS VS CONTROLS ## all subjects included, object and control trials # Notes on data: ## Controls (where included) are not averaged ## 4 different object trials per bird ## Female HOSPs 106, 108 and 112 are assigned phenotype 3 (neophobic) & ## Female HOSPs 99, 100 & 110 are assigned phenotype 1 (non-neophobic) ## These were the 6 birds used for RNAseq analysis. ## Neophobic also includes female 103 and males 101, 104, and 111 ## Non-neophobic also includes females 102 and 105 and males 98, 107, and 109 ## Missing Trial 1 (control) from HOSP 99, Trial 2 (object) from HOSP 112 ## and Trials 7 and 8 (1 control, 1 object) from HOSP 102 (video malfunctions) ## Objects: 0=Control, 1=Keychain, 2=Red dish, 3=Light, 4=Egg, 5=Cover ## Phenotype: 1=not neophobic, 3=neophobic ## Status = 0=Did not feed, 1=Fed ## Object_noobject = 0=control, 1=object # resources for packages: ## coxme command is from the 'coxme' package - can handle random effects: https://cran.r-project.org/web/packages/coxme/coxme.pdf ### interpretation of cox regression model coefficients: ### http://www.sthda.com/english/wiki/cox-proportional-hazards-model (~ 1/2 way down the page) #packages install.packages(c("survival","survminer")) library("survival") library("survminer") library("coxme") #Reset R's brain rm(list=ls()) #getwd tells you where R is currently looking getwd() #setwd tells R where to look setwd("/Neophobia projects/RNAseq project/R analysis") #use getwd to confirm that R is now looking there getwd() #name the datafile birds<-read.csv("2018_object_times_for_R.csv") head(birds) str(birds) #make appropriate data types (must all be numeric for survival plots) birds$ID<-factor(birds$ID) birds$OBJECT<-factor(birds$OBJECT) birds$PHENOTYPE<-factor(birds$PHENOTYPE) birds$TIME<-as.numeric(birds$TIME) birds$STATUS<-as.numeric(birds$STATUS) birds$TRIAL<-as.numeric(birds$TRIAL) birds$OBJECT_NOOBJECT<-factor(birds$OBJECT_NOOBJECT) birds$SEX<-factor(birds$SEX) str(birds) ################## # CHECKING ASSUMPTIONS # ################## #From: http://www.sthda.com/english/wiki/cox-model-assumptions #Check Schoenfeld residuals to check the proportional hazards assumption #of Cox models #Do not have continuous covariates, so no need to check Martingale residuals #to assess nonlinearity #Can also check deviance residuals (symmetric transformation of the Martinguale #residuals), to examine influential observations #These tests can only be used for fixed effects, not random effects #Make a Cox model with fixed effects only (also do this for OBJECT_NOOBJECT) res.cox<-coxph(Surv(TIME,STATUS)~OBJECT,data=birds) res.cox #Test the proportional hazards assumption #using the function cox.zph() in the survival package test.ph<-cox.zph(res.cox) test.ph #Can also check graphs of the scaled Schoenfeld residuals against the #transformed time using ggcoxzph() in the survminer package ggcoxzph(test.ph) #To check for influential observations, can visualize the dfbeta values #or the deviance residuals #Using the function ggcoxdiagnostics() in the survminer package: ggcoxdiagnostics(res.cox,type="deviance", linear.predictions=FALSE, ggtheme=theme_bw()) ################## # OBJECT EFFECTS # ################## ##Checking for a global object vs. no-object effect controlling for individual #random effects using the coxme package: cox.sparrow.global<-coxme(Surv(TIME,STATUS)~OBJECT_NOOBJECT+(1|ID),data=birds) cox.sparrow.global ##Contrasting different object effects with controls while controlling for #individual random effects using coxme package: cox.sparrow.contrasts<-coxme(Surv(TIME,STATUS)~OBJECT+(1|ID),data=birds) cox.sparrow.contrasts # object plot fit.object<-survfit(Surv(TIME,STATUS)~OBJECT,data=birds) ggsurvplot(fit.object, data=birds, size=1, #change line size #palette = c("#E7B800","#2E9FDF","#9F18C4"), #custom colours via https://www.google.com/search?q=color+picker #conf.int = TRUE, #add confidence interval #conf.int.style = "ribbon", #"ribbon or "step" #conf.int.alpha = 0.3, #0 = transparent & 1 = not transparent pval=FALSE, #add p-value pval.coord=c(2700,0.9), #change position of p-value risk.table = TRUE, #add risk table risk.table.col = "strata", #risk table colour by groups legend.labs = c("Control","Keychain","Red dish","Light","Egg","Cover"), #change legend labels xlab = "Time (seconds)", #change x-axis label ylab = "Proportion yet to feed", #change y-axis label break.time.by = 300, risk.table.height = 0.4, #useful to change when you have multiple groups risk.table.title = "Number yet to feed", ggtheme = theme_bw() #change ggplot theme )