#Examples of models used in Klein et al. Sleep Maps study. Not every subset or model was used in our analyses. subset(bees,bees$d_n=="d")->dbees #d = day; n = night subset(bees,bees$d_n=="n")->nbees subset(bees,bees$Year=="first")->first #first year, entire dataset subset(bees,bees$Year=="second")->second #second year, entire dataset subset(bees,bees$Caste=="f")->foragers #only have forager data for first year subset(bees,bees$Caste=="n")->nurses subset(bees,bees$Caste=="fs")->storers subset(bees,bees$Caste=="c")->cleaners subset(cleaners,cleaners$Year=="first")->firstyearcleaners subset(cleaners,cleaners$Year=="second")->secondyearcleaners subset(bees,bees$Beh=="awake")->awakebees #both years, awake bees (important for 2006, when T is the response variable & want to analyze across castes; only have data for awake condition; sleep data insufficient for non-foragers subset(bees,bees$Beh=="asleep")->asleepbees subset(awakebees,awakebees$Caste=="f")->awakeforagers subset(awakebees,awakebees$Caste=="n")->awakenurses subset(awakebees,awakebees$Caste=="fs")->awakestorers subset(awakebees,awakebees$Caste=="c")->awakecleaners subset(asleepbees,asleepbees$Caste=="f")->asleepforagers subset(asleepbees,asleepbees$Caste=="n")->asleepnurses subset(asleepbees,asleepbees$Caste=="fs")->asleepstorers subset(asleepbees,asleepbees$Caste=="c")->asleepcleaners subset(awakebees,awakebees$Year=="first")->firstyearawakebees #first year, analysis T of awake bees across castes subset(awakebees,awakebees$Year=="second")->secondyearawakebees subset(firstyearawakebees,firstyearawakebees$Caste=="c")->firstyearawakecleaners subset(secondyearawakebees,secondyearawakebees$Caste=="c")->secondyearawakecleaners subset(bees,bees$Behav=="0")->zerobees subset(zerobees,zerobees$Caste=="f")->zeroforagers subset(zerobees,zerobees$Caste=="n")->zeronurses subset(zerobees,zerobees$Caste=="fs")->zerostorers subset(zerobees,zerobees$Caste=="c")->zerocleaners subset(zerobees,zerobees$Year=="first")->firstyearzerobees subset(zerobees,zerobees$Year=="second")->secondyearzerobees subset(firstyearzerobees,firstyearzerobees$Caste=="c")->firstyearzerocleaners subset(secondyearzerobees,secondyearzerobees$Caste=="c")->secondyearzerocleaners subset(bees,bees$Behav=="dv")->dvbees subset(dvbees,dvbees$Year=="first")->firstyeardvbees subset(dvbees,dvbees$Year=="second")->secondyeardvbees subset(bees,bees$Behav=="awake")->Behavawakebees subset(Behasleepcleaners,Behasleepcleaners$Year=="first")->firstyearBehasleepcleaners subset(Behasleepcleaners,Behasleepcleaners$Year=="second")->secondyearBehasleepcleaners rbind(zerobees,Behavawakebees)->zeroawake #comparing 0 vs. awake, both years rbind(firstyearzerobees,firstyearBehavawakebees)->firstyearzeroawake rbind(firstyearzeroforagers,firstyearBehavawakeforagers)->firstyearzeroawakeforagers #compare foragers 0 vs. awake subset(firstyearzeroawakeforagers ,firstyearzeroawakeforagers$Newforager=="no")->firstyearzeroawakeforagers_nonewforagers #compare foragers 0 vs. awake, but only after removing added foragers (added in 2006 when sample was dwindling) rbind(secondyearzerobees,secondyearBehavawakebees)->secondyearzeroawake rbind(dvbees,Behavawakebees)->dvawake #comparing dv vs. awake, both years rbind(firstyeardvbees,firstyearBehavawakebees)->firstyeardvawake rbind(secondyeardvbees,secondyearBehavawakebees)->secondyeardvawake subset(bees,bees$Newforager=="no")->nonewbees #yes & no only in rows for 2006 data, but can be used for entire dataset (all castes), eliminates all extra foragers, added during 2006 to supplement dwindling sample subset(nonewbees,nonewbees$Caste=="f")->nonewbees_foragers subset(nonewbees_foragers,nonewbees_foragers$Behav=="awake")->nonewbees_foragers_awake #FORAGERS: Tbody & d_n (only data for 2006) model1a1 = lmer(Tbody~(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model1a2 = lmer(Tbody~d_n+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model11 = lmer(Tbody~Beh+d_n+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model1a4 = lmer(Tbody~Beh*d_n+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model11 = lmer(Tbody~Behav+d_n+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model1d = lmer(Tbody~d_n+(1|Bee), data=subset(awakebees,awakebees$Caste=="f"), na.action=na.omit) model1e = lmer(Tbody~d_n+(1|Bee), data=subset(zerobees,zerobees$Caste=="f"), na.action=na.omit) model12 = lmer(Tbody~d_n+(1|Bee), data=subset(Behasleepbees, Behasleepbees$Caste=="f"), na.action=na.omit) model2a = lmer(Tbodysurr~d_n+(1|Bee), data=foragers, na.action=na.omit) model2b = lmer(Tbodysurr~Beh*d_n+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model2c = lmer(Tbodysurr~Behav*d_n+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model2d = lmer(Tbodysurr~d_n+(1|Bee), data=subset(awakebees,awakebees$Caste=="f"), na.action=na.omit) model2e = lmer(Tbodysurr~d_n+(1|Bee), data=subset(zerobees,zerobees$Caste=="f"), na.action=na.omit) model2f = lmer(Tbodysurr~d_n+(1|Bee), data=subset(Behasleepbees, Behasleepbees$Caste=="f"), na.action=na.omit) #FORAGERS: Tbody & UnderColor_majority (only data for 2006) model3b = lmer(Tbody~Beh*UnderColor_majority+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model3c = lmer(Tbody~Behav*UnderColor_majority+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model3d = lmer(Tbody~UnderColor_majority+(1|Bee), data=subset(awakebees,awakebees$Caste=="f"), na.action=na.omit) model3e = lmer(Tbody~UnderColor_majority+(1|Bee), data=subset(zerobees,zerobees$Caste=="f"), na.action=na.omit) model3f = lmer(Tbody~UnderColor_majority+(1|Bee), data=subset(Behasleepbees, Behasleepbees$Caste=="f"), na.action=na.omit) model4b = lmer(Tbodysurr~Beh*UnderColor_majority+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model4c = lmer(Tbodysurr~Behav*UnderColor_majority+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model4d = lmer(Tbodysurr~UnderColor_majority+(1|Bee), data=subset(awakebees,awakebees$Caste=="f"), na.action=na.omit) model4e = lmer(Tbodysurr~UnderColor_majority+(1|Bee), data=subset(zerobees,zerobees$Caste=="f"), na.action=na.omit) model4f = lmer(Tbodysurr~UnderColor_majority+(1|Bee), data=subset(Behasleepbees, Behasleepbees$Caste=="f"), na.action=na.omit) #FORAGERS: Tbody & UnderColor_white (only data for 2006) model5b = lmer(Tbody~Beh*UnderColor_white+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model5c = lmer(Tbody~Behav*UnderColor_white+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model5d = lmer(Tbody~UnderColor_white+(1|Bee), data=subset(awakebees,awakebees$Caste=="f"), na.action=na.omit) model5e = lmer(Tbody~UnderColor_white+(1|Bee), data=subset(zerobees,zerobees$Caste=="f"), na.action=na.omit) model5f = lmer(Tbody~UnderColor_white+(1|Bee), data=subset(Behasleepbees, Behasleepbees$Caste=="f"), na.action=na.omit) model6b = lmer(Tbodysurr~Beh*UnderColor_white+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model6c = lmer(Tbodysurr~Behav*UnderColor_white+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model6d = lmer(Tbodysurr~UnderColor_white+(1|Bee), data=subset(awakebees,awakebees$Caste=="f"), na.action=na.omit) model6e = lmer(Tbodysurr~UnderColor_white+(1|Bee), data=subset(zerobees,zerobees$Caste=="f"), na.action=na.omit) model6f = lmer(Tbodysurr~UnderColor_white+(1|Bee), data=subset(Behasleepbees, Behasleepbees$Caste=="f"), na.action=na.omit) #FORAGERS: Tbody & cm_edge (only data for 2006) model7b = lmer(Tbody~Beh*cm_edge+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model7c = lmer(Tbody~Behav*cm_edge+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model7d = lmer(Tbody~cm_edge+(1|Bee), data=subset(awakebees,awakebees$Caste=="f"), na.action=na.omit) model7e = lmer(Tbody~cm_edge+(1|Bee), data=subset(zerobees,zerobees$Caste=="f"), na.action=na.omit) model7f = lmer(Tbody~cm_edge+(1|Bee), data=subset(Behasleepbees, Behasleepbees$Caste=="f"), na.action=na.omit) model8a = lmer(Tbodysurr~cm_edge+(1|Bee), data=foragers, na.action=na.omit) model8b = lmer(Tbodysurr~Beh*cm_edge+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model8c = lmer(Tbodysurr~Behav*cm_edge+(1|Bee), data=subset(bees,bees$Caste=="f"), na.action=na.omit) model8d = lmer(Tbodysurr~cm_edge+(1|Bee), data=subset(awakebees,awakebees$Caste=="f"), na.action=na.omit) model8e = lmer(Tbodysurr~cm_edge+(1|Bee), data=subset(zerobees,zerobees$Caste=="f"), na.action=na.omit) model8f = lmer(Tbodysurr~cm_edge+(1|Bee), data=subset(Behasleepbees, Behasleepbees$Caste=="f"), na.action=na.omit) #Repeat above with other castes (n, fs, & c = nurse bees, food storers, & cell cleaners, respectively) #Beh~Tsurr [NOTE that family=binomial because Beh is categorical, not continuous (default; family=gaussian)] mod9a = lmer(Beh~Tsurr*cm_edge+(1|Bee), data=subset(bees,bees$Caste=="f"), family = binomial, na.action=na.omit) mod9b = lmer(Beh~Tsurr*d_n+(1|Bee), data=subset(bees,bees$Caste=="f"), family = binomial, na.action=na.omit) mod9c = lmer(Beh~Tsurr*UnderColor_majority+(1|Bee), data=subset(bees,bees$Caste=="f"), family = binomial, na.action=na.omit) mod9d = lmer(Beh~Tsurr*UnderColor_white+(1|Bee), data=subset(bees,bees$Caste=="f"), family = binomial, na.action=na.omit) #Behav~Tsurr mod9e = lmer(Behav~Tsurr*cm_edge+(1|Bee), data=subset(bees,bees$Caste=="f"), family = binomial, na.action=na.omit) mod9f = lmer(Behav~Tsurr*d_n+(1|Bee), data=subset(bees,bees$Caste=="f"), family = binomial, na.action=na.omit) mod9g = lmer(Behav~Tsurr*UnderColor_majority+(1|Bee), data=subset(bees,bees$Caste=="f"), family = binomial, na.action=na.omit) mod9h = lmer(Behav~Tsurr*UnderColor_white+(1|Bee), data=subset(bees,bees$Caste=="f"), family = binomial, na.action=na.omit) #Repeat with other castes #mean(na.omit(bees$cm_edge[bees$Caste=="f"])) #Mean #binary logistic regression: #arbitrary name(e.g., g) = glm(DEPENDENT VAR~INDEPvar+INDEPvar2, family=binomial)