---
title: "R Notebook"
output: html_notebook
---
```{r}
#ibrary for arranging figures
library(gridExtra)
#library for our data transformation tools
library(dplyr)
#Useful library for recoding factors
library(forcats)
#type II ANOVA
require(car)
require(drc)
require(ggplot2)
library(nlme)
library(emmeans)
getwd()
Dev_Reallometry <- read.csv("./ReDevelop_IntervalPixels.csv")
#col_names = TRUE, na = "NA",
#col_types = list(
# TimeF = col_character(),
#Time = col_double(),
#Food = col_factor(c("10", "25", "100")),
# Temp = col_factor(c("25", "29")),
#Stage = col_factor(c("L1", "L3")),
#BrainVolume = col_double(),
# LarvalVolume = col_double()))
head(Dev_Reallometry)
Dev_Reallometry<- Dev_Reallometry %>% mutate(Time_Food = paste(TimeF, Food, sep = "_"), LarvalVolume = LarvalPixels * 100000000, logBrain= log(BrainPixelSize), logMB = log(MBPixelSize), logVolume = log(LarvalVolume), FoodF = as.factor(Food), Temp = as.factor(Temp), Time_Treatment = paste(TimeF, Food, Temp, Stage, sep = "_"))
###check the conversion of the size of each pixel for the larval volume and brain volume (larval volume 300 pixels/mm)
##Prepupa - 80um per pixel, Wandering - 70um/pixel and L3 - 50um
Dev_Reallometry
```
seperate by stage
```{r}
L1_BrainDev <- Dev_Reallometry %>% filter(Stage == "L1")
L2_BrainDev <- Dev_Reallometry %>% filter(Stage == "L2")
L3_BrainDev <- Dev_Reallometry %>% filter(Stage == "L3")
```
traits over time for L1, L2, and L3 larval, brain, and mushroom body volumes on 100% food and at 25ºC
```{r}
FigReL1a<-ggplot(data= L1_BrainDev, aes(x= Time, y= logVolume))+
xlab("Time (hours after hatch)")+
ylab("Larval Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
scale_y_continuous(limits=c(12,21))+
scale_colour_manual(values=c("black"))+
geom_point(shape = 1, size=3, alpha=0.7)+
geom_smooth(method="lm", colour = "black", fill = "black", se=FALSE, size = 1) +
#geom_errorbar(aes(ymin = brain_mean-brain_CI, ymax=brain_mean + brain_CI))+
#geom_errorbarh(aes(xmin = larval_mean-larval_CI, xmax=larval_mean + larval_CI))+
#facet_grid(. ~ Stage)+
geom_blank()
FigReL1a
FigReL1b<-ggplot(data= L1_BrainDev, aes(x= Time, y= logBrain))+
xlab("Time (hours after hatch)")+
ylab("Whole Brain Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
scale_y_continuous(limits=c(12.5,16.5))+
scale_colour_manual(values=c("black"))+
geom_point(shape = 16, size=3, alpha=0.7)+
geom_smooth(method="lm", colour = "black", fill = "black", se=FALSE, size = 1) +
#geom_errorbar(aes(ymin = brain_mean-brain_CI, ymax=brain_mean + brain_CI))+
#geom_errorbarh(aes(xmin = larval_mean-larval_CI, xmax=larval_mean + larval_CI))+
#facet_grid(. ~ Stage)+
geom_blank()
FigReL1b
FigReL1c<-ggplot(data= L1_BrainDev, aes(x= Time, y= logMB))+
xlab("Time (hours after hatch)")+
ylab("Mushroom Body Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
scale_y_continuous(limits=c(6.9,11.5))+
scale_colour_manual(values=c("black"))+
geom_point(shape = 17, size=3)+
geom_smooth(method="lm", colour = "black", fill = "black", se=FALSE, size = 1) +
#geom_errorbar(aes(ymin = brain_mean-brain_CI, ymax=brain_mean + brain_CI))+
#geom_errorbarh(aes(xmin = larval_mean-larval_CI, xmax=larval_mean + larval_CI))+
#facet_grid(. ~ Stage)+
geom_blank()
FigReL1c
```
stats for L1
```{r}
larval.lmL1 <- lm(logVolume ~ Time, data = L1_BrainDev)
Anova(larval.lmL1)
summary(larval.lmL1)
brain.lmL1 <- lm(logBrain ~ Time, data = L1_BrainDev)
Anova(brain.lmL1)
summary(brain.lmL1)
MB.lmL1 <- lm(logMB ~ Time, data = L1_BrainDev)
Anova(MB.lmL1)
summary(MB.lmL1)
```
L2s
```{r}
FigReL2a<-ggplot(data= subset(L2_BrainDev, FoodF == "100" & Temp == "25"), aes(x= Time, y= logVolume))+
xlab("Time (hours after L2 moult)")+
ylab("Larval Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
scale_y_continuous(limits=c(12,21))+
scale_colour_manual(values=c("black"))+
geom_point(shape = 1, size=3, alpha=0.7)+
geom_smooth(method="lm", colour = "black", fill = "black", se=FALSE, size = 1) +
#geom_errorbar(aes(ymin = brain_mean-brain_CI, ymax=brain_mean + brain_CI))+
#geom_errorbarh(aes(xmin = larval_mean-larval_CI, xmax=larval_mean + larval_CI))+
#facet_grid(. ~ Stage)+
geom_blank()
FigReL2a
FigReL2b<-ggplot(data= subset(L2_BrainDev, FoodF == "100" & Temp == "25"), aes(x= Time, y= logBrain))+
xlab("Time (hours after L2 moult)")+
ylab("Whole Brain Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
scale_y_continuous(limits=c(12.5,16.5))+
scale_colour_manual(values=c("black"))+
geom_point(shape = 16, size=3, alpha=0.7)+
#geom_smooth(method="lm", colour = "black", fill = "black", se=FALSE, size = 1) +
#geom_errorbar(aes(ymin = brain_mean-brain_CI, ymax=brain_mean + brain_CI))+
#geom_errorbarh(aes(xmin = larval_mean-larval_CI, xmax=larval_mean + larval_CI))+
#facet_grid(. ~ Stage)+
geom_blank()
FigReL2b
FigReL2c<-ggplot(data= subset(L2_BrainDev, FoodF == "100" & Temp == "25"), aes(x= Time, y= logMB))+
xlab("Time (hours after L2 moult)")+
ylab("Mushroom Body Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
scale_y_continuous(limits=c(6.9,11.5))+
scale_colour_manual(values=c("black"))+
geom_point(shape = 17, size=3)+
geom_smooth(method="lm", colour = "black", fill = "black", se=FALSE, size = 1) +
#geom_errorbar(aes(ymin = brain_mean-brain_CI, ymax=brain_mean + brain_CI))+
#geom_errorbarh(aes(xmin = larval_mean-larval_CI, xmax=larval_mean + larval_CI))+
#facet_grid(. ~ Stage)+
geom_blank()
FigReL2c
```
stats for L2
```{r}
larval.lmL2 <- lm(logVolume ~ Time, data = subset(L2_BrainDev, FoodF == "100" & Temp == "25"))
Anova(larval.lmL2)
summary(larval.lmL2)
brain.lmL2 <- lm(logBrain ~ Time, data = subset(L2_BrainDev, FoodF == "100" & Temp == "25"))
Anova(brain.lmL2)
summary(brain.lmL2)
MB.lmL2 <- lm(logMB ~ Time, data = subset(L2_BrainDev, FoodF == "100" & Temp == "25"))
Anova(MB.lmL2)
summary(MB.lmL2)
```
L3s control
```{r}
FigReL3a<-ggplot(data= subset(L3_BrainDev, FoodF == "100" & Temp == "25"), aes(x= Time, y= logVolume))+
xlab("Time (hours after L3 moult)")+
ylab("Larval Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
scale_y_continuous(limits=c(12,21))+
scale_colour_manual(values=c("black"))+
geom_point(shape = 1, size=3, alpha=0.7)+
geom_smooth(method="lm", colour = "black", fill = "black", se=FALSE, size = 1) +
#geom_errorbar(aes(ymin = brain_mean-brain_CI, ymax=brain_mean + brain_CI))+
#geom_errorbarh(aes(xmin = larval_mean-larval_CI, xmax=larval_mean + larval_CI))+
#facet_grid(. ~ Stage)+
geom_blank()
FigReL3a
brain.explagL3_100 <- nls(logBrain ~ a + exp((Time - b)/c), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"), start = list(a = 20, b = 1, c = 5))
summary(brain.explagL3_100)
coef1 <- coef(brain.explagL3_100)
fun_1 <- function(x) coef1[1] + exp((x-coef1[2])/coef1[3])
FigReL3b<-ggplot(data= subset(L3_BrainDev, FoodF == "100" & Temp == "25"), aes(x= Time, y= logBrain))+
xlab("Time (hours after L3 moult)")+
ylab("Whole Brain Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
scale_y_continuous(limits=c(12.5,16.5))+
scale_colour_manual(values=c("black"))+
geom_point(shape = 16, size=3, alpha=0.7)+
stat_function(fun = fun_1, size = 2)+
# geom_smooth(method="nls", method.args = list(formula = y ~ D + (A-D)/(1+ (x/C)^B), start=list(A=20,B=116,C=-2.33,D=47)), colour = "black", fill = "black", se=FALSE, size = 1) +
#geom_errorbar(aes(ymin = brain_mean-brain_CI, ymax=brain_mean + brain_CI))+
#geom_errorbarh(aes(xmin = larval_mean-larval_CI, xmax=larval_mean + larval_CI))+
#facet_grid(. ~ Stage)+
geom_blank()
FigReL3b
# b:(Intercept) c:(Intercept) d:(Intercept) e:(Intercept)
# -2.334232 20.981898 47.679576 116.629141
FigReL3c<-ggplot(data= subset(L3_BrainDev, FoodF == "100" & Temp == "25"), aes(x= Time, y= logMB))+
xlab("Time (hours after L3 moult)")+
ylab("Mushroom Body Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
scale_y_continuous(limits=c(6.9,11.5))+
scale_colour_manual(values=c("black"))+
geom_point(shape = 17, size=3)+
geom_smooth(method="lm",colour = "black", fill = "black", se=FALSE, size = 1) +
#geom_errorbar(aes(ymin = brain_mean-brain_CI, ymax=brain_mean + brain_CI))+
#geom_errorbarh(aes(xmin = larval_mean-larval_CI, xmax=larval_mean + larval_CI))+
#facet_grid(. ~ Stage)+
geom_blank()
FigReL3c
pdf("./FigBrainTraitsOverTime.pdf", width=15, height=12, useDingbats=FALSE)
grid.arrange(FigReL1a, FigReL2a, FigReL3a, FigReL1b, FigReL2b, FigReL3b,FigReL1c, FigReL2c, FigReL3c,ncol=3)
dev.off()
```
L3 stats
```{r}
volume.lmL3 <- lm(logVolume ~ Time, data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"))
Anova(volume.lmL3)
summary(volume.lmL3)
volume.lmL3poly <- lm(logVolume ~ poly(Time,2, raw = TRUE), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"))
Anova(volume.lmL3poly)
summary(volume.lmL3poly)
#volume.lmL3gompertz <- lm(logVolume ~ SSgompertz(Time, Asym, b2, b3), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"))
#Anova(volume.lmL3gompertz)
#summary(volume.lmL3gompertz)
volume.expL3 <- nls(logVolume ~ a + exp(b * Time), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"), start = list(a = 20, b = 0.5))
summary(volume.expL3)
#volume.explagL3_100 <- nls(logVolume ~ a + exp((Time - b) / c), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"), start = list(a = 15, b = 0, c = 50))
#summary(volume.explagL3_100)
### I can't get this model to resolve, even if b=0, which makes no sense.
volume.powerL3 <- nls(logVolume ~ A + (Time ^ B), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"), start = list(A = 20, B = 0.5))
summary(volume.powerL3)
AIC(volume.lmL3)
AIC(volume.lmL3poly)
AIC(volume.expL3)
#AIC(volume.explagL3_100)
AIC(volume.powerL3)
BIC(volume.lmL3)
BIC(volume.lmL3poly)
BIC(volume.expL3)
#AIC(volume.explagL3_100)
BIC(volume.powerL3)
brain.lmL3 <- lm(logBrain ~ Time, data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"))
Anova(brain.lmL3)
summary(brain.lmL3)
brain.lmL3poly <- lm(logBrain ~ poly(Time,2, raw = TRUE), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"))
Anova(brain.lmL3poly)
summary(brain.lmL3poly)
brain.expL3 <- nls(logBrain ~ a + exp(b * Time), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"), start = list(a = 20, b = 0))
summary(brain.expL3)
coef(brain.expL3)
brain.explagL3_100 <- nls(logBrain ~ a + exp((Time - b)/c), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"), start = list(a = 20, b = 1, c = 5))
summary(brain.explagL3_100)
brain.powerL3 <- nls(logBrain ~ A + (Time ^ B), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"), start = list(A = 20, B = 0.5))
summary(brain.powerL3)
AIC(brain.lmL3)
AIC(brain.lmL3poly)
AIC(brain.expL3)
AIC(brain.explagL3_100)
AIC(brain.powerL3)
BIC(brain.lmL3)
BIC(brain.lmL3poly)
BIC(brain.expL3)
BIC(brain.explagL3_100)
BIC(brain.powerL3)
MB.lmL3 <- lm(logMB ~ Time, data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"))
Anova(MB.lmL3)
summary(MB.lmL3)
MB.lmL3poly <- lm(logMB ~ poly(Time,2, raw = TRUE), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"))
Anova(MB.lmL3poly)
summary(MB.lmL3poly)
MB.expL3 <- nls(logMB ~ a + exp(b * Time), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"), start = list(a = 20, b = 0))
summary(MB.expL3)
coef(MB.expL3)
MB.explagL3_100 <- nls(logMB ~ a + exp((Time - b)/c), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"), start = list(a = 20, b = 1, c = 5))
summary(MB.explagL3_100)
MB.powerL3 <- nls(logMB ~ A + (Time ^ B), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"), start = list(A = 20, B = 0.5))
summary(MB.powerL3)
AIC(MB.lmL3)
AIC(MB.lmL3poly)
AIC(MB.expL3)
AIC(MB.explagL3_100)
AIC(MB.powerL3)
BIC(MB.lmL3)
BIC(MB.lmL3poly)
BIC(MB.expL3)
BIC(MB.explagL3_100)
BIC(MB.powerL3)
```
pupal brain and mushroom body volume by food
```{r}
FigReL3PupalVolumeALL <- ggplot(data= subset(Dev_Reallometry, TimeF == "Prepupa"))+
xlab("Food Dilution (%)")+
ylab("Prepupal Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
theme(strip.text.x = element_text(size = 16))+
#scale_y_continuous(limits=c(15,17))+
scale_colour_manual(values=c("#8fbdcc", "#33cfff", "black"))+
scale_fill_manual(values=c("#8fbdcc", "#33cfff", "black"))+
geom_point(aes(x= FoodF, y= logVolume, colour = FoodF, fill = FoodF), shape = 1, size=5, alpha = 1)+
facet_grid(~ Temp)+
geom_blank()
FigReL3PupalVolumeALL
FigReL3PupalMBALL<-ggplot(data= subset(Dev_Reallometry, TimeF == "Prepupa"))+
xlab("Food Dilution (%)")+
ylab("Mushroom Body Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
theme(strip.text.x = element_text(size = 16))+
scale_y_continuous(limits=c(9.75,12.25))+
scale_colour_manual(values=c("#b3edff", "#33cfff", "black"))+
scale_fill_manual(values=c("#b3edff", "#33cfff", "black"))+
geom_point(aes(x= FoodF, y= logMB, colour = FoodF, fill = FoodF), shape = 17, size=5, alpha = 0.7)+
facet_grid(~ Temp)+
geom_blank()
FigReL3PupalMBALL
FigReL3PupalBrainALL <- ggplot(data= subset(Dev_Reallometry, TimeF == "Prepupa"))+
xlab("Food Dilution (%)")+
ylab("Whole Brain Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
theme(strip.text.x = element_text(size = 16))+
scale_y_continuous(limits=c(14.75,17.25))+
scale_colour_manual(values=c("#b3edff", "#33cfff", "black"))+
scale_fill_manual(values=c("#b3edff", "#33cfff", "black"))+
geom_point(aes(x= FoodF, y= logBrain, colour = FoodF, fill = FoodF), shape = 16, size=5, alpha = 0.7)+
facet_grid(~ Temp)+
geom_blank()
FigReL3PupalBrainALL
pdf("./FigReL3PupalVolumesALL.pdf", width=8, height=18, useDingbats=FALSE)
grid.arrange(FigReL3PupalVolumeALL, FigReL3PupalBrainALL, FigReL3PupalMBALL, ncol=1)
dev.off()
```
stats for pupal brains by food and temperature (to match plots)
```{r}
lm_Volume_ALL <- lm(logVolume ~ Food * Temp, data = subset(Dev_Reallometry, TimeF == "Prepupa"))
summary(lm_Volume_ALL)
Anova(lm_Volume_ALL)
lm_brain_ALL <- lm(logBrain ~ Food * Temp, data = subset(Dev_Reallometry, TimeF == "Prepupa"))
summary(lm_brain_ALL)
Anova(lm_brain_ALL)
lm_MB_ALL <- lm(logMB ~ Food * Temp, data = subset(Dev_Reallometry, TimeF == "Prepupa"))
summary(lm_MB_ALL)
Anova(lm_MB_ALL)
```
proportional brain and mushroom body volume by larval volume
```{r}
FigReL3PupalMBXbrain <- ggplot(data= subset(Dev_Reallometry, TimeF == "Prepupa"))+
xlab("Whole Brain Volume (ln µm3)")+
ylab("Mushroom Body Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=16))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
theme(strip.text.x = element_text(size = 16))+
scale_y_continuous(limits=c(9.75,12.25))+
scale_x_continuous(limits=c(14.75,17.25))+
scale_colour_manual(values=c("#b3edff", "#33cfff", "black"))+
scale_fill_manual(values=c("#b3edff", "#33cfff", "black"))+
geom_point(aes(x= logBrain, y= logMB, colour = FoodF, fill = FoodF), shape = 16, size=5, alpha = 0.7)+
facet_grid(~ Temp)+
geom_blank()
FigReL3PupalMBXbrain
pdf("./FigReL3PupalVolumesALL.pdf", width=16, height=12, useDingbats=FALSE)
grid.arrange(FigReL3PupalVolumeALL, FigReL3PupalBrainALL, FigReL3PupalMBALL,FigReL3PupalMBXbrain, ncol=2)
dev.off()
```
brain and mushroom body volumes by larval volume
```{r}
lm_brainXvolume <- lm(logBrain ~ logVolume * Food * Temp, data = subset(Dev_Reallometry, TimeF == "Prepupa"))
summary(lm_brainXvolume)
Anova(lm_brainXvolume)
lm_MBXvolume <- lm(logMB ~ logVolume * Food * Temp, data = subset(Dev_Reallometry, TimeF == "Prepupa"))
summary(lm_MBXvolume)
Anova(lm_MBXvolume)
lm_MBXbrain <- lm(logMB ~ logBrain * Food * Temp, data = subset(Dev_Reallometry, TimeF == "Prepupa"))
summary(lm_MBXbrain)
Anova(lm_MBXbrain)
```
growth dynamics over food conditions
first some stats - we've already done the 100% food at 25ºC above, I would argue we could do the statistical analysis using polynomials and plot the lagged exponentials based on the analysis above.
```{r}
#test to see if curves differ by temperature and nutrition
#larval volume
volume.lmL3 <- lm(logVolume ~ Time * as.factor(Food) * as.factor(Temp), data = L3_BrainDev)
Anova(volume.lmL3)
summary(volume.lmL3)
volume.lmL3.pairwise1 <- emtrends(volume.lmL3, pairwise ~ as.factor(Temp) | as.factor(Food) , var = "Time")
volume.lmL3.pairwise1
volume.lmL3.pairwise2 <- emtrends(volume.lmL3, pairwise ~ as.factor(Food) | as.factor(Temp) , var = "Time")
volume.lmL3.pairwise2
# the whole brain
brain.lmL3poly <- lm(logBrain ~ poly(Time,2, raw = TRUE) * as.factor(Food) * as.factor(Temp), data = L3_BrainDev)
Anova(brain.lmL3poly)
summary(brain.lmL3poly)
brain.lmL3.pairwise1 <- emtrends(brain.lmL3poly, pairwise ~ as.factor(Temp) | as.factor(Food) , var = "Time")
brain.lmL3.pairwise1
brain.lmL3.pairwise2 <- emtrends(brain.lmL3poly, pairwise ~ as.factor(Food) | as.factor(Temp) , var = "Time")
brain.lmL3.pairwise2
#extract the coefficients from the lagged exponential
#25ºC
brain.explagL3_100_25 <- nls(logBrain ~ a + exp((Time - b)/c), data = subset(L3_BrainDev, FoodF == "100" & Temp == "25"), start = list(a = 20, b = 1, c = 5))
summary(brain.explagL3_100_25)
brain.explagL3_25_25 <- nls(logBrain ~ a + exp((Time - b)/c), data = subset(L3_BrainDev, FoodF == "25" & Temp == "25"), start = list(a = 20, b = 1, c = 5))
summary(brain.explagL3_25_25)
brain.explagL3_10_25 <- nls(logBrain ~ a + exp((Time - b)/c), data = subset(L3_BrainDev, FoodF == "10" & Temp == "25"), start = list(a = 20, b = 1, c = 5))
summary(brain.explagL3_10_25)
#29ºC
brain.explagL3_100_29 <- nls(logBrain ~ a + exp((Time - b)/c), data = subset(L3_BrainDev, FoodF == "100" & Temp == "29"), start = list(a = 20, b = 1, c = 5))
summary(brain.explagL3_100_29)
brain.explagL3_25_29 <- nls(logBrain ~ a + exp((Time - b)/c), data = subset(L3_BrainDev, FoodF == "25" & Temp == "29"), start = list(a = 20, b = 1, c = 5))
summary(brain.explagL3_25_29)
brain.explagL3_10_29 <- nls(logBrain ~ a + exp((Time - b)/c), data = subset(L3_BrainDev, FoodF == "10" & Temp == "29"), start = list(a = 20, b = 1, c = 5))
summary(brain.explagL3_10_29)
#25ºC
coef1 <- coef(brain.explagL3_100_25)
coef2 <- coef(brain.explagL3_25_25)
coef3 <- coef(brain.explagL3_10_25)
#29ºC
coef4 <- coef(brain.explagL3_100_29)
coef5 <- coef(brain.explagL3_25_29)
coef6 <- coef(brain.explagL3_10_29)
#25ºC
fun_1 <- function(x) coef1[1] + exp((x-coef1[2])/coef1[3])
fun_2 <- function(x) coef2[1] + exp((x-coef2[2])/coef2[3])
fun_3 <- function(x) coef3[1] + exp((x-coef3[2])/coef3[3])
#29ºC
fun_4 <- function(x) coef4[1] + exp((x-coef4[2])/coef4[3])
fun_5 <- function(x) coef5[1] + exp((x-coef5[2])/coef5[3])
fun_6 <- function(x) coef6[1] + exp((x-coef6[2])/coef6[3])
MB.lmL3 <- lm(logMB ~ Time * as.factor(Food) * as.factor(Temp), data = L3_BrainDev)
Anova(MB.lmL3)
summary(MB.lmL3)
MB.lmL3.pairwise1 <- emtrends(MB.lmL3, pairwise ~ as.factor(Temp) | as.factor(Food) , var = "Time")
MB.lmL3.pairwise1
MB.lmL3.pairwise2 <- emtrends(MB.lmL3, pairwise ~ as.factor(Food) | as.factor(Temp) , var = "Time")
MB.lmL3.pairwise2
MB.lmL3.pairwise3 <- emmeans(MB.lmL3, pairwise ~ as.factor(Temp) | as.factor(Food) , var = "Time")
MB.lmL3.pairwise3
```
over time by food and temperature
```{r}
FigReL3Larval25 <- ggplot(data = subset(L3_BrainDev, Temp == "25"))+
xlab("Time (hours after L3 moult)")+
ylab("Larval Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
theme(strip.text.x = element_text(size = 16))+
scale_y_continuous(limits=c(16,20))+
scale_colour_manual(values=c("#b3edff", "#33cfff", "black"))+
scale_fill_manual(values=c("#b3edff", "#33cfff", "black"))+
geom_point(aes(x= Time, y= logVolume, colour = FoodF, fill = FoodF), shape = 1, size=3)+
geom_smooth(aes(x = Time, y= logVolume, colour = FoodF, fill = FoodF), method="lm", se = FALSE, size = 2)+
geom_blank()
FigReL3Larval25
FigReL3Larval29 <- ggplot(data = subset(L3_BrainDev, Temp == "29"))+
xlab("Time (hours after L3 moult)")+
ylab("Larval Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
theme(strip.text.x = element_text(size = 16))+
scale_y_continuous(limits=c(16,20))+
scale_colour_manual(values=c("#b3edff", "#33cfff", "black"))+
scale_fill_manual(values=c("#b3edff", "#33cfff", "black"))+
geom_point(aes(x= Time, y= logVolume, colour = FoodF, fill = FoodF), shape = 1, size=3)+
geom_smooth(aes(x = Time, y= logVolume, colour = FoodF, fill = FoodF), method="lm", se = FALSE, size = 2)+
geom_blank()
FigReL3Larval29
FigReL3Brain25<-ggplot(data = subset(L3_BrainDev, Temp == "25"))+
xlab("Time (hours after L3 moult)")+
ylab("Whole Brain Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
theme(strip.text.x = element_text(size = 16))+
scale_y_continuous(limits=c(13.75,17.25))+
scale_colour_manual(values=c("#b3edff", "#33cfff", "black"))+
scale_fill_manual(values=c("#b3edff", "#33cfff", "black"))+
geom_point(aes(x= Time, y= logBrain, colour = FoodF, fill = FoodF), shape = 16, size=3)+
stat_function(fun = fun_1, size = 2, xlim = c(0,43))+
stat_function(fun = fun_2, size = 2, colour = "#33cfff", xlim = c(0,50))+
stat_function(fun = fun_3, size = 2, colour = "#b3edff")+
geom_blank()
FigReL3Brain25
FigReL3Brain29<-ggplot(data = subset(L3_BrainDev, Temp == "29"))+
xlab("Time (hours after L3 moult)")+
ylab("Whole Brain Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
theme(strip.text.x = element_text(size = 16))+
scale_y_continuous(limits=c(13.75,17.25))+
scale_colour_manual(values=c("#b3edff", "#33cfff", "black"))+
scale_fill_manual(values=c("#b3edff", "#33cfff", "black"))+
geom_point(aes(x= Time, y= logBrain, colour = FoodF, fill = FoodF), shape = 16, size=3)+
stat_function(fun = fun_4, size = 2, xlim = c(0,43))+
stat_function(fun = fun_5, size = 2, colour = "#33cfff", xlim = c(0,43))+
stat_function(fun = fun_6, size = 2, colour = "#b3edff")+
geom_blank()
FigReL3Brain29
FigReL3MB25<-ggplot(data= subset(L3_BrainDev, Temp == "25"))+
xlab("Time (hours after L3 moult)")+
ylab("Mushroom Body Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
scale_y_continuous(limits=c(8.5,12))+
scale_colour_manual(values=c("#b3edff", "#33cfff", "black"))+
scale_fill_manual(values=c("#b3edff", "#33cfff", "black"))+
geom_point(aes(x= Time, y= logMB, colour = FoodF, fill = FoodF), shape = 17, size=3)+
geom_smooth(aes(x= Time, y= logMB, colour = FoodF, fill = FoodF), method="lm", se=FALSE, size = 2) +
geom_blank()
FigReL3MB25
FigReL3MB29<-ggplot(data= subset(L3_BrainDev, Temp == "29"))+
xlab("Time (hours after L3 moult)")+
ylab("Mushroom Body Volume (ln µm3)")+
theme_bw()+
theme(panel.grid=element_blank(),axis.title.x=element_text(size=20), axis.title.y=element_text(size=20),
axis.text.y=element_text(size=16), axis.text.x=element_text(size=16), panel.background = element_rect(colour = "black"), legend.background = element_rect(), legend.key = element_rect(colour = "white"), legend.text=element_text(face="italic", size=14))+
theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=1.5))+
theme(legend.title=element_blank())+
theme(legend.title=element_blank())+
theme(plot.margin=unit(c(1,1,1,1),"cm"))+
scale_y_continuous(limits=c(8.5,12))+
scale_colour_manual(values=c("#b3edff", "#33cfff", "black"))+
scale_fill_manual(values=c("#b3edff", "#33cfff", "black"))+
geom_point(aes(x= Time, y= logMB, colour = FoodF, fill = FoodF), shape = 17, size=3)+
geom_smooth(aes(x= Time, y= logMB, colour = FoodF, fill = FoodF), method="lm", se=FALSE, size = 2) +
geom_blank()
FigReL3MB29
pdf("./FigReL3GrowthXEnvironment.pdf", width=15, height=18, useDingbats=FALSE)
grid.arrange(FigReL3Larval25, FigReL3Larval29, FigReL3Brain25, FigReL3Brain29, FigReL3MB25, FigReL3MB29, ncol=2)
dev.off()
```
we wanted to test between hypothesis 1, 2, and 3.
to test if hypothesis 1 is correct, we would expect a gompertz model to fit the brain/mushroom body data better than linear/polynomial/lagged exponential model in poorer food conditions
none of these models resolve for the brain
```{r}
# 25% food, 25ºC
#brain.gompertz_25_25 = nls(logBrain ~ SSgompertz(Time, Asym, b2, b3), data = subset(L3_BrainDev, FoodF == "25" & Temp == "25"))
#summary(brain.gompertz_25_25)
#brain.asymp_25_25 = nls(logBrain ~ SSasymp(Time, Asym, R0, lrc), data = subset(L3_BrainDev, FoodF == "25" & Temp == "25"))
#summary(brain.asymp_25_25)
####these models do not resolve
# 10% food, 25ºC
#brain.gompertz_10_25 = nls(logBrain ~ SSgompertz(Time, Asym, b2, b3), data = subset(L3_BrainDev, FoodF == "10" & Temp == "25"))
#summary(brain.gompertz_25_25)
#brain.asymp_10_25 = nls(logBrain ~ SSasymp(Time, Asym, R0, lrc), data = subset(L3_BrainDev, FoodF == "10" & Temp == "25"))
#summary(brain.asymp_10_25)
# 25% food, 29ºC
#brain.gompertz_25_29 = nls(logBrain ~ SSgompertz(Time, Asym, b2, b3), data = subset(L3_BrainDev, FoodF == "25" & Temp == "29"))
#summary(brain.gompertz_25_29)
#brain.asymp_25_29 = nls(logBrain ~ SSasymp(Time, Asym, R0, lrc), data = subset(L3_BrainDev, FoodF == "25" & Temp == "29"))
#summary(brain.asymp_25_29)
# 10% food, 29ºC
#brain.gompertz_10_29 = nls(logBrain ~ SSgompertz(Time, Asym, b2, b3), data = subset(L3_BrainDev, FoodF == "10" & Temp == "29"))
#summary(brain.gompertz_25_29)
#brain.asymp_10_29 = nls(logBrain ~ SSasymp(Time, Asym, R0, lrc), data = subset(L3_BrainDev, FoodF == "10" & Temp == "29"))
#summary(brain.asymp_10_29)
```
At least we would expect that the polynomial for time would be negative as the brain size reaches a plateau for the poorer conditions
in all cases where the poly2 is significant for the brain and mushroom body, it is positive. this suggests that hypothesis 1 is unlikely
```{r}
####whole brain
#25% food, 25ºC
brain.poly_25_25 = lm(logBrain ~ poly(Time, 2, raw = TRUE), data = subset(L3_BrainDev, FoodF == "25" & Temp == "25"))
summary(brain.poly_25_25)
#10% food, 25ºC
brain.poly_10_25 = lm(logBrain ~ poly(Time, 2, raw = TRUE), data = subset(L3_BrainDev, FoodF == "10" & Temp == "25"))
summary(brain.poly_10_25)
#25% food, 29ºC
brain.poly_25_29 = lm(logBrain ~ poly(Time, 2, raw = TRUE), data = subset(L3_BrainDev, FoodF == "25" & Temp == "29"))
summary(brain.poly_25_29)
#10% food, 29ºC
brain.poly_10_29 = lm(logBrain ~ poly(Time, 2, raw = TRUE), data = subset(L3_BrainDev, FoodF == "10" & Temp == "29"))
summary(brain.poly_10_29)
####mushroom body
#25% food, 25ºC
MB.poly_25_25 = lm(logMB ~ poly(Time, 2, raw = TRUE), data = subset(L3_BrainDev, FoodF == "25" & Temp == "25"))
summary(MB.poly_25_25)
#10% food, 25ºC
MB.poly_10_25 = lm(logMB ~ poly(Time, 2, raw = TRUE), data = subset(L3_BrainDev, FoodF == "10" & Temp == "25"))
summary(MB.poly_10_25)
#25% food, 29ºC
MB.poly_25_29 = lm(logMB ~ poly(Time, 2, raw = TRUE), data = subset(L3_BrainDev, FoodF == "25" & Temp == "29"))
summary(MB.poly_25_29)
#10% food, 29ºC
MB.poly_10_29 = lm(logMB ~ poly(Time, 2, raw = TRUE), data = subset(L3_BrainDev, FoodF == "10" & Temp == "29"))
summary(MB.poly_10_29)
```
for hypothesis 2 to be true, we would expect that the rate of growth in the brain would be the same between food/temperature conditions, but that growth would switch on at different times. We can test for this by seeing if the growth rate and time lag coefficient differ between food/temperature conditions
the mushroom body does not fit a lagged exponential trajectory, so should not be modelled in this way.
```{r}
# model for each food condition at 25ºC
x1 <- subset(L3_BrainDev, Food == "100" & Temp == "25")$Time
y1 <- subset(L3_BrainDev, Food == "100" & Temp == "25")$logBrain
x2 <- subset(L3_BrainDev, Food == "25" & Temp == "25")$Time
y2 <- subset(L3_BrainDev, Food == "25" & Temp == "25")$logBrain
x3 <- subset(L3_BrainDev, Food == "10" & Temp == "25")$Time
y3 <- subset(L3_BrainDev, Food == "10" & Temp == "25")$logBrain
n1 <- length(x1)
n2 <- length(x2)
# Comparison between 100 and 25% food at 25ºC
y <- c(y1,y2); x <- c(x1,x2)
lcon1 <- rep(c(1,0), c(n1,n2))
lcon2 <- rep(c(0,1), c(n1,n2))
mcon1 <- lcon1
mcon2 <- lcon2
ncon1 <- lcon1
ncon2 <- lcon2
brain.25.alt <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.25.alt)
brain.25.null <- nls(y ~ a + exp((x - b)/c), start = list(a = 20, b = 1, c = 5))
summary(brain.25.null)
anova(brain.25.alt, brain.25.null)
brain.25.nulla <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/c), start = list(a1 = 20, a2 = 20,b = 1, c = 5))
summary(brain.25.nulla)
anova(brain.25.alt, brain.25.nulla)
brain.25.nullb <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/c), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c = 5))
summary(brain.25.nullb)
anova(brain.25.alt, brain.25.nullb)
brain.25.nullc <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b = 1, c1 = 5, c2 = 5))
summary(brain.25.nullc)
anova(brain.25.alt, brain.25.nullc)
# Comparison between 25% and 10% food at 25ºC
n1 <- length(x2)
n2 <- length(x3)
y <- c(y2,y3); x <- c(x2,x3)
lcon1 <- rep(c(1,0), c(n1,n2))
lcon2 <- rep(c(0,1), c(n1,n2))
mcon1 <- lcon1
mcon2 <- lcon2
ncon1 <- lcon1
ncon2 <- lcon2
brain.25.alt2 <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.25.alt2)
#brain.25.nulla <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/c), start = list(a1 = 20, a2 = 20,b = 1, c = 5))
#summary(brain.25.nulla)
#anova(brain.25.alt2, brain.25.nulla)
brain.25.nullb <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/c), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c = 5))
summary(brain.25.nullb)
anova(brain.25.alt, brain.25.nullb)
#brain.25.nullc <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b = 1, c1 = 5, c2 = 5))
#summary(brain.25.nullc)
#anova(brain.25.alt, brain.25.nullc)
brain.25.nulld <- nls(y ~ a + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.25.nullc)
anova(brain.25.alt, brain.25.nulld)
# Comparison between 100% and 10% food at 25ºC
n1 <- length(x1)
n2 <- length(x3)
y <- c(y1,y3); x <- c(x1,x3)
lcon1 <- rep(c(1,0), c(n1,n2))
lcon2 <- rep(c(0,1), c(n1,n2))
mcon1 <- lcon1
mcon2 <- lcon2
ncon1 <- lcon1
ncon2 <- lcon2
brain.25.alt2 <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.25.alt2)
#brain.25.nulla <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/c), start = list(a1 = 20, a2 = 20,b = 1, c = 5))
#summary(brain.25.nulla)
#anova(brain.25.alt2, brain.25.nulla)
brain.25.nullb <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/c), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c = 5))
summary(brain.25.nullb)
anova(brain.25.alt, brain.25.nullb)
#brain.25.nullc <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b = 1, c1 = 5, c2 = 5))
#summary(brain.25.nullc)
#anova(brain.25.alt, brain.25.nullc)
brain.25.nulld <- nls(y ~ a + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.25.nullc)
anova(brain.25.alt, brain.25.nulld)
# model for each food condition at 29ºC
x1 <- subset(L3_BrainDev, Food == "100" & Temp == "29")$Time
y1 <- subset(L3_BrainDev, Food == "100" & Temp == "29")$logBrain
x2 <- subset(L3_BrainDev, Food == "25" & Temp == "29")$Time
y2 <- subset(L3_BrainDev, Food == "25" & Temp == "29")$logBrain
x3 <- subset(L3_BrainDev, Food == "10" & Temp == "29")$Time
y3 <- subset(L3_BrainDev, Food == "10" & Temp == "29")$logBrain
n1 <- length(x1)
n2 <- length(x2)
# Comparison between 100 and 25% food at 29ºC
y <- c(y1,y2); x <- c(x1,x2)
lcon1 <- rep(c(1,0), c(n1,n2))
lcon2 <- rep(c(0,1), c(n1,n2))
mcon1 <- lcon1
mcon2 <- lcon2
ncon1 <- lcon1
ncon2 <- lcon2
brain.29.alt <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.29.alt)
brain.29.null <- nls(y ~ a + exp((x - b)/c), start = list(a = 20, b = 1, c = 5))
summary(brain.29.null)
anova(brain.29.alt, brain.29.null)
# Comparison between 25% and 10% food at 29ºC
n1 <- length(x2)
n2 <- length(x3)
y <- c(y2,y3); x <- c(x2,x3)
lcon1 <- rep(c(1,0), c(n1,n2))
lcon2 <- rep(c(0,1), c(n1,n2))
mcon1 <- lcon1
mcon2 <- lcon2
ncon1 <- lcon1
ncon2 <- lcon2
brain.29.alt2 <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.29.alt2)
brain.29.null <- nls(y ~ a + exp((x - b)/c), start = list(a = 20, b = 1, c = 5))
summary(brain.29.null)
anova(brain.29.alt2, brain.29.null)
brain.29.nulla <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/c), start = list(a1 = 20, a2 = 20, b = 1, c = 5))
summary(brain.29.nulla)
anova(brain.29.alt2, brain.29.nulla)
brain.29.nullb <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/c), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c = 5))
summary(brain.29.nullb)
anova(brain.29.alt2, brain.29.nullb)
#brain.29.nullc <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/(c1*ncon1 + c2*ncon2)), start = list(a = 20, b = 1, c1 = 5, c2 = 5))
#summary(brain.29.nullc)
#anova(brain.29.alt2, brain.29.nullc)
brain.29.nulld <- nls(y ~ a + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.29.nulld)
anova(brain.29.alt, brain.29.nulld)
# Comparison between 100% and 10% food at 29ºC
n1 <- length(x1)
n2 <- length(x3)
y <- c(y1,y3); x <- c(x1,x3)
lcon1 <- rep(c(1,0), c(n1,n2))
lcon2 <- rep(c(0,1), c(n1,n2))
mcon1 <- lcon1
mcon2 <- lcon2
ncon1 <- lcon1
ncon2 <- lcon2
brain.29.alt2 <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.29.alt2)
brain.29.null <- nls(y ~ a + exp((x - b)/c), start = list(a = 20, b = 1, c = 5))
summary(brain.29.null)
anova(brain.29.alt2, brain.29.null)
brain.29.nulla <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/c), start = list(a1 = 20, a2 = 20,b = 1, c = 5))
summary(brain.29.nulla)
anova(brain.29.alt2, brain.29.nulla)
brain.29.nullb <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/c), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c = 5))
summary(brain.29.nullb)
anova(brain.29.alt2, brain.29.nullb)
brain.29.nullc <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b = 1, c1 = 5, c2 = 5))
summary(brain.29.nullc)
anova(brain.29.alt, brain.29.nullc)
brain.29.nulld <- nls(y ~ a + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.29.nulld)
anova(brain.29.alt, brain.29.nulld)
#now compare same food but accross temperature
# first 100% food at 25 & 29ºC
x1 <- subset(L3_BrainDev, Food == "100" & Temp == "25")$Time
y1 <- subset(L3_BrainDev, Food == "100" & Temp == "25")$logBrain
x2 <- subset(L3_BrainDev, Food == "100" & Temp == "29")$Time
y2 <- subset(L3_BrainDev, Food == "100" & Temp == "29")$logBrain
n1 <- length(x1)
n2 <- length(x2)
y <- c(y1,y2); x <- c(x1,x2)
lcon1 <- rep(c(1,0), c(n1,n2))
lcon2 <- rep(c(0,1), c(n1,n2))
mcon1 <- lcon1
mcon2 <- lcon2
ncon1 <- lcon1
ncon2 <- lcon2
brain.25_29.100.alt <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.25_29.100.alt)
brain.25_29.100.null <- nls(y ~ a + exp((x - b)/c), start = list(a = 20, b = 1, c = 5))
summary(brain.25_29.100.null)
anova(brain.25_29.100.alt, brain.25_29.100.null)
brain.25_29.100.nulla <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/c), start = list(a1 = 20, a2 = 20, b = 1, c = 5))
summary(brain.25_29.100.nulla)
anova(brain.25_29.100.alt, brain.25_29.100.nulla)
brain.25_29.100.nullb <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/c), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c = 5))
summary(brain.25_29.100.nullb)
anova(brain.25_29.100.alt, brain.25_29.100.nullb)
brain.25_29.100.nullc <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b = 1, c1 = 5, c2 = 5))
summary(brain.25_29.100.nullc)
anova(brain.25_29.100.alt, brain.25_29.100.nullc)
# now 25% food at 25 & 29ºC
x1 <- subset(L3_BrainDev, Food == "25" & Temp == "25")$Time
y1 <- subset(L3_BrainDev, Food == "25" & Temp == "25")$logBrain
x2 <- subset(L3_BrainDev, Food == "25" & Temp == "29")$Time
y2 <- subset(L3_BrainDev, Food == "25" & Temp == "29")$logBrain
n1 <- length(x1)
n2 <- length(x2)
y <- c(y1,y2); x <- c(x1,x2)
lcon1 <- rep(c(1,0), c(n1,n2))
lcon2 <- rep(c(0,1), c(n1,n2))
mcon1 <- lcon1
mcon2 <- lcon2
ncon1 <- lcon1
ncon2 <- lcon2
brain.25_29.25.alt <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.25_29.25.alt)
brain.25_29.25.null <- nls(y ~ a + exp((x - b)/c), start = list(a = 20, b = 1, c = 5))
summary(brain.25_29.25.null)
anova(brain.25_29.25.alt, brain.25_29.25.null)
brain.25_29.25.nulla <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/c), start = list(a1 = 20, a2 = 20, b = 1, c = 5))
summary(brain.25_29.25.nulla)
anova(brain.25_29.25.alt, brain.25_29.25.nulla)
brain.25_29.25.nullb <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/c), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c = 5))
summary(brain.25_29.25.nullb)
anova(brain.25_29.25.alt, brain.25_29.25.nullb)
brain.25_29.25.nullc <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b = 1, c1 = 5, c2 = 5))
summary(brain.25_29.25.nullc)
anova(brain.25_29.25.alt, brain.25_29.25.nullc)
# finally 10% food at 25 & 29ºC
x1 <- subset(L3_BrainDev, Food == "10" & Temp == "25")$Time
y1 <- subset(L3_BrainDev, Food == "10" & Temp == "25")$logBrain
x2 <- subset(L3_BrainDev, Food == "10" & Temp == "29")$Time
y2 <- subset(L3_BrainDev, Food == "10" & Temp == "29")$logBrain
n1 <- length(x1)
n2 <- length(x2)
y <- c(y1,y2); x <- c(x1,x2)
lcon1 <- rep(c(1,0), c(n1,n2))
lcon2 <- rep(c(0,1), c(n1,n2))
mcon1 <- lcon1
mcon2 <- lcon2
ncon1 <- lcon1
ncon2 <- lcon2
brain.25_29.10.alt <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c1 = 5, c2 = 5))
summary(brain.25_29.10.alt)
brain.25_29.10.null <- nls(y ~ a + exp((x - b)/c), start = list(a = 20, b = 1, c = 5))
summary(brain.25_29.10.null)
anova(brain.25_29.10.alt, brain.25_29.10.null)
brain.25_29.10.nulla <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/c), start = list(a1 = 20, a2 = 20, b = 1, c = 5))
summary(brain.25_29.10.nulla)
anova(brain.25_29.10.alt, brain.25_29.10.nulla)
brain.25_29.10.nullb <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - (b1*mcon1 + b2*mcon2))/c), start = list(a1 = 20, a2 = 20, b1 = 1, b2 = 1, c = 5))
summary(brain.25_29.10.nullb)
anova(brain.25_29.10.alt, brain.25_29.10.nullb)
brain.25_29.10_ab_anova <- anova(brain.25_29.10.alt, brain.25_29.10.nullb)
brain.25_29_10_ab_p <- as.numeric(brain.25_29.10_ab_anova[2,6])
brain.25_29.10.nullc <- nls(y ~ (a1*lcon1 + a2*lcon2) + exp((x - b)/(c1*ncon1 + c2*ncon2)), start = list(a1 = 20, a2 = 20, b = 1, c1 = 5, c2 = 5))
summary(brain.25_29.10.nullc)
anova(brain.25_29.10.alt, brain.25_29.10.nullc)
brain.25_29.10_ac_anova <- anova(brain.25_29.10.alt, brain.25_29.10.nullc)
brain.25_29_10_ac_p <- as.numeric(brain.25_29.10_ac_anova[2,6])
p_values <- data.frame(c(brain.25_29_10_ab_p, brain.25_29_10_ac_p))
parcomp<-within(parcomp,{
p.mixmod.adj=p.adjust(p.mixmod)
p.mixmod=round(p.mixmod,5)
p.linmod.adj=round(p.adjust(p.linmod),5)
p.linmod=round(p.linmod,5)
})
parcomp
```