OSCR

Distinct evolutionary trajectories of two integration centres, the central complex and mushroom bodies, across Heliconiini butterflies.

Code ↔ Paper

3 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 3 matches
  1. [1] § Materials and methods › Image processing, 3D segmentation, and annotation for fine-scale analysis ↔ Heliconiini-CX_SCRIPT.R, lines 2226–2307 · score 0.63 · bulb volume, ER neuron, metrics, quantified, segment, cell
  2. [2] § Results › GABA-ergic ER neurons increase in number, with increased innervation of the fan-shaped body in pollen feeders ↔ Heliconiini-CX_SCRIPT.R, lines 2226–2307 · score 0.63 · predict bulb, bulb volume, ER neuron, segmented, species, sex
  3. [3] § Results › Isolated impact of mushroom body expansion within the central complex, AOTU, and POTU circuit ↔ Heliconiini-CX_SCRIPT.R, lines 1–44 · score 0.54 · closer inspection, nested model, simplest, MCMCglmm, rCBR, sex

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

R · 2,308 lines · 87 KB · CC-BY-4.0 · 3 matches

  1. ##### PREREQUISITES #####
  2. rm(list=ls())
  3. library(tidyverse)
  4. library(ggpubr)
  5. library(phangorn)
  6. library(MCMCglmm)
  7. library(phytools)
  8. library(bbmle)
  9. library(MuMIn)
  10. library(plotly)
  11. library(ggbeeswarm)
  12. library(wesanderson)
  13. library(ggResidpanel)
  14. library(emmeans)
  15. ##### #SEX DIFFERENCES (FIGURE S1) #####
  16. setwd("C:/R-Analysis")
  17. cx.data=read.table(file="Hel-CX-MB_vs4.txt", sep="\t", header=TRUE)
  18. str(cx.data)
  19. #test whether pervasive sex differences exist that need closer inspection.
  20. #perform three different nested models, then compare their fit, to use the best fit and simplest to interpret.
  21. #TREE
  22. tree = read.nexus("Heliconiini.trees")
  23. tree=force.ultrametric(tree,method="nnls")
  24. plot(tree)
  25. inv.phylo=inverseA(tree,nodes="TIPS",scale=TRUE)
  26. ##MCMCglmm
  27. # set priors
  28. prior=list(G=list(G1=list(V=1,nu=0.02)),R=list(V=1,nu=0.02)) #standard priors as explored by SHM
  29. ## define models
  30. model.sexA=log10(Total.CX.woNO)~log10(rCBR)+SEX.mod
  31. ## run model
  32. model.sexA.1=MCMCglmm(model.sexA, random=~phylo, family=c("gaussian"),
  33. ginverse=list(phylo=inv.phylo$Ainv),
  34. prior=prior, data=cx.data,
  35. nitt=500000,burnin=10000,thin=500)
  36. ## run the model twice
  37. model.sexA.2=MCMCglmm(model.sexA, random=~phylo, family=c("gaussian"),
  38. ginverse=list(phylo=inv.phylo$Ainv),
  39. prior=prior, data=cx.data,
  40. nitt=500000,burnin=10000,thin=500)
  41. ##diagnostics
  42. ## convergence
  43. gelman.diag(mcmc.list(model.sexA.1$Sol,model.sexA.2$Sol))
  44. #good The test statistic is called the scale reduction factor. The closer this factor is to 1, the better the convergence of our chains. In practice, values below 1.1 can be acceptable and values below 1.02 are good.
  45. gelman.diag(mcmc.list(model.sexA.1$VCV,model.sexA.2$VCV))
  46. plot(mcmc.list(model.sexA.1$VCV,model.sexA.2$VCV))
  47. ## autocorrelation
  48. autocorr(model.sexA.1$Sol)
  49. autocorr(model.sexA.1$VCV)
  50. #alternative model B
  51. ## define models
  52. model.sexB=log10(Total.CX.woNO)~log10(rCBR)+SEX.mod+HelNonHel
  53. ## run model
  54. model.sexB.1=MCMCglmm(model.sexB, random=~phylo, family=c("gaussian"),
  55. ginverse=list(phylo=inv.phylo$Ainv),
  56. prior=prior, data=cx.data,
  57. nitt=500000,burnin=10000,thin=500)
  58. ## run the model twice
  59. model.sexB.2=MCMCglmm(model.sexB, random=~phylo, family=c("gaussian"),
  60. ginverse=list(phylo=inv.phylo$Ainv),
  61. prior=prior, data=cx.data,
  62. nitt=500000,burnin=10000,thin=500)
  63. ##diagnostics
  64. ## convergence
  65. gelman.diag(mcmc.list(model.sexB.1$Sol,model.sexB.2$Sol))
  66. #okay
  67. gelman.diag(mcmc.list(model.sexB.1$VCV,model.sexB.2$VCV))
  68. #okay? phylo a bit
  69. plot(mcmc.list(model.sexB.1$VCV,model.sexB.2$VCV))
  70. ## autocorrelation
  71. autocorr(model.sexB.1$Sol)
  72. autocorr(model.sexB.1$VCV)
  73. #alternative model C
  74. ## define models
  75. model.sexC=log10(Total.CX.woNO)~log10(rCBR)+SEX.mod*HelNonHel
  76. ## run model
  77. model.sexC.1=MCMCglmm(model.sexC, random=~phylo, family=c("gaussian"),
  78. ginverse=list(phylo=inv.phylo$Ainv),
  79. prior=prior, data=cx.data,
  80. nitt=500000,burnin=10000,thin=500)
  81. ## run the model twice
  82. model.sexC.2=MCMCglmm(model.sexC, random=~phylo, family=c("gaussian"),
  83. ginverse=list(phylo=inv.phylo$Ainv),
  84. prior=prior, data=cx.data,
  85. nitt=500000,burnin=10000,thin=500)
  86. ##diagnostics
  87. ## convergence
  88. gelman.diag(mcmc.list(model.sexC.1$Sol,model.sexC.2$Sol))
  89. gelman.diag(mcmc.list(model.sexC.1$VCV,model.sexC.2$VCV))
  90. plot(mcmc.list(model.sexC.1$VCV,model.sexC.2$VCV))
  91. ## autocorrelation
  92. autocorr(model.sexC.1$Sol)
  93. autocorr(model.sexC.1$VCV)
  94. #comparison of nested models.
  95. DIC(model.sexA.1)
  96. DIC(model.sexB.1)
  97. DIC(model.sexC.1)
  98. #differences are miniscule at best, hence its worth checking the model A still as its the simplest by far and performs similarly.
  99. summary(model.sexA.1)
  100. #p. val is indeed 0.031
  101. #plot
  102. log.rCBR=log10(cx.data$rCBR)
  103. log.CX=log10(cx.data$Total.CX.woNO)
  104. log.CBU=log10(cx.data$CBU)
  105. log.CBL=log10(cx.data$CBL)
  106. log.PB=log10(cx.data$PB)
  107. log.AOTU=log10(cx.data$AOTU)
  108. log.POTU=log10(cx.data$POTU)
  109. #add this to cx.data
  110. cx.data.log=cx.data %>%
  111. mutate(log.rCBR = log.rCBR,log.CX=log.CX,log.CBU=log.CBU,log.CBL=log.CBL,log.PB=log.PB,log.AOTU=log.AOTU,log.POTU=log.POTU)
  112. str(cx.data.log)
  113. sex.means=cx.data.log %>%
  114. group_by(SEX.mod) %>%
  115. summarise(log.rCBR = mean(log.rCBR),
  116. log.CX = mean(log.CX))
  117. sex.means
  118. cx.data.log$SEX.mod=factor(cx.data.log$SEX.mod,levels=
  119. c("male","female"))
  120. sex.CX.plot=ggplot(cx.data.log, aes(x=log.rCBR, y=log.CX, col=SEX.mod))+geom_point(alpha=0.3,size=4,stroke=NA)
  121. sex.CX.plot
  122. sex.CX.plot2=sex.CX.plot+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = element_line(colour = "black"))+
  123. scale_color_manual(values = c("#59A3A2","#F0884D"))
  124. sex.CX.plot2
  125. sex.CX.plot3=sex.CX.plot2+geom_point(data=sex.means, size = 5)
  126. sex.CX.plot3
  127. # illustrates that there might be sex diffs, particulary when combined with phylogeny, but the biological meaningfulness is limited.
  128. #see whether any substructures harbour sex effects more than others
  129. #PB
  130. sex.PB.plot=ggplot(cx.data, aes(x=log.rCBR, y=log.PB))+geom_point(aes(col=SEX.mod, size=3, alpha=0.5))
  131. sex.PB.plot
  132. sex.PB.plot2=sex.PB.plot+ theme_minimal()
  133. sex.PB.plot2
  134. #CBU
  135. sex.CBU.plot=ggplot(cx.data, aes(x=log.rCBR, y=log.CBU))+geom_point(aes(col=SEX.mod, size=3, alpha=0.5))
  136. sex.CBU.plot
  137. sex.CBU.plot2=sex.CBU.plot+ theme_minimal()
  138. sex.CBU.plot2
  139. #CBL
  140. sex.CBL.plot=ggplot(cx.data, aes(x=log.rCBR, y=log.CBL))+geom_point(aes(col=SEX.mod, size=3, alpha=0.5))
  141. sex.CBL.plot
  142. sex.CBL.plot2=sex.CBL.plot+ theme_minimal()
  143. sex.CBL.plot2
  144. #consistent sex effects here... can do posthoc tests but doesnt look too fascinating.
  145. #we conclude that for the CX, we include sex as control factor but not examine biological context more closely.
  146. #what about sex differences in terms of POTU and AOTU sizes?
  147. #AOTU
  148. #with new AOTU values
  149. ## define models
  150. model.sex.aotu.A=log10(AOTU)~log10(rCBR)+SEX.mod
  151. model.sex.aotu.B=log10(AOTU)~log10(rCBR)+SEX.mod+HelNonHel
  152. model.sex.aotu.C=log10(AOTU)~log10(rCBR)+SEX.mod*HelNonHel
  153. ## run models
  154. model.sex.aotu.A.1=MCMCglmm(model.sex.aotu.A, random=~phylo, family=c("gaussian"),
  155. ginverse=list(phylo=inv.phylo$Ainv),
  156. prior=prior, data=cx.data,
  157. nitt=500000,burnin=10000,thin=500)
  158. model.sex.aotu.B.1=MCMCglmm(model.sex.aotu.B, random=~phylo, family=c("gaussian"),
  159. ginverse=list(phylo=inv.phylo$Ainv),
  160. prior=prior, data=cx.data,
  161. nitt=500000,burnin=10000,thin=500)
  162. model.sex.aotu.C.1=MCMCglmm(model.sex.aotu.C, random=~phylo, family=c("gaussian"),
  163. ginverse=list(phylo=inv.phylo$Ainv),
  164. prior=prior, data=cx.data,
  165. nitt=500000,burnin=10000,thin=500)
  166. ## run the models twice
  167. ## run models
  168. model.sex.aotu.A.2=MCMCglmm(model.sex.aotu.A, random=~phylo, family=c("gaussian"),
  169. ginverse=list(phylo=inv.phylo$Ainv),
  170. prior=prior, data=cx.data,
  171. nitt=500000,burnin=10000,thin=500)
  172. model.sex.aotu.B.2=MCMCglmm(model.sex.aotu.B, random=~phylo, family=c("gaussian"),
  173. ginverse=list(phylo=inv.phylo$Ainv),
  174. prior=prior, data=cx.data,
  175. nitt=500000,burnin=10000,thin=500)
  176. model.sex.aotu.C.2=MCMCglmm(model.sex.aotu.C, random=~phylo, family=c("gaussian"),
  177. ginverse=list(phylo=inv.phylo$Ainv),
  178. prior=prior, data=cx.data,
  179. nitt=500000,burnin=10000,thin=500)
  180. ##diagnostics
  181. gelman.diag(mcmc.list(model.sex.aotu.A.1$Sol,model.sex.aotu.A.2$Sol))
  182. gelman.diag(mcmc.list(model.sex.aotu.A.1$VCV,model.sex.aotu.A.2$VCV))
  183. plot(mcmc.list(model.sex.aotu.A.1$VCV,model.sex.aotu.A.2$VCV))
  184. autocorr(model.sex.aotu.A.1$Sol)
  185. autocorr(model.sex.aotu.A.1$VCV)
  186. gelman.diag(mcmc.list(model.sex.aotu.B.1$Sol,model.sex.aotu.B.2$Sol))
  187. gelman.diag(mcmc.list(model.sex.aotu.B.1$VCV,model.sex.aotu.B.2$VCV))
  188. plot(mcmc.list(model.sex.aotu.B.1$VCV,model.sex.aotu.B.2$VCV))
  189. autocorr(model.sex.aotu.B.1$Sol)
  190. autocorr(model.sex.aotu.B.1$VCV)
  191. gelman.diag(mcmc.list(model.sex.aotu.C.1$Sol,model.sex.aotu.C.2$Sol))
  192. gelman.diag(mcmc.list(model.sex.aotu.C.1$VCV,model.sex.aotu.C.2$VCV))
  193. plot(mcmc.list(model.sex.aotu.C.1$VCV,model.sex.aotu.C.2$VCV))
  194. autocorr(model.sex.aotu.C.1$Sol)
  195. autocorr(model.sex.aotu.C.1$VCV)
  196. DIC(model.sex.aotu.A.1)
  197. DIC(model.sex.aotu.B.1)
  198. DIC(model.sex.aotu.C.1)
  199. #again simplest model.
  200. summary(model.sex.aotu.A.1)
  201. #highly signficiant.
  202. sex.means.aotu=cx.data.log %>%
  203. group_by(SEX.mod) %>%
  204. summarise(log.rCBR = mean(log.rCBR),
  205. log.AOTU = mean(log.AOTU))
  206. sex.means.aotu
  207. cx.data.log$SEX.mod=factor(cx.data.log$SEX.mod,levels=
  208. c("male","female"))
  209. sex.AOTU.plot=ggplot(cx.data.log, aes(x=log.rCBR, y=log.AOTU, col=SEX.mod))+geom_point(alpha=0.3,size=4,stroke=NA)
  210. sex.AOTU.plot
  211. sex.AOTU.plot2=sex.AOTU.plot+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = element_line(colour = "black"))+
  212. scale_color_manual(values = c("#59A3A2","#F0884D"))
  213. sex.AOTU.plot2
  214. sex.AOTU.plot3=sex.AOTU.plot2+geom_point(data=sex.means.aotu, size =5)
  215. sex.AOTU.plot3
  216. #POTU
  217. ## define models
  218. model.sex.potu.A=log10(POTU)~log10(rCBR)+SEX.mod
  219. model.sex.potu.B=log10(POTU)~log10(rCBR)+SEX.mod+HelNonHel
  220. model.sex.potu.C=log10(POTU)~log10(rCBR)+SEX.mod*HelNonHel
  221. ## run models
  222. model.sex.potu.A.1=MCMCglmm(model.sex.potu.A, random=~phylo, family=c("gaussian"),
  223. ginverse=list(phylo=inv.phylo$Ainv),
  224. prior=prior, data=cx.data,
  225. nitt=500000,burnin=10000,thin=500)
  226. model.sex.potu.B.1=MCMCglmm(model.sex.potu.B, random=~phylo, family=c("gaussian"),
  227. ginverse=list(phylo=inv.phylo$Ainv),
  228. prior=prior, data=cx.data,
  229. nitt=500000,burnin=10000,thin=500)
  230. model.sex.potu.C.1=MCMCglmm(model.sex.potu.C, random=~phylo, family=c("gaussian"),
  231. ginverse=list(phylo=inv.phylo$Ainv),
  232. prior=prior, data=cx.data,
  233. nitt=500000,burnin=10000,thin=500)
  234. ## run the models twice
  235. ## run models
  236. model.sex.potu.A.2=MCMCglmm(model.sex.potu.A, random=~phylo, family=c("gaussian"),
  237. ginverse=list(phylo=inv.phylo$Ainv),
  238. prior=prior, data=cx.data,
  239. nitt=500000,burnin=10000,thin=500)
  240. model.sex.potu.B.2=MCMCglmm(model.sex.potu.B, random=~phylo, family=c("gaussian"),
  241. ginverse=list(phylo=inv.phylo$Ainv),
  242. prior=prior, data=cx.data,
  243. nitt=500000,burnin=10000,thin=500)
  244. model.sex.potu.C.2=MCMCglmm(model.sex.potu.C, random=~phylo, family=c("gaussian"),
  245. ginverse=list(phylo=inv.phylo$Ainv),
  246. prior=prior, data=cx.data,
  247. nitt=500000,burnin=10000,thin=500)
  248. ##diagnostics
  249. gelman.diag(mcmc.list(model.sex.potu.A.1$Sol,model.sex.potu.A.2$Sol))
  250. gelman.diag(mcmc.list(model.sex.potu.A.1$VCV,model.sex.potu.A.2$VCV))
  251. plot(mcmc.list(model.sex.potu.A.1$VCV,model.sex.potu.A.2$VCV))
  252. autocorr(model.sex.potu.A.1$Sol)
  253. autocorr(model.sex.potu.A.1$VCV)
  254. gelman.diag(mcmc.list(model.sex.potu.B.1$Sol,model.sex.potu.B.2$Sol))
  255. gelman.diag(mcmc.list(model.sex.potu.B.1$VCV,model.sex.potu.B.2$VCV))
  256. plot(mcmc.list(model.sex.potu.B.1$VCV,model.sex.potu.B.2$VCV))
  257. autocorr(model.sex.potu.B.1$Sol)
  258. autocorr(model.sex.potu.B.1$VCV)
  259. gelman.diag(mcmc.list(model.sex.potu.C.1$Sol,model.sex.potu.C.2$Sol))
  260. gelman.diag(mcmc.list(model.sex.potu.C.1$VCV,model.sex.potu.C.2$VCV))
  261. plot(mcmc.list(model.sex.potu.C.1$VCV,model.sex.potu.C.2$VCV))
  262. autocorr(model.sex.potu.C.1$Sol)
  263. autocorr(model.sex.potu.C.1$VCV)
  264. DIC(model.sex.potu.A.1)
  265. DIC(model.sex.potu.B.1)
  266. DIC(model.sex.potu.C.1)
  267. #again simplest model.
  268. summary(model.sex.potu.A.1)
  269. #insignificant.
  270. sex.means.POTU=cx.data.log %>%
  271. group_by(SEX.mod) %>%
  272. summarise(log.rCBR = mean(log.rCBR),
  273. log.POTU = mean(log.POTU))
  274. sex.means.POTU
  275. cx.data.log$SEX.mod=factor(cx.data.log$SEX.mod,levels=
  276. c("male","female"))
  277. sex.POTU.plot=ggplot(cx.data.log, aes(x=log.rCBR, y=log.POTU, col=SEX.mod))+geom_point(alpha=0.3,size=4,stroke=NA)
  278. sex.POTU.plot
  279. sex.POTU.plot2=sex.POTU.plot+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = element_line(colour = "black"))+
  280. scale_color_manual(values = c("#59A3A2","#F0884D"))
  281. sex.POTU.plot2
  282. sex.POTU.plot3=sex.POTU.plot2+geom_point(data=sex.means.POTU, size = 5)
  283. sex.POTU.plot3
  284. sex.plot=ggarrange(sex.CX.plot3,sex.AOTU.plot3,sex.POTU.plot3,
  285. ncol = 3, nrow = 1,common.legend = TRUE, legend="bottom")
  286. sex.plot
  287. ##### CLADE DIFFERENCES (related to Figure 2 and S2) #####
  288. #number of individuals per species.
  289. count.data=cx.data %>% count(phylo)
  290. #TREE
  291. tree = read.nexus("Heliconiini.trees")
  292. tree=force.ultrametric(tree,method="nnls")
  293. plot(tree)
  294. inv.phylo=inverseA(tree,nodes="TIPS",scale=TRUE)
  295. ##MCMCglmm
  296. # set priors
  297. prior=list(G=list(G1=list(V=1,nu=0.02)),R=list(V=1,nu=0.02)) #standard priors as explored by SHM
  298. ## define model
  299. model.CX.total=log10(Total.CX.woNO)~log10(rCBR)+PollenF+SEX.mod
  300. ## run model
  301. model.CX.1=MCMCglmm(model.CX.total, random=~phylo, family=c("gaussian"),
  302. ginverse=list(phylo=inv.phylo$Ainv),
  303. prior=prior, data=cx.data,
  304. nitt=500000,burnin=10000,thin=500)
  305. ## run the model twice
  306. model.CX.2=MCMCglmm(model.CX.total, random=~phylo, family=c("gaussian"),
  307. ginverse=list(phylo=inv.phylo$Ainv),
  308. prior=prior, data=cx.data,
  309. nitt=500000,burnin=10000,thin=500)
  310. ##diagnostics
  311. ## convergence
  312. gelman.diag(mcmc.list(model.CX.1$Sol,model.CX.2$Sol))
  313. gelman.diag(mcmc.list(model.CX.1$VCV,model.CX.2$VCV))
  314. #random and fixed okay
  315. plot(mcmc.list(model.CX.1$VCV,model.CX.2$VCV))
  316. plot(mcmc.list(model.CX.1$Sol,model.CX.2$Sol))
  317. #all good.
  318. summary(model.CX.1)
  319. #non significant.
  320. model.AOTU=log10(AOTU)~log10(rCBR)+PollenF+SEX.mod
  321. model.AOTU.1=MCMCglmm(model.AOTU, random=~phylo, family=c("gaussian"),
  322. ginverse=list(phylo=inv.phylo$Ainv),
  323. prior=prior, data=cx.data,
  324. nitt=500000,burnin=10000,thin=500)
  325. ## run the model twice
  326. model.AOTU.2=MCMCglmm(model.AOTU, random=~phylo, family=c("gaussian"),
  327. ginverse=list(phylo=inv.phylo$Ainv),
  328. prior=prior, data=cx.data,
  329. nitt=500000,burnin=10000,thin=500)
  330. ##diagnostics
  331. ## convergence
  332. gelman.diag(mcmc.list(model.AOTU.1$Sol,model.AOTU.2$Sol))
  333. gelman.diag(mcmc.list(model.AOTU.1$VCV,model.AOTU.2$VCV))
  334. #random and fixed okay
  335. plot(mcmc.list(model.AOTU.1$VCV,model.AOTU.2$VCV))
  336. plot(mcmc.list(model.AOTU.1$Sol,model.AOTU.2$Sol))
  337. #all good.
  338. summary(model.AOTU.1)
  339. #insignificant.
  340. model.POTU=log10(POTU)~log10(rCBR)+PollenF+SEX.mod
  341. model.POTU.1=MCMCglmm(model.POTU, random=~phylo, family=c("gaussian"),
  342. ginverse=list(phylo=inv.phylo$Ainv),
  343. prior=prior, data=cx.data,
  344. nitt=500000,burnin=10000,thin=500)
  345. ## run the model twice
  346. model.POTU.2=MCMCglmm(model.POTU, random=~phylo, family=c("gaussian"),
  347. ginverse=list(phylo=inv.phylo$Ainv),
  348. prior=prior, data=cx.data,
  349. nitt=500000,burnin=10000,thin=500)
  350. ##diagnostics
  351. ## convergence
  352. gelman.diag(mcmc.list(model.POTU.1$Sol,model.POTU.2$Sol))
  353. gelman.diag(mcmc.list(model.POTU.1$VCV,model.POTU.2$VCV))
  354. #random and fixed okay
  355. plot(mcmc.list(model.POTU.1$VCV,model.POTU.2$VCV))
  356. plot(mcmc.list(model.POTU.1$Sol,model.POTU.2$Sol))
  357. #all good.
  358. summary(model.POTU.1)
  359. #insignificant.
  360. model.PB=log10(PB)~log10(rCBR)+PollenF+SEX.mod
  361. model.PB.1=MCMCglmm(model.PB, random=~phylo, family=c("gaussian"),
  362. ginverse=list(phylo=inv.phylo$Ainv),
  363. prior=prior, data=cx.data,
  364. nitt=500000,burnin=10000,thin=500)
  365. ## run the model twice
  366. model.PB.2=MCMCglmm(model.PB, random=~phylo, family=c("gaussian"),
  367. ginverse=list(phylo=inv.phylo$Ainv),
  368. prior=prior, data=cx.data,
  369. nitt=500000,burnin=10000,thin=500)
  370. ##diagnostics
  371. ## convergence
  372. gelman.diag(mcmc.list(model.PB.1$Sol,model.PB.2$Sol))
  373. gelman.diag(mcmc.list(model.PB.1$VCV,model.PB.2$VCV))
  374. #random and fixed okay
  375. plot(mcmc.list(model.PB.1$VCV,model.PB.2$VCV))
  376. plot(mcmc.list(model.PB.1$Sol,model.PB.2$Sol))
  377. #all good.
  378. summary(model.PB.1)
  379. #insignificant.
  380. model.CBL=log10(CBL)~log10(rCBR)+PollenF+SEX.mod
  381. model.CBL.1=MCMCglmm(model.CBL, random=~phylo, family=c("gaussian"),
  382. ginverse=list(phylo=inv.phylo$Ainv),
  383. prior=prior, data=cx.data,
  384. nitt=500000,burnin=10000,thin=500)
  385. ## run the model twice
  386. model.CBL.2=MCMCglmm(model.CBL, random=~phylo, family=c("gaussian"),
  387. ginverse=list(phylo=inv.phylo$Ainv),
  388. prior=prior, data=cx.data,
  389. nitt=500000,burnin=10000,thin=500)
  390. ##diagnostics
  391. ## convergence
  392. gelman.diag(mcmc.list(model.CBL.1$Sol,model.CBL.2$Sol))
  393. gelman.diag(mcmc.list(model.CBL.1$VCV,model.CBL.2$VCV))
  394. #random and fixed okay
  395. plot(mcmc.list(model.CBL.1$VCV,model.CBL.2$VCV))
  396. plot(mcmc.list(model.CBL.1$Sol,model.CBL.2$Sol))
  397. #all good.
  398. summary(model.CBL.1)
  399. #insignificant.
  400. model.CBU=log10(CBU)~log10(rCBR)+PollenF+SEX.mod
  401. model.CBU.1=MCMCglmm(model.CBU, random=~phylo, family=c("gaussian"),
  402. ginverse=list(phylo=inv.phylo$Ainv),
  403. prior=prior, data=cx.data,
  404. nitt=500000,burnin=10000,thin=500)
  405. ## run the model twice
  406. model.CBU.2=MCMCglmm(model.CBU, random=~phylo, family=c("gaussian"),
  407. ginverse=list(phylo=inv.phylo$Ainv),
  408. prior=prior, data=cx.data,
  409. nitt=500000,burnin=10000,thin=500)
  410. ##diagnostics
  411. ## convergence
  412. gelman.diag(mcmc.list(model.CBU.1$Sol,model.CBU.2$Sol))
  413. gelman.diag(mcmc.list(model.CBU.1$VCV,model.CBU.2$VCV))
  414. #random and fixed okay
  415. plot(mcmc.list(model.CBU.1$VCV,model.CBU.2$VCV))
  416. plot(mcmc.list(model.CBU.1$Sol,model.CBU.2$Sol))
  417. #all good.
  418. summary(model.CBU.1)
  419. #insignificant.
  420. model.NO=log10(NO)~log10(rCBR)+PollenF+SEX.mod
  421. model.NO.1=MCMCglmm(model.NO, random=~phylo, family=c("gaussian"),
  422. ginverse=list(phylo=inv.phylo$Ainv),
  423. prior=prior, data=cx.data,
  424. nitt=500000,burnin=10000,thin=500)
  425. ## run the model twice
  426. model.NO.2=MCMCglmm(model.NO, random=~phylo, family=c("gaussian"),
  427. ginverse=list(phylo=inv.phylo$Ainv),
  428. prior=prior, data=cx.data,
  429. nitt=500000,burnin=10000,thin=500)
  430. ##diagnostics
  431. ## convergence
  432. gelman.diag(mcmc.list(model.NO.1$Sol,model.NO.2$Sol))
  433. gelman.diag(mcmc.list(model.NO.1$VCV,model.NO.2$VCV))
  434. #random and fixed okay
  435. plot(mcmc.list(model.NO.1$VCV,model.NO.2$VCV))
  436. plot(mcmc.list(model.NO.1$Sol,model.NO.2$Sol))
  437. #all good.
  438. summary(model.NO.1)
  439. #insignificant.
  440. CX.plot=ggplot(cx.data, aes(x=log10(rCBR), y=log10(Total.CX.woNO),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  441. CX.plot
  442. CX.plot2=CX.plot+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  443. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  444. CX.plot2
  445. #ggplotly(CX.plot2)
  446. #speciesaverages.
  447. spec.avg=read.table(file="SpecAvg-plot_vs2.txt", sep="\t", header=TRUE)
  448. str(spec.avg)
  449. CX.plot3=CX.plot2+geom_point(data=spec.avg,size=5)
  450. CX.plot3
  451. AOTU.plot=ggplot(cx.data, aes(x=log10(rCBR), y=log10(AOTU),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  452. AOTU.plot
  453. AOTU.plot2=AOTU.plot+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  454. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  455. AOTU.plot2
  456. AOTU.plot3=AOTU.plot2+geom_point(data=spec.avg,size=5)
  457. AOTU.plot3
  458. POTU.plot=ggplot(cx.data, aes(x=log10(rCBR), y=log10(POTU),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  459. POTU.plot
  460. POTU.plot2=POTU.plot+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  461. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  462. POTU.plot2
  463. POTU.plot3=POTU.plot2+geom_point(data=spec.avg,size=5)
  464. POTU.plot3
  465. CBU.plot=ggplot(cx.data, aes(x=log10(rCBR), y=log10(CBU),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  466. CBU.plot
  467. CBU.plot2=CBU.plot+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  468. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  469. CBU.plot2
  470. CBU.plot3=CBU.plot2+geom_point(data=spec.avg,size=5)
  471. CBU.plot3
  472. CBL.plot=ggplot(cx.data, aes(x=log10(rCBR), y=log10(CBL),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  473. CBL.plot
  474. CBL.plot2=CBL.plot+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  475. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  476. CBL.plot2
  477. CBL.plot3=CBL.plot2+geom_point(data=spec.avg,size=5)
  478. CBL.plot3
  479. PB.plot=ggplot(cx.data, aes(x=log10(rCBR), y=log10(PB),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  480. PB.plot
  481. PB.plot2=PB.plot+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  482. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  483. PB.plot2
  484. PB.plot3=PB.plot2+geom_point(data=spec.avg,size=5)
  485. PB.plot3
  486. NO.data=subset(cx.data, NO >= 20)
  487. NO.data.avg=subset(spec.avg,NO >= 20)
  488. NO.plot=ggplot(NO.data, aes(x=log10(rCBR), y=log10(NO),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  489. NO.plot
  490. NO.plot2=NO.plot+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  491. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  492. NO.plot2
  493. NO.plot3=NO.plot2+geom_point(data=NO.data.avg,size=5)
  494. NO.plot3
  495. pollen.p1= ggarrange(PB.plot3,CBU.plot3, CBL.plot3 ,NO.plot3,
  496. ncol = 4, nrow = 1,common.legend = TRUE, legend="bottom" )
  497. pollen.p1
  498. pollen.p2=ggarrange(CX.plot3, AOTU.plot3, POTU.plot3,
  499. ncol = 3, nrow = 1,common.legend = TRUE, legend="bottom" )
  500. pollen.p2
  501. xplot=ggdensity(cx.data, "log10(rCBR)", fill = "Grp.color")+scale_fill_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))+clean_theme()
  502. xplot
  503. CX.yplot=ggdensity(cx.data, "log10(Total.CX.woNO)", fill = "Grp.color")+scale_fill_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))+coord_flip()+clean_theme()
  504. CX.yplot
  505. CX.plot.full=ggarrange(xplot, NULL, CX.plot3, CX.yplot,
  506. ncol = 2, nrow = 2, align = "hv",
  507. widths = c(2, 1), heights = c(1, 2),
  508. common.legend = TRUE)
  509. CX.plot.full
  510. ##### MB-CX co-evolution DIFFERENCES (related to Figure 2 and S2) #####
  511. #TREE
  512. tree = read.nexus("Heliconiini.trees")
  513. tree=force.ultrametric(tree,method="nnls")
  514. plot(tree)
  515. inv.phylo=inverseA(tree,nodes="TIPS",scale=TRUE)
  516. ##MCMCglmm
  517. # set priors
  518. prior=list(G=list(G1=list(V=1,nu=0.02)),R=list(V=1,nu=0.02)) #standard priors as explored by SHM
  519. #total CX
  520. ## define model
  521. model.CX.MB.PF=log10(Total.CX.woNO)~log10(rCBR)+log10(total.MB)*PollenF+SEX.mod
  522. ## run model
  523. model.CX.MB.PF.1=MCMCglmm(model.CX.MB.PF, random=~phylo, family=c("gaussian"),
  524. ginverse=list(phylo=inv.phylo$Ainv),
  525. prior=prior, data=cx.data,
  526. nitt=500000,burnin=10000,thin=500)
  527. ## run the model twice
  528. model.CX.MB.PF.2=MCMCglmm(model.CX.MB.PF, random=~phylo, family=c("gaussian"),
  529. ginverse=list(phylo=inv.phylo$Ainv),
  530. prior=prior, data=cx.data,
  531. nitt=500000,burnin=10000,thin=500)
  532. ##diagnostics
  533. ## convergence
  534. gelman.diag(mcmc.list(model.CX.MB.PF.1$Sol,model.CX.MB.PF.2$Sol))
  535. gelman.diag(mcmc.list(model.CX.MB.PF.1$VCV,model.CX.MB.PF.2$VCV))
  536. #random and fixed okay
  537. plot(mcmc.list(model.CX.MB.PF.1$VCV,model.CX.MB.PF.2$VCV))
  538. plot(mcmc.list(model.CX.MB.PF.1$Sol,model.CX.MB.PF.2$Sol))
  539. #all good.
  540. summary(model.CX.MB.PF.1)
  541. #MB and rCBR significant.
  542. model.CX.MB.PFn=log10(Total.CX.woNO)~log10(rCBR)+log10(total.MB)+PollenF+SEX.mod
  543. ## run model
  544. model.CX.MB.PFn.1=MCMCglmm(model.CX.MB.PFn, random=~phylo, family=c("gaussian"),
  545. ginverse=list(phylo=inv.phylo$Ainv),
  546. prior=prior, data=cx.data,
  547. nitt=500000,burnin=10000,thin=500)
  548. ## run the model twice
  549. model.CX.MB.PFn.2=MCMCglmm(model.CX.MB.PFn, random=~phylo, family=c("gaussian"),
  550. ginverse=list(phylo=inv.phylo$Ainv),
  551. prior=prior, data=cx.data,
  552. nitt=500000,burnin=10000,thin=500)
  553. ##diagnostics
  554. ## convergence
  555. gelman.diag(mcmc.list(model.CX.MB.PFn.1$Sol,model.CX.MB.PFn.2$Sol))
  556. gelman.diag(mcmc.list(model.CX.MB.PFn.1$VCV,model.CX.MB.PFn.2$VCV))
  557. #random and fixed okay
  558. plot(mcmc.list(model.CX.MB.PFn.1$VCV,model.CX.MB.PFn.2$VCV))
  559. plot(mcmc.list(model.CX.MB.PFn.1$Sol,model.CX.MB.PFn.2$Sol))
  560. #all good.
  561. DIC(model.CX.MB.PFn.1)
  562. DIC(model.CX.MB.PF.1)
  563. #very similar.
  564. sum.CX=summary(model.CX.MB.PF.1)
  565. sum.CX.output=sum.CX$solutions
  566. #total CX. clade effects.
  567. ## define model
  568. model.CX.MB.cl=log10(Total.CX.woNO)~log10(rCBR)+log10(total.MB)*Grp.color+SEX.mod
  569. ## run model
  570. model.CX.MB.cl.1=MCMCglmm(model.CX.MB.cl, random=~phylo, family=c("gaussian"),
  571. ginverse=list(phylo=inv.phylo$Ainv),
  572. prior=prior, data=cx.data,
  573. nitt=500000,burnin=10000,thin=500)
  574. ## run the model twice
  575. model.CX.MB.cl.2=MCMCglmm(model.CX.MB.cl, random=~phylo, family=c("gaussian"),
  576. ginverse=list(phylo=inv.phylo$Ainv),
  577. prior=prior, data=cx.data,
  578. nitt=500000,burnin=10000,thin=500)
  579. ##diagnostics
  580. ## convergence
  581. gelman.diag(mcmc.list(model.CX.MB.cl.1$Sol,model.CX.MB.cl.2$Sol))
  582. gelman.diag(mcmc.list(model.CX.MB.cl.1$VCV,model.CX.MB.cl.2$VCV))
  583. #random and fixed okay
  584. plot(mcmc.list(model.CX.MB.cl.1$VCV,model.CX.MB.cl.2$VCV))
  585. plot(mcmc.list(model.CX.MB.cl.1$Sol,model.CX.MB.cl.2$Sol))
  586. #all good.
  587. summary(model.CX.MB.cl.1)
  588. #MB and rCBR significant.
  589. #comparison to null model.
  590. model.CX.MB.cln=log10(Total.CX.woNO)~log10(rCBR)+log10(total.MB)+Grp.color+SEX.mod
  591. ## run model
  592. model.CX.MB.cln.1=MCMCglmm(model.CX.MB.cln, random=~phylo, family=c("gaussian"),
  593. ginverse=list(phylo=inv.phylo$Ainv),
  594. prior=prior, data=cx.data,
  595. nitt=500000,burnin=10000,thin=500)
  596. ## run the model twice
  597. model.CX.MB.cln.2=MCMCglmm(model.CX.MB.cln, random=~phylo, family=c("gaussian"),
  598. ginverse=list(phylo=inv.phylo$Ainv),
  599. prior=prior, data=cx.data,
  600. nitt=500000,burnin=10000,thin=500)
  601. ##diagnostics
  602. ## convergence
  603. gelman.diag(mcmc.list(model.CX.MB.cln.1$Sol,model.CX.MB.cln.2$Sol))
  604. gelman.diag(mcmc.list(model.CX.MB.cln.1$VCV,model.CX.MB.cln.2$VCV))
  605. #random and fixed okay
  606. plot(mcmc.list(model.CX.MB.cln.1$VCV,model.CX.MB.cln.2$VCV))
  607. plot(mcmc.list(model.CX.MB.cln.1$Sol,model.CX.MB.cln.2$Sol))
  608. DIC(model.CX.MB.cln.1)
  609. DIC(model.CX.MB.cl.1)
  610. #AOTU
  611. ## define model
  612. model.AOTU.MB.PF=log10(AOTU)~log10(rCBR)+log10(total.MB)*PollenF+SEX.mod
  613. ## run model
  614. model.AOTU.MB.PF.1=MCMCglmm(model.AOTU.MB.PF, random=~phylo, family=c("gaussian"),
  615. ginverse=list(phylo=inv.phylo$Ainv),
  616. prior=prior, data=cx.data,
  617. nitt=500000,burnin=10000,thin=500)
  618. ## run the model twice
  619. model.AOTU.MB.PF.2=MCMCglmm(model.AOTU.MB.PF, random=~phylo, family=c("gaussian"),
  620. ginverse=list(phylo=inv.phylo$Ainv),
  621. prior=prior, data=cx.data,
  622. nitt=500000,burnin=10000,thin=500)
  623. ##diagnostics
  624. ## convergence
  625. gelman.diag(mcmc.list(model.AOTU.MB.PF.1$Sol,model.AOTU.MB.PF.2$Sol))
  626. gelman.diag(mcmc.list(model.AOTU.MB.PF.1$VCV,model.AOTU.MB.PF.2$VCV))
  627. #random and fixed okay
  628. plot(mcmc.list(model.AOTU.MB.PF.1$VCV,model.AOTU.MB.PF.2$VCV))
  629. plot(mcmc.list(model.AOTU.MB.PF.1$Sol,model.AOTU.MB.PF.2$Sol))
  630. #all good.
  631. ## null model
  632. model.AOTU.MB.PFn=log10(AOTU)~log10(rCBR)+log10(total.MB)+PollenF+SEX.mod
  633. ## model
  634. model.AOTU.MB.PFn.1=MCMCglmm(model.AOTU.MB.PFn, random=~phylo, family=c("gaussian"),
  635. ginverse=list(phylo=inv.phylo$Ainv),
  636. prior=prior, data=cx.data,
  637. nitt=500000,burnin=10000,thin=500)
  638. ## run the model twice
  639. model.AOTU.MB.PFn.2=MCMCglmm(model.AOTU.MB.PFn, random=~phylo, family=c("gaussian"),
  640. ginverse=list(phylo=inv.phylo$Ainv),
  641. prior=prior, data=cx.data,
  642. nitt=500000,burnin=10000,thin=500)
  643. DIC(model.AOTU.MB.PF.1)
  644. DIC(model.AOTU.MB.PFn.1)
  645. summary(model.AOTU.MB.PF.1)
  646. #MB and rCBR significant.
  647. sum.aotu=summary(model.AOTU.MB.PF.1)
  648. sum.aotu.output=sum.aotu$solutions
  649. #clade diffs
  650. model.AOTU.MB.cl=log10(AOTU)~log10(rCBR)+log10(total.MB)*Grp.color+SEX.mod
  651. ## model
  652. model.AOTU.MB.cl.1=MCMCglmm(model.AOTU.MB.cl, random=~phylo, family=c("gaussian"),
  653. ginverse=list(phylo=inv.phylo$Ainv),
  654. prior=prior, data=cx.data,
  655. nitt=500000,burnin=10000,thin=500)
  656. ## run the model twice
  657. model.AOTU.MB.cl.2=MCMCglmm(model.AOTU.MB.cl, random=~phylo, family=c("gaussian"),
  658. ginverse=list(phylo=inv.phylo$Ainv),
  659. prior=prior, data=cx.data,
  660. nitt=500000,burnin=10000,thin=500)
  661. ##diagnostics
  662. ## convergence
  663. gelman.diag(mcmc.list(model.AOTU.MB.cl.1$Sol,model.AOTU.MB.cl.2$Sol))
  664. gelman.diag(mcmc.list(model.AOTU.MB.cl.1$VCV,model.AOTU.MB.cl.2$VCV))
  665. #random and fixed okay
  666. plot(mcmc.list(model.AOTU.MB.cl.1$VCV,model.AOTU.MB.cl.2$VCV))
  667. plot(mcmc.list(model.AOTU.MB.cl.1$Sol,model.AOTU.MB.cl.2$Sol))
  668. #all good.
  669. #null model
  670. model.AOTU.MB.cln=log10(AOTU)~log10(rCBR)+log10(total.MB)+Grp.color+SEX.mod
  671. ## model
  672. model.AOTU.MB.cln.1=MCMCglmm(model.AOTU.MB.cln, random=~phylo, family=c("gaussian"),
  673. ginverse=list(phylo=inv.phylo$Ainv),
  674. prior=prior, data=cx.data,
  675. nitt=500000,burnin=10000,thin=500)
  676. ## run the model twice
  677. model.AOTU.MB.cln.2=MCMCglmm(model.AOTU.MB.cln, random=~phylo, family=c("gaussian"),
  678. ginverse=list(phylo=inv.phylo$Ainv),
  679. prior=prior, data=cx.data,
  680. nitt=500000,burnin=10000,thin=500)
  681. DIC(model.AOTU.MB.cl.1)
  682. DIC(model.AOTU.MB.cln.1)
  683. summary(model.AOTU.MB.cl.1)
  684. #MB and rCBR significant.
  685. sum.aotu.cl=summary(model.AOTU.MB.cl.1)
  686. sum.aotu.cl.output=sum.aotu.cl$solutions
  687. #POTU
  688. ## define model
  689. model.POTU.MB.PF=log10(POTU)~log10(rCBR)+log10(total.MB)*PollenF+SEX.mod
  690. ## run model
  691. model.POTU.MB.PF.1=MCMCglmm(model.POTU.MB.PF, random=~phylo, family=c("gaussian"),
  692. ginverse=list(phylo=inv.phylo$Ainv),
  693. prior=prior, data=cx.data,
  694. nitt=500000,burnin=10000,thin=500)
  695. ## run the model twice
  696. model.POTU.MB.PF.2=MCMCglmm(model.POTU.MB.PF, random=~phylo, family=c("gaussian"),
  697. ginverse=list(phylo=inv.phylo$Ainv),
  698. prior=prior, data=cx.data,
  699. nitt=500000,burnin=10000,thin=500)
  700. ##diagnostics
  701. ## convergence
  702. gelman.diag(mcmc.list(model.POTU.MB.PF.1$Sol,model.POTU.MB.PF.2$Sol))
  703. gelman.diag(mcmc.list(model.POTU.MB.PF.1$VCV,model.POTU.MB.PF.2$VCV))
  704. #random and fixed okay
  705. plot(mcmc.list(model.POTU.MB.PF.1$VCV,model.POTU.MB.PF.2$VCV))
  706. plot(mcmc.list(model.POTU.MB.PF.1$Sol,model.POTU.MB.PF.2$Sol))
  707. #all good.
  708. ## null model
  709. model.POTU.MB.PFn=log10(POTU)~log10(rCBR)+log10(total.MB)+PollenF+SEX.mod
  710. ## model
  711. model.POTU.MB.PFn.1=MCMCglmm(model.POTU.MB.PFn, random=~phylo, family=c("gaussian"),
  712. ginverse=list(phylo=inv.phylo$Ainv),
  713. prior=prior, data=cx.data,
  714. nitt=500000,burnin=10000,thin=500)
  715. ## run the model twice
  716. model.POTU.MB.PFn.2=MCMCglmm(model.POTU.MB.PFn, random=~phylo, family=c("gaussian"),
  717. ginverse=list(phylo=inv.phylo$Ainv),
  718. prior=prior, data=cx.data,
  719. nitt=500000,burnin=10000,thin=500)
  720. DIC(model.POTU.MB.PF.1)
  721. DIC(model.POTU.MB.PFn.1)
  722. summary(model.POTU.MB.PF.1)
  723. #MB and rCBR significant.
  724. sum.POTU=summary(model.POTU.MB.PF.1)
  725. sum.POTU.output=sum.POTU$solutions
  726. #clade diffs
  727. model.POTU.MB.cl=log10(POTU)~log10(rCBR)+log10(total.MB)*Grp.color+SEX.mod
  728. ## model
  729. model.POTU.MB.cl.1=MCMCglmm(model.POTU.MB.cl, random=~phylo, family=c("gaussian"),
  730. ginverse=list(phylo=inv.phylo$Ainv),
  731. prior=prior, data=cx.data,
  732. nitt=500000,burnin=10000,thin=500)
  733. ## run the model twice
  734. model.POTU.MB.cl.2=MCMCglmm(model.POTU.MB.cl, random=~phylo, family=c("gaussian"),
  735. ginverse=list(phylo=inv.phylo$Ainv),
  736. prior=prior, data=cx.data,
  737. nitt=500000,burnin=10000,thin=500)
  738. ##diagnostics
  739. ## convergence
  740. gelman.diag(mcmc.list(model.POTU.MB.cl.1$Sol,model.POTU.MB.cl.2$Sol))
  741. gelman.diag(mcmc.list(model.POTU.MB.cl.1$VCV,model.POTU.MB.cl.2$VCV))
  742. #random and fixed okay
  743. plot(mcmc.list(model.POTU.MB.cl.1$VCV,model.POTU.MB.cl.2$VCV))
  744. plot(mcmc.list(model.POTU.MB.cl.1$Sol,model.POTU.MB.cl.2$Sol))
  745. #all good.
  746. #null model
  747. model.POTU.MB.cln=log10(POTU)~log10(rCBR)+log10(total.MB)+Grp.color+SEX.mod
  748. ## model
  749. model.POTU.MB.cln.1=MCMCglmm(model.POTU.MB.cln, random=~phylo, family=c("gaussian"),
  750. ginverse=list(phylo=inv.phylo$Ainv),
  751. prior=prior, data=cx.data,
  752. nitt=500000,burnin=10000,thin=500)
  753. ## run the model twice
  754. model.POTU.MB.cln.2=MCMCglmm(model.POTU.MB.cln, random=~phylo, family=c("gaussian"),
  755. ginverse=list(phylo=inv.phylo$Ainv),
  756. prior=prior, data=cx.data,
  757. nitt=500000,burnin=10000,thin=500)
  758. DIC(model.POTU.MB.cl.1)
  759. DIC(model.POTU.MB.cln.1)
  760. summary(model.POTU.MB.cl.1)
  761. #MB and rCBR significant.
  762. sum.POTU.cl=summary(model.POTU.MB.cl.1)
  763. sum.POTU.cl.output=sum.POTU.cl$solutions
  764. #CBU
  765. ## define model
  766. model.CBU.MB.PF=log10(CBU)~log10(rCBR)+log10(total.MB)*PollenF+SEX.mod
  767. ## run model
  768. model.CBU.MB.PF.1=MCMCglmm(model.CBU.MB.PF, random=~phylo, family=c("gaussian"),
  769. ginverse=list(phylo=inv.phylo$Ainv),
  770. prior=prior, data=cx.data,
  771. nitt=500000,burnin=10000,thin=500)
  772. ## run the model twice
  773. model.CBU.MB.PF.2=MCMCglmm(model.CBU.MB.PF, random=~phylo, family=c("gaussian"),
  774. ginverse=list(phylo=inv.phylo$Ainv),
  775. prior=prior, data=cx.data,
  776. nitt=500000,burnin=10000,thin=500)
  777. ##diagnostics
  778. ## convergence
  779. gelman.diag(mcmc.list(model.CBU.MB.PF.1$Sol,model.CBU.MB.PF.2$Sol))
  780. gelman.diag(mcmc.list(model.CBU.MB.PF.1$VCV,model.CBU.MB.PF.2$VCV))
  781. #random and fixed okay
  782. plot(mcmc.list(model.CBU.MB.PF.1$VCV,model.CBU.MB.PF.2$VCV))
  783. plot(mcmc.list(model.CBU.MB.PF.1$Sol,model.CBU.MB.PF.2$Sol))
  784. #all good.
  785. ## null model
  786. model.CBU.MB.PFn=log10(CBU)~log10(rCBR)+log10(total.MB)+PollenF+SEX.mod
  787. ## model
  788. model.CBU.MB.PFn.1=MCMCglmm(model.CBU.MB.PFn, random=~phylo, family=c("gaussian"),
  789. ginverse=list(phylo=inv.phylo$Ainv),
  790. prior=prior, data=cx.data,
  791. nitt=500000,burnin=10000,thin=500)
  792. ## run the model twice
  793. model.CBU.MB.PFn.2=MCMCglmm(model.CBU.MB.PFn, random=~phylo, family=c("gaussian"),
  794. ginverse=list(phylo=inv.phylo$Ainv),
  795. prior=prior, data=cx.data,
  796. nitt=500000,burnin=10000,thin=500)
  797. DIC(model.CBU.MB.PF.1)
  798. DIC(model.CBU.MB.PFn.1)
  799. summary(model.CBU.MB.PF.1)
  800. #MB and rCBR significant.
  801. sum.CBU=summary(model.CBU.MB.PF.1)
  802. sum.CBU.output=sum.CBU$solutions
  803. #clade diffs
  804. model.CBU.MB.cl=log10(CBU)~log10(rCBR)+log10(total.MB)*Grp.color+SEX.mod
  805. ## model
  806. model.CBU.MB.cl.1=MCMCglmm(model.CBU.MB.cl, random=~phylo, family=c("gaussian"),
  807. ginverse=list(phylo=inv.phylo$Ainv),
  808. prior=prior, data=cx.data,
  809. nitt=500000,burnin=10000,thin=500)
  810. ## run the model twice
  811. model.CBU.MB.cl.2=MCMCglmm(model.CBU.MB.cl, random=~phylo, family=c("gaussian"),
  812. ginverse=list(phylo=inv.phylo$Ainv),
  813. prior=prior, data=cx.data,
  814. nitt=500000,burnin=10000,thin=500)
  815. ##diagnostics
  816. ## convergence
  817. gelman.diag(mcmc.list(model.CBU.MB.cl.1$Sol,model.CBU.MB.cl.2$Sol))
  818. gelman.diag(mcmc.list(model.CBU.MB.cl.1$VCV,model.CBU.MB.cl.2$VCV))
  819. #random and fixed okay
  820. plot(mcmc.list(model.CBU.MB.cl.1$VCV,model.CBU.MB.cl.2$VCV))
  821. plot(mcmc.list(model.CBU.MB.cl.1$Sol,model.CBU.MB.cl.2$Sol))
  822. #all good.
  823. #null model
  824. model.CBU.MB.cln=log10(CBU)~log10(rCBR)+log10(total.MB)+Grp.color+SEX.mod
  825. ## model
  826. model.CBU.MB.cln.1=MCMCglmm(model.CBU.MB.cln, random=~phylo, family=c("gaussian"),
  827. ginverse=list(phylo=inv.phylo$Ainv),
  828. prior=prior, data=cx.data,
  829. nitt=500000,burnin=10000,thin=500)
  830. ## run the model twice
  831. model.CBU.MB.cln.2=MCMCglmm(model.CBU.MB.cln, random=~phylo, family=c("gaussian"),
  832. ginverse=list(phylo=inv.phylo$Ainv),
  833. prior=prior, data=cx.data,
  834. nitt=500000,burnin=10000,thin=500)
  835. DIC(model.CBU.MB.cl.1)
  836. DIC(model.CBU.MB.cln.1)
  837. summary(model.CBU.MB.cl.1)
  838. #MB and rCBR significant.
  839. sum.CBU.cl=summary(model.CBU.MB.cl.1)
  840. sum.CBU.cl.output=sum.CBU.cl$solutions
  841. #CBL
  842. ## define model
  843. model.CBL.MB.PF=log10(CBL)~log10(rCBR)+log10(total.MB)*PollenF+SEX.mod
  844. ## run model
  845. model.CBL.MB.PF.1=MCMCglmm(model.CBL.MB.PF, random=~phylo, family=c("gaussian"),
  846. ginverse=list(phylo=inv.phylo$Ainv),
  847. prior=prior, data=cx.data,
  848. nitt=500000,burnin=10000,thin=500)
  849. ## run the model twice
  850. model.CBL.MB.PF.2=MCMCglmm(model.CBL.MB.PF, random=~phylo, family=c("gaussian"),
  851. ginverse=list(phylo=inv.phylo$Ainv),
  852. prior=prior, data=cx.data,
  853. nitt=500000,burnin=10000,thin=500)
  854. ##diagnostics
  855. ## convergence
  856. gelman.diag(mcmc.list(model.CBL.MB.PF.1$Sol,model.CBL.MB.PF.2$Sol))
  857. gelman.diag(mcmc.list(model.CBL.MB.PF.1$VCV,model.CBL.MB.PF.2$VCV))
  858. #random and fixed okay
  859. plot(mcmc.list(model.CBL.MB.PF.1$VCV,model.CBL.MB.PF.2$VCV))
  860. plot(mcmc.list(model.CBL.MB.PF.1$Sol,model.CBL.MB.PF.2$Sol))
  861. #all good.
  862. ## null model
  863. model.CBL.MB.PFn=log10(CBL)~log10(rCBR)+log10(total.MB)+PollenF+SEX.mod
  864. ## model
  865. model.CBL.MB.PFn.1=MCMCglmm(model.CBL.MB.PFn, random=~phylo, family=c("gaussian"),
  866. ginverse=list(phylo=inv.phylo$Ainv),
  867. prior=prior, data=cx.data,
  868. nitt=500000,burnin=10000,thin=500)
  869. ## run the model twice
  870. model.CBL.MB.PFn.2=MCMCglmm(model.CBL.MB.PFn, random=~phylo, family=c("gaussian"),
  871. ginverse=list(phylo=inv.phylo$Ainv),
  872. prior=prior, data=cx.data,
  873. nitt=500000,burnin=10000,thin=500)
  874. DIC(model.CBL.MB.PF.1)
  875. DIC(model.CBL.MB.PFn.1)
  876. summary(model.CBL.MB.PF.1)
  877. #MB and rCBR significant.
  878. sum.CBL=summary(model.CBL.MB.PF.1)
  879. sum.CBL.output=sum.CBL$solutions
  880. #clade diffs
  881. model.CBL.MB.cl=log10(CBL)~log10(rCBR)+log10(total.MB)*Grp.color+SEX.mod
  882. ## model
  883. model.CBL.MB.cl.1=MCMCglmm(model.CBL.MB.cl, random=~phylo, family=c("gaussian"),
  884. ginverse=list(phylo=inv.phylo$Ainv),
  885. prior=prior, data=cx.data,
  886. nitt=500000,burnin=10000,thin=500)
  887. ## run the model twice
  888. model.CBL.MB.cl.2=MCMCglmm(model.CBL.MB.cl, random=~phylo, family=c("gaussian"),
  889. ginverse=list(phylo=inv.phylo$Ainv),
  890. prior=prior, data=cx.data,
  891. nitt=500000,burnin=10000,thin=500)
  892. ##diagnostics
  893. ## convergence
  894. gelman.diag(mcmc.list(model.CBL.MB.cl.1$Sol,model.CBL.MB.cl.2$Sol))
  895. gelman.diag(mcmc.list(model.CBL.MB.cl.1$VCV,model.CBL.MB.cl.2$VCV))
  896. #random and fixed okay
  897. plot(mcmc.list(model.CBL.MB.cl.1$VCV,model.CBL.MB.cl.2$VCV))
  898. plot(mcmc.list(model.CBL.MB.cl.1$Sol,model.CBL.MB.cl.2$Sol))
  899. #all good.
  900. #null model
  901. model.CBL.MB.cln=log10(CBL)~log10(rCBR)+log10(total.MB)+Grp.color+SEX.mod
  902. ## model
  903. model.CBL.MB.cln.1=MCMCglmm(model.CBL.MB.cln, random=~phylo, family=c("gaussian"),
  904. ginverse=list(phylo=inv.phylo$Ainv),
  905. prior=prior, data=cx.data,
  906. nitt=500000,burnin=10000,thin=500)
  907. ## run the model twice
  908. model.CBL.MB.cln.2=MCMCglmm(model.CBL.MB.cln, random=~phylo, family=c("gaussian"),
  909. ginverse=list(phylo=inv.phylo$Ainv),
  910. prior=prior, data=cx.data,
  911. nitt=500000,burnin=10000,thin=500)
  912. DIC(model.CBL.MB.cl.1)
  913. DIC(model.CBL.MB.cln.1)
  914. summary(model.CBL.MB.cl.1)
  915. #MB and rCBR significant.
  916. sum.CBL.cl=summary(model.CBL.MB.cl.1)
  917. sum.CBL.cl.output=sum.CBL.cl$solutions
  918. #PB
  919. ## define model
  920. model.PB.MB.PF=log10(PB)~log10(rCBR)+log10(total.MB)*PollenF+SEX.mod
  921. ## run model
  922. model.PB.MB.PF.1=MCMCglmm(model.PB.MB.PF, random=~phylo, family=c("gaussian"),
  923. ginverse=list(phylo=inv.phylo$Ainv),
  924. prior=prior, data=cx.data,
  925. nitt=500000,burnin=10000,thin=500)
  926. ## run the model twice
  927. model.PB.MB.PF.2=MCMCglmm(model.PB.MB.PF, random=~phylo, family=c("gaussian"),
  928. ginverse=list(phylo=inv.phylo$Ainv),
  929. prior=prior, data=cx.data,
  930. nitt=500000,burnin=10000,thin=500)
  931. ##diagnostics
  932. ## convergence
  933. gelman.diag(mcmc.list(model.PB.MB.PF.1$Sol,model.PB.MB.PF.2$Sol))
  934. gelman.diag(mcmc.list(model.PB.MB.PF.1$VCV,model.PB.MB.PF.2$VCV))
  935. #random and fixed okay
  936. plot(mcmc.list(model.PB.MB.PF.1$VCV,model.PB.MB.PF.2$VCV))
  937. plot(mcmc.list(model.PB.MB.PF.1$Sol,model.PB.MB.PF.2$Sol))
  938. #all good.
  939. ## null model
  940. model.PB.MB.PFn=log10(PB)~log10(rCBR)+log10(total.MB)+PollenF+SEX.mod
  941. ## model
  942. model.PB.MB.PFn.1=MCMCglmm(model.PB.MB.PFn, random=~phylo, family=c("gaussian"),
  943. ginverse=list(phylo=inv.phylo$Ainv),
  944. prior=prior, data=cx.data,
  945. nitt=500000,burnin=10000,thin=500)
  946. ## run the model twice
  947. model.PB.MB.PFn.2=MCMCglmm(model.PB.MB.PFn, random=~phylo, family=c("gaussian"),
  948. ginverse=list(phylo=inv.phylo$Ainv),
  949. prior=prior, data=cx.data,
  950. nitt=500000,burnin=10000,thin=500)
  951. DIC(model.PB.MB.PF.1)
  952. DIC(model.PB.MB.PFn.1)
  953. summary(model.PB.MB.PF.1)
  954. #MB and rCBR significant.
  955. sum.PB=summary(model.PB.MB.PF.1)
  956. sum.PB.output=sum.PB$solutions
  957. #clade diffs
  958. model.PB.MB.cl=log10(PB)~log10(rCBR)+log10(total.MB)*Grp.color+SEX.mod
  959. ## model
  960. model.PB.MB.cl.1=MCMCglmm(model.PB.MB.cl, random=~phylo, family=c("gaussian"),
  961. ginverse=list(phylo=inv.phylo$Ainv),
  962. prior=prior, data=cx.data,
  963. nitt=500000,burnin=10000,thin=500)
  964. ## run the model twice
  965. model.PB.MB.cl.2=MCMCglmm(model.PB.MB.cl, random=~phylo, family=c("gaussian"),
  966. ginverse=list(phylo=inv.phylo$Ainv),
  967. prior=prior, data=cx.data,
  968. nitt=500000,burnin=10000,thin=500)
  969. ##diagnostics
  970. ## convergence
  971. gelman.diag(mcmc.list(model.PB.MB.cl.1$Sol,model.PB.MB.cl.2$Sol))
  972. gelman.diag(mcmc.list(model.PB.MB.cl.1$VCV,model.PB.MB.cl.2$VCV))
  973. #random and fixed okay
  974. plot(mcmc.list(model.PB.MB.cl.1$VCV,model.PB.MB.cl.2$VCV))
  975. plot(mcmc.list(model.PB.MB.cl.1$Sol,model.PB.MB.cl.2$Sol))
  976. #all good.
  977. #null model
  978. model.PB.MB.cln=log10(PB)~log10(rCBR)+log10(total.MB)+Grp.color+SEX.mod
  979. ## model
  980. model.PB.MB.cln.1=MCMCglmm(model.PB.MB.cln, random=~phylo, family=c("gaussian"),
  981. ginverse=list(phylo=inv.phylo$Ainv),
  982. prior=prior, data=cx.data,
  983. nitt=500000,burnin=10000,thin=500)
  984. ## run the model twice
  985. model.PB.MB.cln.2=MCMCglmm(model.PB.MB.cln, random=~phylo, family=c("gaussian"),
  986. ginverse=list(phylo=inv.phylo$Ainv),
  987. prior=prior, data=cx.data,
  988. nitt=500000,burnin=10000,thin=500)
  989. DIC(model.PB.MB.cl.1)
  990. DIC(model.PB.MB.cln.1)
  991. summary(model.PB.MB.cl.1)
  992. #MB and rCBR significant.
  993. sum.PB.cl=summary(model.PB.MB.cl.1)
  994. sum.PB.cl.output=sum.PB.cl$solutions
  995. #NO
  996. ## define model
  997. model.NO.MB.PF=log10(NO)~log10(rCBR)+log10(total.MB)*PollenF+SEX.mod
  998. ## run model
  999. model.NO.MB.PF.1=MCMCglmm(model.NO.MB.PF, random=~phylo, family=c("gaussian"),
  1000. ginverse=list(phylo=inv.phylo$Ainv),
  1001. prior=prior, data=cx.data,
  1002. nitt=500000,burnin=10000,thin=500)
  1003. ## run the model twice
  1004. model.NO.MB.PF.2=MCMCglmm(model.NO.MB.PF, random=~phylo, family=c("gaussian"),
  1005. ginverse=list(phylo=inv.phylo$Ainv),
  1006. prior=prior, data=cx.data,
  1007. nitt=500000,burnin=10000,thin=500)
  1008. ##diagnostics
  1009. ## convergence
  1010. gelman.diag(mcmc.list(model.NO.MB.PF.1$Sol,model.NO.MB.PF.2$Sol))
  1011. gelman.diag(mcmc.list(model.NO.MB.PF.1$VCV,model.NO.MB.PF.2$VCV))
  1012. #random and fixed okay
  1013. plot(mcmc.list(model.NO.MB.PF.1$VCV,model.NO.MB.PF.2$VCV))
  1014. plot(mcmc.list(model.NO.MB.PF.1$Sol,model.NO.MB.PF.2$Sol))
  1015. #all good.
  1016. ## null model
  1017. model.NO.MB.PFn=log10(NO)~log10(rCBR)+log10(total.MB)+PollenF+SEX.mod
  1018. ## model
  1019. model.NO.MB.PFn.1=MCMCglmm(model.NO.MB.PFn, random=~phylo, family=c("gaussian"),
  1020. ginverse=list(phylo=inv.phylo$Ainv),
  1021. prior=prior, data=cx.data,
  1022. nitt=500000,burnin=10000,thin=500)
  1023. ## run the model twice
  1024. model.NO.MB.PFn.2=MCMCglmm(model.NO.MB.PFn, random=~phylo, family=c("gaussian"),
  1025. ginverse=list(phylo=inv.phylo$Ainv),
  1026. prior=prior, data=cx.data,
  1027. nitt=500000,burnin=10000,thin=500)
  1028. DIC(model.NO.MB.PF.1)
  1029. DIC(model.NO.MB.PFn.1)
  1030. summary(model.NO.MB.PF.1)
  1031. #MB and rCBR significant.
  1032. sum.NO=summary(model.NO.MB.PF.1)
  1033. sum.NO.output=sum.NO$solutions
  1034. #clade diffs
  1035. model.NO.MB.cl=log10(NO)~log10(rCBR)+log10(total.MB)*Grp.color+SEX.mod
  1036. ## model
  1037. model.NO.MB.cl.1=MCMCglmm(model.NO.MB.cl, random=~phylo, family=c("gaussian"),
  1038. ginverse=list(phylo=inv.phylo$Ainv),
  1039. prior=prior, data=cx.data,
  1040. nitt=500000,burnin=10000,thin=500)
  1041. ## run the model twice
  1042. model.NO.MB.cl.2=MCMCglmm(model.NO.MB.cl, random=~phylo, family=c("gaussian"),
  1043. ginverse=list(phylo=inv.phylo$Ainv),
  1044. prior=prior, data=cx.data,
  1045. nitt=500000,burnin=10000,thin=500)
  1046. ##diagnostics
  1047. ## convergence
  1048. gelman.diag(mcmc.list(model.NO.MB.cl.1$Sol,model.NO.MB.cl.2$Sol))
  1049. gelman.diag(mcmc.list(model.NO.MB.cl.1$VCV,model.NO.MB.cl.2$VCV))
  1050. #random and fixed okay
  1051. plot(mcmc.list(model.NO.MB.cl.1$VCV,model.NO.MB.cl.2$VCV))
  1052. plot(mcmc.list(model.NO.MB.cl.1$Sol,model.NO.MB.cl.2$Sol))
  1053. #all good.
  1054. #null model
  1055. model.NO.MB.cln=log10(NO)~log10(rCBR)+log10(total.MB)+Grp.color+SEX.mod
  1056. ## model
  1057. model.NO.MB.cln.1=MCMCglmm(model.NO.MB.cln, random=~phylo, family=c("gaussian"),
  1058. ginverse=list(phylo=inv.phylo$Ainv),
  1059. prior=prior, data=cx.data,
  1060. nitt=500000,burnin=10000,thin=500)
  1061. ## run the model twice
  1062. model.NO.MB.cln.2=MCMCglmm(model.NO.MB.cln, random=~phylo, family=c("gaussian"),
  1063. ginverse=list(phylo=inv.phylo$Ainv),
  1064. prior=prior, data=cx.data,
  1065. nitt=500000,burnin=10000,thin=500)
  1066. DIC(model.NO.MB.cl.1)
  1067. DIC(model.NO.MB.cln.1)
  1068. summary(model.NO.MB.cl.1)
  1069. #MB and rCBR significant.
  1070. sum.NO.cl=summary(model.NO.MB.cl.1)
  1071. sum.NO.cl.output=sum.NO.cl$solutions
  1072. #plotting
  1073. CX.plot.MB=ggplot(cx.data, aes(x=log10(total.MB), y=log10(Total.CX.woNO),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  1074. CX.plot.MB
  1075. CX.plot.MB.2=CX.plot.MB+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  1076. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  1077. CX.plot.MB.2
  1078. #ggplotly(CX.plot2)
  1079. #speciesaverages.
  1080. spec.avg=read.table(file="SpecAvg-plot.txt", sep="\t", header=TRUE)
  1081. str(spec.avg)
  1082. CX.plot.MB.3=CX.plot.MB.2+geom_point(data=spec.avg,size=5)
  1083. CX.plot.MB.3
  1084. AOTU.plot.MB=ggplot(cx.data, aes(x=log10(total.MB), y=log10(AOTU),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  1085. AOTU.plot.MB
  1086. AOTU.plot.MB.2=AOTU.plot.MB+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  1087. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  1088. AOTU.plot.MB.2
  1089. AOTU.plot.MB.3=AOTU.plot.MB.2+geom_point(data=spec.avg,size=5)
  1090. AOTU.plot.MB.3
  1091. POTU.plot.MB=ggplot(cx.data, aes(x=log10(total.MB), y=log10(POTU),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  1092. POTU.plot.MB
  1093. POTU.plot.MB.2=POTU.plot.MB+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  1094. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  1095. POTU.plot.MB.2
  1096. POTU.plot.MB.3=POTU.plot.MB.2+geom_point(data=spec.avg,size=5)
  1097. POTU.plot.MB.3
  1098. CBU.plot.MB=ggplot(cx.data, aes(x=log10(total.MB), y=log10(CBU),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  1099. CBU.plot.MB
  1100. CBU.plot.MB.2=CBU.plot.MB+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  1101. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  1102. CBU.plot.MB.2
  1103. CBU.plot.MB.3=CBU.plot.MB.2+geom_point(data=spec.avg,size=5)
  1104. CBU.plot.MB.3
  1105. CBL.plot.MB=ggplot(cx.data, aes(x=log10(total.MB), y=log10(CBL),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  1106. CBL.plot.MB
  1107. CBL.plot.MB.2=CBL.plot.MB+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  1108. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  1109. CBL.plot.MB.2
  1110. CBL.plot.MB.3=CBL.plot.MB.2+geom_point(data=spec.avg,size=5)
  1111. CBL.plot.MB.3
  1112. PB.plot.MB=ggplot(cx.data, aes(x=log10(total.MB), y=log10(PB),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  1113. PB.plot.MB
  1114. PB.plot.MB.2=PB.plot.MB+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  1115. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  1116. PB.plot.MB.2
  1117. PB.plot.MB.3=PB.plot.MB.2+geom_point(data=spec.avg,size=5)
  1118. PB.plot.MB.3
  1119. NO.data=subset(cx.data, NO >= 20)
  1120. NO.data.avg=subset(spec.avg,NO >= 20)
  1121. NO.plot.MB=ggplot(NO.data, aes(x=log10(total.MB), y=log10(NO),col=Grp.color,size=2.5))+geom_point(alpha=0.3,stroke=NA)
  1122. NO.plot.MB
  1123. NO.plot.MB.2=NO.plot.MB+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  1124. panel.background = element_blank(), axis.line = element_line(colour = "black"))+scale_colour_manual(values = c("#7d9c2c","#84478e", "#c64f37","#ed6d26","#1a90b3"))
  1125. NO.plot.MB.2
  1126. NO.plot.MB.3=NO.plot.MB.2+geom_point(data=NO.data.avg,size=5)
  1127. NO.plot.MB.3
  1128. pollen.MB.p1= ggarrange(PB.plot.MB.3,CBU.plot.MB.3, CBL.plot.MB.3 ,NO.plot.MB.3,
  1129. ncol = 4, nrow = 1,common.legend = TRUE, legend="bottom" )
  1130. pollen.MB.p1
  1131. pollen.MB.p2=ggarrange(CX.plot.MB.3, AOTU.plot.MB.3, POTU.plot.MB.3,
  1132. ncol = 3, nrow = 1,common.legend = TRUE, legend="bottom" )
  1133. pollen.MB.p2
  1134. #single pair models.
  1135. #TREE
  1136. tree = read.nexus("Heliconiini.trees")
  1137. tree=force.ultrametric(tree,method="nnls")
  1138. plot(tree)
  1139. inv.phylo=inverseA(tree,nodes="TIPS",scale=TRUE)
  1140. ##MCMCglmm
  1141. # set priors
  1142. prior=list(G=list(G1=list(V=1,nu=0.02)),R=list(V=1,nu=0.02)) #standard priors as explored by SHM
  1143. #CBU tNO
  1144. ## define model
  1145. model.NO.CBU=log10(NO)~log10(rCBR)+log10(CBU)*PollenF+SEX.mod
  1146. ## run model
  1147. model.NO.CBU.1=MCMCglmm(model.NO.CBU, random=~phylo, family=c("gaussian"),
  1148. ginverse=list(phylo=inv.phylo$Ainv),
  1149. prior=prior, data=NO.data,
  1150. nitt=500000,burnin=10000,thin=500)
  1151. ## run the model twice
  1152. model.NO.CBU.2=MCMCglmm(model.NO.CBU, random=~phylo, family=c("gaussian"),
  1153. ginverse=list(phylo=inv.phylo$Ainv),
  1154. prior=prior, data=NO.data,
  1155. nitt=500000,burnin=10000,thin=500)
  1156. ##diagnostics
  1157. ## convergence
  1158. gelman.diag(mcmc.list(model.NO.CBU.1$Sol,model.NO.CBU.2$Sol))
  1159. gelman.diag(mcmc.list(model.NO.CBU.1$VCV,model.NO.CBU.2$VCV))
  1160. #random and fixed okay
  1161. plot(mcmc.list(model.NO.CBU.1$VCV,model.NO.CBU.2$VCV))
  1162. plot(mcmc.list(model.NO.CBU.1$Sol,model.NO.CBU.2$Sol))
  1163. #all good.
  1164. summary(model.NO.CBU.1)
  1165. #hm no diffs according to PF.
  1166. #CBU tNO
  1167. ## define model
  1168. model.NO.CBU.cl=log10(NO)~log10(rCBR)+log10(CBU)*Grp.color+SEX.mod
  1169. ## run model
  1170. model.NO.CBU.cl.1=MCMCglmm(model.NO.CBU.cl, random=~phylo, family=c("gaussian"),
  1171. ginverse=list(phylo=inv.phylo$Ainv),
  1172. prior=prior, data=NO.data,
  1173. nitt=500000,burnin=10000,thin=500)
  1174. ## run the model twice
  1175. model.NO.CBU.cl.2=MCMCglmm(model.NO.CBU.cl, random=~phylo, family=c("gaussian"),
  1176. ginverse=list(phylo=inv.phylo$Ainv),
  1177. prior=prior, data=NO.data,
  1178. nitt=500000,burnin=10000,thin=500)
  1179. ##diagnostics
  1180. ## convergence
  1181. gelman.diag(mcmc.list(model.NO.CBU.cl.1$Sol,model.NO.CBU.cl.2$Sol))
  1182. gelman.diag(mcmc.list(model.NO.CBU.cl.1$VCV,model.NO.CBU.cl.2$VCV))
  1183. #random and fixed okay
  1184. plot(mcmc.list(model.NO.CBU.cl.1$VCV,model.NO.CBU.cl.2$VCV))
  1185. plot(mcmc.list(model.NO.CBU.cl.1$Sol,model.NO.CBU.cl.2$Sol))
  1186. #all good.
  1187. summary(model.NO.CBU.cl.1)
  1188. #CBL tNO
  1189. ## define model
  1190. model.NO.CBL=log10(NO)~log10(rCBR)+log10(CBL)*PollenF+SEX.mod
  1191. ## run model
  1192. model.NO.CBL.1=MCMCglmm(model.NO.CBL, random=~phylo, family=c("gaussian"),
  1193. ginverse=list(phylo=inv.phylo$Ainv),
  1194. prior=prior, data=NO.data,
  1195. nitt=500000,burnin=10000,thin=500)
  1196. ## run the model twice
  1197. model.NO.CBL.2=MCMCglmm(model.NO.CBL, random=~phylo, family=c("gaussian"),
  1198. ginverse=list(phylo=inv.phylo$Ainv),
  1199. prior=prior, data=NO.data,
  1200. nitt=500000,burnin=10000,thin=500)
  1201. ##diagnostics
  1202. ## convergence
  1203. gelman.diag(mcmc.list(model.NO.CBL.1$Sol,model.NO.CBL.2$Sol))
  1204. gelman.diag(mcmc.list(model.NO.CBL.1$VCV,model.NO.CBL.2$VCV))
  1205. #random and fixed okay
  1206. plot(mcmc.list(model.NO.CBL.1$VCV,model.NO.CBL.2$VCV))
  1207. plot(mcmc.list(model.NO.CBL.1$Sol,model.NO.CBL.2$Sol))
  1208. #all good.
  1209. summary(model.NO.CBL.1)
  1210. #hm no diffs according to PF.
  1211. #CBL tNO
  1212. ## define model
  1213. model.NO.CBL.cl=log10(NO)~log10(rCBR)+log10(CBL)*Grp.color+SEX.mod
  1214. ## run model
  1215. model.NO.CBL.cl.1=MCMCglmm(model.NO.CBL.cl, random=~phylo, family=c("gaussian"),
  1216. ginverse=list(phylo=inv.phylo$Ainv),
  1217. prior=prior, data=NO.data,
  1218. nitt=500000,burnin=10000,thin=500)
  1219. ## run the model twice
  1220. model.NO.CBL.cl.2=MCMCglmm(model.NO.CBL.cl, random=~phylo, family=c("gaussian"),
  1221. ginverse=list(phylo=inv.phylo$Ainv),
  1222. prior=prior, data=NO.data,
  1223. nitt=500000,burnin=10000,thin=500)
  1224. ##diagnostics
  1225. ## convergence
  1226. gelman.diag(mcmc.list(model.NO.CBL.cl.1$Sol,model.NO.CBL.cl.2$Sol))
  1227. gelman.diag(mcmc.list(model.NO.CBL.cl.1$VCV,model.NO.CBL.cl.2$VCV))
  1228. #random and fixed okay
  1229. plot(mcmc.list(model.NO.CBL.cl.1$VCV,model.NO.CBL.cl.2$VCV))
  1230. plot(mcmc.list(model.NO.CBL.cl.1$Sol,model.NO.CBL.cl.2$Sol))
  1231. #all good.
  1232. summary(model.NO.CBL.cl.1)
  1233. ##### CX, AOTU, POTU within DIFFERENCES (Figure 3) #####
  1234. setwd("C:/R-Analysis")
  1235. cx.data=read.table(file="Hel-CX-MB_vs2.txt", sep="\t", header=TRUE)
  1236. str(cx.data)
  1237. #TREE
  1238. tree = read.nexus("Heliconiini.trees")
  1239. tree=force.ultrametric(tree,method="nnls")
  1240. plot(tree)
  1241. inv.phylo=inverseA(tree,nodes="TIPS",scale=TRUE)
  1242. ##MCMCglmm
  1243. # set priors
  1244. prior=list(G=list(G1=list(V=1,nu=0.02)),R=list(V=1,nu=0.02)) #standard priors as explored by SHM
  1245. #AOTU to rest
  1246. ## define model
  1247. model.AOTU.win=log10(AOTU)~log10(rCBR)+log10(POTU)+log10(CBU)+log10(CBL)+log10(PB)+SEX.mod
  1248. ## run model
  1249. model.AOTU.win.1=MCMCglmm(model.AOTU.win, random=~phylo, family=c("gaussian"),
  1250. ginverse=list(phylo=inv.phylo$Ainv),
  1251. prior=prior, data=cx.data,
  1252. nitt=500000,burnin=10000,thin=500)
  1253. ## run the model twice
  1254. model.AOTU.win.2=MCMCglmm(model.AOTU.win, random=~phylo, family=c("gaussian"),
  1255. ginverse=list(phylo=inv.phylo$Ainv),
  1256. prior=prior, data=cx.data,
  1257. nitt=500000,burnin=10000,thin=500)
  1258. ##diagnostics
  1259. ## convergence
  1260. gelman.diag(mcmc.list(model.AOTU.win.1$Sol,model.AOTU.win.2$Sol))
  1261. gelman.diag(mcmc.list(model.AOTU.win.1$VCV,model.AOTU.win.2$VCV))
  1262. #random and fixed okay
  1263. plot(mcmc.list(model.AOTU.win.1$VCV,model.AOTU.win.2$VCV))
  1264. plot(mcmc.list(model.AOTU.win.1$Sol,model.AOTU.win.2$Sol))
  1265. #all good.
  1266. sum.AOTU=summary(model.AOTU.win.1)
  1267. sum.AOTU.output=sum.AOTU$solutions
  1268. #POTU to rest
  1269. ## define model
  1270. model.POTU.win=log10(POTU)~log10(rCBR)+log10(AOTU)+log10(CBU)+log10(CBL)+log10(PB)+SEX.mod
  1271. ## run model
  1272. model.POTU.win.1=MCMCglmm(model.POTU.win, random=~phylo, family=c("gaussian"),
  1273. ginverse=list(phylo=inv.phylo$Ainv),
  1274. prior=prior, data=cx.data,
  1275. nitt=500000,burnin=10000,thin=500)
  1276. ## run the model twice
  1277. model.POTU.win.2=MCMCglmm(model.POTU.win, random=~phylo, family=c("gaussian"),
  1278. ginverse=list(phylo=inv.phylo$Ainv),
  1279. prior=prior, data=cx.data,
  1280. nitt=500000,burnin=10000,thin=500)
  1281. ##diagnostics
  1282. ## convergence
  1283. gelman.diag(mcmc.list(model.POTU.win.1$Sol,model.POTU.win.2$Sol))
  1284. gelman.diag(mcmc.list(model.POTU.win.1$VCV,model.POTU.win.2$VCV))
  1285. #random and fixed okay
  1286. plot(mcmc.list(model.POTU.win.1$VCV,model.POTU.win.2$VCV))
  1287. plot(mcmc.list(model.POTU.win.1$Sol,model.POTU.win.2$Sol))
  1288. #all good.
  1289. sum.POTU=summary(model.POTU.win.1)
  1290. sum.POTU.output=sum.POTU$solutions
  1291. #CBU to rest
  1292. ## define model
  1293. model.CBU.win=log10(CBU)~log10(rCBR)+log10(AOTU)+log10(POTU)+log10(CBL)+log10(PB)+SEX.mod
  1294. ## run model
  1295. model.CBU.win.1=MCMCglmm(model.CBU.win, random=~phylo, family=c("gaussian"),
  1296. ginverse=list(phylo=inv.phylo$Ainv),
  1297. prior=prior, data=cx.data,
  1298. nitt=500000,burnin=10000,thin=500)
  1299. ## run the model twice
  1300. model.CBU.win.2=MCMCglmm(model.CBU.win, random=~phylo, family=c("gaussian"),
  1301. ginverse=list(phylo=inv.phylo$Ainv),
  1302. prior=prior, data=cx.data,
  1303. nitt=500000,burnin=10000,thin=500)
  1304. ##diagnostics
  1305. ## convergence
  1306. gelman.diag(mcmc.list(model.CBU.win.1$Sol,model.CBU.win.2$Sol))
  1307. gelman.diag(mcmc.list(model.CBU.win.1$VCV,model.CBU.win.2$VCV))
  1308. #random and fixed okay
  1309. plot(mcmc.list(model.CBU.win.1$VCV,model.CBU.win.2$VCV))
  1310. plot(mcmc.list(model.CBU.win.1$Sol,model.CBU.win.2$Sol))
  1311. #all good.
  1312. sum.CBU=summary(model.CBU.win.1)
  1313. sum.CBU.output=sum.CBU$solutions
  1314. #CBL to rest
  1315. ## define model
  1316. model.CBL.win=log10(CBL)~log10(rCBR)+log10(AOTU)+log10(POTU)+log10(CBU)+log10(PB)+SEX.mod
  1317. ## run model
  1318. model.CBL.win.1=MCMCglmm(model.CBL.win, random=~phylo, family=c("gaussian"),
  1319. ginverse=list(phylo=inv.phylo$Ainv),
  1320. prior=prior, data=cx.data,
  1321. nitt=500000,burnin=10000,thin=500)
  1322. ## run the model twice
  1323. model.CBL.win.2=MCMCglmm(model.CBL.win, random=~phylo, family=c("gaussian"),
  1324. ginverse=list(phylo=inv.phylo$Ainv),
  1325. prior=prior, data=cx.data,
  1326. nitt=500000,burnin=10000,thin=500)
  1327. ##diagnostics
  1328. ## convergence
  1329. gelman.diag(mcmc.list(model.CBL.win.1$Sol,model.CBL.win.2$Sol))
  1330. gelman.diag(mcmc.list(model.CBL.win.1$VCV,model.CBL.win.2$VCV))
  1331. #random and fixed okay
  1332. plot(mcmc.list(model.CBL.win.1$VCV,model.CBL.win.2$VCV))
  1333. plot(mcmc.list(model.CBL.win.1$Sol,model.CBL.win.2$Sol))
  1334. #all good.
  1335. sum.CBL=summary(model.CBL.win.1)
  1336. sum.CBL.output=sum.CBL$solutions
  1337. #PB to rest
  1338. ## define model
  1339. model.PB.win=log10(PB)~log10(rCBR)+log10(AOTU)+log10(POTU)+log10(CBU)+log10(CBL)+SEX.mod
  1340. ## run model
  1341. model.PB.win.1=MCMCglmm(model.PB.win, random=~phylo, family=c("gaussian"),
  1342. ginverse=list(phylo=inv.phylo$Ainv),
  1343. prior=prior, data=cx.data,
  1344. nitt=500000,burnin=10000,thin=500)
  1345. ## run the model twice
  1346. model.PB.win.2=MCMCglmm(model.PB.win, random=~phylo, family=c("gaussian"),
  1347. ginverse=list(phylo=inv.phylo$Ainv),
  1348. prior=prior, data=cx.data,
  1349. nitt=500000,burnin=10000,thin=500)
  1350. ##diagnostics
  1351. ## convergence
  1352. gelman.diag(mcmc.list(model.PB.win.1$Sol,model.PB.win.2$Sol))
  1353. gelman.diag(mcmc.list(model.PB.win.1$VCV,model.PB.win.2$VCV))
  1354. #random and fixed okay
  1355. plot(mcmc.list(model.PB.win.1$VCV,model.PB.win.2$VCV))
  1356. plot(mcmc.list(model.PB.win.1$Sol,model.PB.win.2$Sol))
  1357. #all good.
  1358. sum.PB=summary(model.PB.win.1)
  1359. sum.PB.output=sum.PB$solutions
  1360. #NO to rest
  1361. NO.data=subset(cx.data, NO >= 20)
  1362. ## define model
  1363. model.NO.win=log10(NO)~log10(rCBR)+log10(AOTU)+log10(POTU)+log10(CBU)+log10(CBL)+log10(PB)+SEX.mod
  1364. ## run model
  1365. model.NO.win.1=MCMCglmm(model.NO.win, random=~phylo, family=c("gaussian"),
  1366. ginverse=list(phylo=inv.phylo$Ainv),
  1367. prior=prior, data=NO.data,
  1368. nitt=500000,burnin=10000,thin=500)
  1369. ## run the model twice
  1370. model.NO.win.2=MCMCglmm(model.NO.win, random=~phylo, family=c("gaussian"),
  1371. ginverse=list(phylo=inv.phylo$Ainv),
  1372. prior=prior, data=NO.data,
  1373. nitt=500000,burnin=10000,thin=500)
  1374. ##diagnostics
  1375. ## convergence
  1376. gelman.diag(mcmc.list(model.NO.win.1$Sol,model.NO.win.2$Sol))
  1377. gelman.diag(mcmc.list(model.NO.win.1$VCV,model.NO.win.2$VCV))
  1378. #random and fixed okay
  1379. plot(mcmc.list(model.NO.win.1$VCV,model.NO.win.2$VCV))
  1380. plot(mcmc.list(model.NO.win.1$Sol,model.NO.win.2$Sol))
  1381. #all good.
  1382. sum.NO=summary(model.NO.win.1)
  1383. sum.NO.output=sum.NO$solutions
  1384. #rerun significant relationships to test effects of pollen feeding
  1385. #model
  1386. model.AOTU.CBU=log10(AOTU)~log10(rCBR)+log10(CBU)*PollenF+SEX.mod
  1387. model.AOTU.CBL=log10(AOTU)~log10(rCBR)+log10(CBL)*PollenF+SEX.mod
  1388. model.POTU.PB=log10(POTU)~log10(rCBR)+log10(PB)*PollenF+SEX.mod
  1389. model.CBU.AOTU=log10(CBU)~log10(rCBR)+log10(AOTU)*PollenF+SEX.mod
  1390. model.CBU.CBL=log10(CBU)~log10(rCBR)+log10(CBL)*PollenF+SEX.mod
  1391. model.CBL.AOTU=log10(CBL)~log10(rCBR)+log10(AOTU)*PollenF+SEX.mod
  1392. model.CBL.CBU=log10(CBL)~log10(rCBR)+log10(CBU)*PollenF+SEX.mod
  1393. model.CBL.PB=log10(CBL)~log10(rCBR)+log10(PB)*PollenF+SEX.mod
  1394. model.PB.POTU=log10(PB)~log10(rCBR)+log10(POTU)*PollenF+SEX.mod
  1395. model.PB.CBL=log10(PB)~log10(rCBR)+log10(CBL)*PollenF+SEX.mod
  1396. ## run model
  1397. model.AOTU.CBU.1=MCMCglmm(model.AOTU.CBU, random=~phylo, family=c("gaussian"),
  1398. ginverse=list(phylo=inv.phylo$Ainv),
  1399. prior=prior, data=cx.data,
  1400. nitt=500000,burnin=10000,thin=500)
  1401. model.AOTU.CBL.1=MCMCglmm(model.AOTU.CBL, random=~phylo, family=c("gaussian"),
  1402. ginverse=list(phylo=inv.phylo$Ainv),
  1403. prior=prior, data=cx.data,
  1404. nitt=500000,burnin=10000,thin=500)
  1405. model.POTU.PB.1=MCMCglmm(model.POTU.PB, random=~phylo, family=c("gaussian"),
  1406. ginverse=list(phylo=inv.phylo$Ainv),
  1407. prior=prior, data=cx.data,
  1408. nitt=500000,burnin=10000,thin=500)
  1409. model.CBU.AOTU.1=MCMCglmm(model.CBU.AOTU, random=~phylo, family=c("gaussian"),
  1410. ginverse=list(phylo=inv.phylo$Ainv),
  1411. prior=prior, data=cx.data,
  1412. nitt=500000,burnin=10000,thin=500)
  1413. model.CBU.CBL.1=MCMCglmm(model.CBU.CBL, random=~phylo, family=c("gaussian"),
  1414. ginverse=list(phylo=inv.phylo$Ainv),
  1415. prior=prior, data=cx.data,
  1416. nitt=500000,burnin=10000,thin=500)
  1417. model.CBL.AOTU.1=MCMCglmm(model.CBL.AOTU, random=~phylo, family=c("gaussian"),
  1418. ginverse=list(phylo=inv.phylo$Ainv),
  1419. prior=prior, data=cx.data,
  1420. nitt=500000,burnin=10000,thin=500)
  1421. model.CBL.CBU.1=MCMCglmm(model.CBL.CBU, random=~phylo, family=c("gaussian"),
  1422. ginverse=list(phylo=inv.phylo$Ainv),
  1423. prior=prior, data=cx.data,
  1424. nitt=500000,burnin=10000,thin=500)
  1425. model.CBL.PB.1=MCMCglmm(model.CBL.PB, random=~phylo, family=c("gaussian"),
  1426. ginverse=list(phylo=inv.phylo$Ainv),
  1427. prior=prior, data=cx.data,
  1428. nitt=500000,burnin=10000,thin=500)
  1429. model.PB.POTU.1=MCMCglmm(model.PB.POTU, random=~phylo, family=c("gaussian"),
  1430. ginverse=list(phylo=inv.phylo$Ainv),
  1431. prior=prior, data=cx.data,
  1432. nitt=500000,burnin=10000,thin=500)
  1433. model.PB.CBL.1=MCMCglmm(model.PB.CBL, random=~phylo, family=c("gaussian"),
  1434. ginverse=list(phylo=inv.phylo$Ainv),
  1435. prior=prior, data=cx.data,
  1436. nitt=500000,burnin=10000,thin=500)
  1437. ## run model again
  1438. model.AOTU.CBU.2=MCMCglmm(model.AOTU.CBU, random=~phylo, family=c("gaussian"),
  1439. ginverse=list(phylo=inv.phylo$Ainv),
  1440. prior=prior, data=cx.data,
  1441. nitt=500000,burnin=10000,thin=500)
  1442. model.AOTU.CBL.2=MCMCglmm(model.AOTU.CBL, random=~phylo, family=c("gaussian"),
  1443. ginverse=list(phylo=inv.phylo$Ainv),
  1444. prior=prior, data=cx.data,
  1445. nitt=500000,burnin=10000,thin=500)
  1446. model.POTU.PB.2=MCMCglmm(model.POTU.PB, random=~phylo, family=c("gaussian"),
  1447. ginverse=list(phylo=inv.phylo$Ainv),
  1448. prior=prior, data=cx.data,
  1449. nitt=500000,burnin=10000,thin=500)
  1450. model.CBU.AOTU.2=MCMCglmm(model.CBU.AOTU, random=~phylo, family=c("gaussian"),
  1451. ginverse=list(phylo=inv.phylo$Ainv),
  1452. prior=prior, data=cx.data,
  1453. nitt=500000,burnin=10000,thin=500)
  1454. model.CBU.CBL.2=MCMCglmm(model.CBU.CBL, random=~phylo, family=c("gaussian"),
  1455. ginverse=list(phylo=inv.phylo$Ainv),
  1456. prior=prior, data=cx.data,
  1457. nitt=500000,burnin=10000,thin=500)
  1458. model.CBL.AOTU.2=MCMCglmm(model.CBL.AOTU, random=~phylo, family=c("gaussian"),
  1459. ginverse=list(phylo=inv.phylo$Ainv),
  1460. prior=prior, data=cx.data,
  1461. nitt=500000,burnin=10000,thin=500)
  1462. model.CBL.CBU.2=MCMCglmm(model.CBL.CBU, random=~phylo, family=c("gaussian"),
  1463. ginverse=list(phylo=inv.phylo$Ainv),
  1464. prior=prior, data=cx.data,
  1465. nitt=500000,burnin=10000,thin=500)
  1466. model.CBL.PB.2=MCMCglmm(model.CBL.PB, random=~phylo, family=c("gaussian"),
  1467. ginverse=list(phylo=inv.phylo$Ainv),
  1468. prior=prior, data=cx.data,
  1469. nitt=500000,burnin=10000,thin=500)
  1470. model.PB.POTU.2=MCMCglmm(model.PB.POTU, random=~phylo, family=c("gaussian"),
  1471. ginverse=list(phylo=inv.phylo$Ainv),
  1472. prior=prior, data=cx.data,
  1473. nitt=500000,burnin=10000,thin=500)
  1474. model.PB.CBL.2=MCMCglmm(model.PB.CBL, random=~phylo, family=c("gaussian"),
  1475. ginverse=list(phylo=inv.phylo$Ainv),
  1476. prior=prior, data=cx.data,
  1477. nitt=500000,burnin=10000,thin=500)
  1478. ##diagnostics
  1479. ## convergence
  1480. gelman.diag(mcmc.list(model.AOTU.CBU.1$Sol,model.AOTU.CBU.2$Sol))
  1481. gelman.diag(mcmc.list(model.AOTU.CBU.1$VCV,model.AOTU.CBU.2$VCV))
  1482. #random and fixed okay
  1483. plot(mcmc.list(model.AOTU.CBU.1$VCV,model.AOTU.CBU.2$VCV))
  1484. plot(mcmc.list(model.AOTU.CBU.1$Sol,model.AOTU.CBU.2$Sol))
  1485. #all good.
  1486. ## convergence
  1487. gelman.diag(mcmc.list(model.AOTU.CBL.1$Sol,model.AOTU.CBL.2$Sol))
  1488. gelman.diag(mcmc.list(model.AOTU.CBL.1$VCV,model.AOTU.CBL.2$VCV))
  1489. #random and fixed okay
  1490. plot(mcmc.list(model.AOTU.CBL.1$VCV,model.AOTU.CBL.2$VCV))
  1491. plot(mcmc.list(model.AOTU.CBL.1$Sol,model.AOTU.CBL.2$Sol))
  1492. #all good.
  1493. ## convergence
  1494. gelman.diag(mcmc.list(model.POTU.PB.1$Sol,model.POTU.PB.2$Sol))
  1495. gelman.diag(mcmc.list(model.POTU.PB.1$VCV,model.POTU.PB.2$VCV))
  1496. #random and fixed okay
  1497. plot(mcmc.list(model.POTU.PB.1$VCV,model.POTU.PB.2$VCV))
  1498. plot(mcmc.list(model.POTU.PB.1$Sol,model.POTU.PB.2$Sol))
  1499. #all good.
  1500. ## convergence
  1501. gelman.diag(mcmc.list(model.CBU.AOTU.1$Sol,model.CBU.AOTU.2$Sol))
  1502. gelman.diag(mcmc.list(model.CBU.AOTU.1$VCV,model.CBU.AOTU.2$VCV))
  1503. #random and fixed okay
  1504. plot(mcmc.list(model.CBU.AOTU.1$VCV,model.CBU.AOTU.2$VCV))
  1505. plot(mcmc.list(model.CBU.AOTU.1$Sol,model.CBU.AOTU.2$Sol))
  1506. #all good.
  1507. ## convergence
  1508. gelman.diag(mcmc.list(model.CBU.CBL.1$Sol,model.CBU.CBL.2$Sol))
  1509. gelman.diag(mcmc.list(model.CBU.CBL.1$VCV,model.CBU.CBL.2$VCV))
  1510. #random and fixed okay
  1511. plot(mcmc.list(model.CBU.CBL.1$VCV,model.CBU.CBL.2$VCV))
  1512. plot(mcmc.list(model.CBU.CBL.1$Sol,model.CBU.CBL.2$Sol))
  1513. #all good.
  1514. ## convergence
  1515. gelman.diag(mcmc.list(model.CBL.AOTU.1$Sol,model.CBL.AOTU.2$Sol))
  1516. gelman.diag(mcmc.list(model.CBL.AOTU.1$VCV,model.CBL.AOTU.2$VCV))
  1517. #random and fixed okay
  1518. plot(mcmc.list(model.CBL.AOTU.1$VCV,model.CBL.AOTU.2$VCV))
  1519. plot(mcmc.list(model.CBL.AOTU.1$Sol,model.CBL.AOTU.2$Sol))
  1520. #all good.
  1521. ## convergence
  1522. gelman.diag(mcmc.list(model.CBL.CBU.1$Sol,model.CBL.CBU.2$Sol))
  1523. gelman.diag(mcmc.list(model.CBL.CBU.1$VCV,model.CBL.CBU.2$VCV))
  1524. #random and fixed okay
  1525. plot(mcmc.list(model.CBL.CBU.1$VCV,model.CBL.CBU.2$VCV))
  1526. plot(mcmc.list(model.CBL.CBU.1$Sol,model.CBL.CBU.2$Sol))
  1527. #all good.
  1528. ## convergence
  1529. gelman.diag(mcmc.list(model.CBL.PB.1$Sol,model.CBL.PB.2$Sol))
  1530. gelman.diag(mcmc.list(model.CBL.PB.1$VCV,model.CBL.PB.2$VCV))
  1531. #random and fixed okay
  1532. plot(mcmc.list(model.CBL.PB.1$VCV,model.CBL.PB.2$VCV))
  1533. plot(mcmc.list(model.CBL.PB.1$Sol,model.CBL.PB.2$Sol))
  1534. #all good.
  1535. ## convergence
  1536. gelman.diag(mcmc.list(model.PB.POTU.1$Sol,model.PB.POTU.2$Sol))
  1537. gelman.diag(mcmc.list(model.PB.POTU.1$VCV,model.PB.POTU.2$VCV))
  1538. #random and fixed okay
  1539. plot(mcmc.list(model.PB.POTU.1$VCV,model.PB.POTU.2$VCV))
  1540. plot(mcmc.list(model.PB.POTU.1$Sol,model.PB.POTU.2$Sol))
  1541. #all good.
  1542. ## convergence
  1543. gelman.diag(mcmc.list(model.PB.CBL.1$Sol,model.PB.CBL.2$Sol))
  1544. gelman.diag(mcmc.list(model.PB.CBL.1$VCV,model.PB.CBL.2$VCV))
  1545. #random and fixed okay
  1546. plot(mcmc.list(model.PB.CBL.1$VCV,model.PB.CBL.2$VCV))
  1547. plot(mcmc.list(model.PB.CBL.1$Sol,model.PB.CBL.2$Sol))
  1548. #all good.
  1549. sum.AOTU.CBU=summary(model.AOTU.CBU.1)
  1550. sum.AOTU.CBU.output=sum.AOTU.CBU$solutions
  1551. sum.AOTU.CBL=summary(model.AOTU.CBL.1)
  1552. sum.AOTU.CBL.output=sum.AOTU.CBL$solutions
  1553. sum.POTU.PB=summary(model.POTU.PB.1)
  1554. sum.POTU.PB.output=sum.POTU.PB$solutions
  1555. sum.CBU.AOTU=summary(model.CBU.AOTU.1)
  1556. sum.CBU.AOTU.output=sum.CBU.AOTU$solutions
  1557. sum.CBU.CBL=summary(model.CBU.CBL.1)
  1558. sum.CBU.CBL.output=sum.CBU.CBL$solutions
  1559. sum.CBL.AOTU=summary(model.CBL.AOTU.1)
  1560. sum.CBL.AOTU.output=sum.CBL.AOTU$solutions
  1561. sum.CBL.CBU=summary(model.CBL.CBU.1)
  1562. sum.CBL.CBU.output=sum.CBL.CBU$solutions
  1563. sum.CBL.PB=summary(model.CBL.PB.1)
  1564. sum.CBL.PB.output=sum.CBL.PB$solutions
  1565. sum.PB.POTU=summary(model.PB.POTU.1)
  1566. sum.PB.POTU.output=sum.PB.POTU$solutions
  1567. sum.PB.CBL=summary(model.PB.CBL.1)
  1568. sum.PB.CBL.output=sum.PB.CBL$solutions
  1569. #no pollen feeding effects
  1570. ##### Rate analysis w multirateBM (phytools) (related to Figure 2 and S3) #####
  1571. setwd("C:/R-Analysis")
  1572. rate.data=read.table(file="Hel-CX-rates_vs2.txt", sep="\t", header=TRUE)
  1573. str(rate.data)
  1574. ## import CX and rCBR data and reformat as named vectors
  1575. names(rate.data)[1] <- ""
  1576. rate.data <- data.frame(rate.data[,-1], row.names=rate.data[,1])
  1577. CX<-setNames(rate.data$log.CX,
  1578. rownames(rate.data))
  1579. rCBR<-setNames(rate.data$log.rCBR,
  1580. rownames(rate.data))
  1581. MB<-setNames(rate.data$log.MB,
  1582. rownames(rate.data))
  1583. AOTU<-setNames(rate.data$log.AOTU,
  1584. rownames(rate.data))
  1585. POTU<-setNames(rate.data$log.POTU,
  1586. rownames(rate.data))
  1587. ## import tree
  1588. tt = read.nexus("Heliconiini.trees")
  1589. ## Fit multirateBM
  1590. fit.HeliconiiniCX<-multirateBM(tt,CX,n.iter=3)
  1591. fit.HeliconiinirCBR<-multirateBM(tt,rCBR,n.iter=3)
  1592. fit.HeliconiiniMB<-multirateBM(tt,MB,n.iter=3)
  1593. fit.HeliconiiniAOTU<-multirateBM(tt,AOTU,n.iter=3)
  1594. fit.HeliconiiniPOTU<-multirateBM(tt,POTU,n.iter=3)
  1595. ## CX
  1596. sig2 <- fit.HeliconiiniCX$sig2
  1597. fit.HeliconiiniCX$sig2 <- sig2
  1598. fit.HeliconiiniCX$tree <- tt
  1599. ##rCBR
  1600. sig2 <- fit.HeliconiinirCBR$sig2
  1601. fit.HeliconiinirCBR$sig2 <- sig2
  1602. fit.HeliconiinirCBR$tree <- tt
  1603. ##MB
  1604. sig2 <- fit.HeliconiiniMB$sig2
  1605. fit.HeliconiiniMB$sig2 <- sig2
  1606. fit.HeliconiiniMB$tree <- tt
  1607. ##AOTU
  1608. sig2 <- fit.HeliconiiniAOTU$sig2
  1609. fit.HeliconiiniAOTU$sig2 <- sig2
  1610. fit.HeliconiiniAOTU$tree <- tt
  1611. ##POTU
  1612. sig2 <- fit.HeliconiiniPOTU$sig2
  1613. fit.HeliconiiniPOTU$sig2 <- sig2
  1614. fit.HeliconiiniPOTU$tree <- tt
  1615. ## calculate edge values function
  1616. ln.mean<-function(x){
  1617. if(x[1]==x[2]) return(x[1])
  1618. else {
  1619. a<-x[2]
  1620. b<-log(x[1])-log(x[2])
  1621. return(a/b*exp(b)-a/b)
  1622. }
  1623. }
  1624. ##CX rates
  1625. CX.sig2<-apply(fit.HeliconiiniCX$tree$edge,1,function(e,fit.HeliconiiniCX)
  1626. ln.mean(fit.HeliconiiniCX[e]),fit=fit.HeliconiiniCX$sig2)
  1627. ## rCBR rates
  1628. rCBR.sig2<-apply(fit.HeliconiinirCBR$tree$edge,1,function(e,fit.HeliconiinirCBR)
  1629. ln.mean(fit.HeliconiinirCBR[e]),fit=fit.HeliconiinirCBR$sig2)
  1630. ## MB rates
  1631. MB.sig2<-apply(fit.HeliconiiniMB$tree$edge,1,function(e,fit.HeliconiiniMB)
  1632. ln.mean(fit.HeliconiiniMB[e]),fit=fit.HeliconiiniMB$sig2)
  1633. ## AOTU rates
  1634. AOTU.sig2<-apply(fit.HeliconiiniAOTU$tree$edge,1,function(e,fit.HeliconiiniAOTU)
  1635. ln.mean(fit.HeliconiiniAOTU[e]),fit=fit.HeliconiiniAOTU$sig2)
  1636. ## POTU rates
  1637. POTU.sig2<-apply(fit.HeliconiiniPOTU$tree$edge,1,function(e,fit.HeliconiiniPOTU)
  1638. ln.mean(fit.HeliconiiniPOTU[e]),fit=fit.HeliconiiniPOTU$sig2)
  1639. ## regress CX sig2 against rCBR sig2 for branches and get residuals
  1640. CX.rCBR <- lm(CX.sig2~rCBR.sig2)
  1641. residuals.CX <- CX.rCBR$residuals
  1642. ## regress MB sig2 against rCBR sig2 for branches and get residuals
  1643. MB.rCBR <- lm(MB.sig2~rCBR.sig2)
  1644. residuals.MB <- MB.rCBR$residuals
  1645. ## regress AOTU sig2 against rCBR sig2 for branches and get residuals
  1646. AOTU.rCBR <- lm(AOTU.sig2~rCBR.sig2)
  1647. residuals.AOTU <- AOTU.rCBR$residuals
  1648. ## regress POTU sig2 against rCBR sig2 for branches and get residuals
  1649. POTU.rCBR <- lm(POTU.sig2~rCBR.sig2)
  1650. residuals.POTU <- POTU.rCBR$residuals
  1651. ## set residuals minimum to 0
  1652. residuals.CX <- residuals.CX - min(residuals.CX)
  1653. residuals.MB <- residuals.MB - min(residuals.MB)
  1654. residuals.AOTU <- residuals.AOTU - min(residuals.AOTU)
  1655. residuals.POTU <- residuals.POTU - min(residuals.POTU)
  1656. ## plot the residuals along branches. CX according to MB rates.
  1657. plot<- TRUE
  1658. cols<-setNames(wes_palette("Zissou1", 1000, type = "continuous"),
  1659. 1:1000)
  1660. min.sig2<-min(residuals.MB)
  1661. max.sig2<-max(residuals.MB)
  1662. edge.states<-vector()
  1663. for(i in 1:length(residuals.CX)){
  1664. edge.states[i]<-round((residuals.CX[i]-min.sig2)/
  1665. (max.sig2-min.sig2)*999)+1
  1666. }
  1667. tree<-paintBranches(fit.HeliconiiniCX$tree,edge=fit.HeliconiiniCX$tree$edge[1,2],
  1668. state=edge.states[1])
  1669. for(i in 2:length(edge.states))
  1670. tree<-paintBranches(tree,edge=tree$edge[i,2],
  1671. state=edge.states[i])
  1672. nticks<-10
  1673. ticks<-seq(min(residuals.CX),max(residuals.CX),
  1674. length.out=nticks)
  1675. object<-list(tree=tree,cols=cols,ticks=ticks)
  1676. class(object)<-"multirateBM_plot"
  1677. plot(object,outline=FALSE)
  1678. invisible(object)
  1679. ## plot the residuals along branches. CX normal
  1680. plot<- TRUE
  1681. cols<-setNames(wes_palette("Zissou1", 1000, type = "continuous"),
  1682. 1:1000)
  1683. min.sig2<-min(residuals.CX)
  1684. max.sig2<-max(residuals.CX)
  1685. edge.states<-vector()
  1686. for(i in 1:length(residuals.CX)){
  1687. edge.states[i]<-round((residuals.CX[i]-min.sig2)/
  1688. (max.sig2-min.sig2)*999)+1
  1689. }
  1690. tree<-paintBranches(fit.HeliconiiniCX$tree,edge=fit.HeliconiiniCX$tree$edge[1,2],
  1691. state=edge.states[1])
  1692. for(i in 2:length(edge.states))
  1693. tree<-paintBranches(tree,edge=tree$edge[i,2],
  1694. state=edge.states[i])
  1695. nticks<-10
  1696. ticks<-seq(min(residuals.CX),max(residuals.CX),
  1697. length.out=nticks)
  1698. object<-list(tree=tree,cols=cols,ticks=ticks)
  1699. class(object)<-"multirateBM_plot"
  1700. plot(object,outline=FALSE)
  1701. invisible(object)
  1702. ## plot the residuals along branches. MB normal
  1703. plot<- TRUE
  1704. cols<-setNames(wes_palette("Zissou1", 1000, type = "continuous"),
  1705. 1:1000)
  1706. min.sig2<-min(residuals.MB)
  1707. max.sig2<-max(residuals.MB)
  1708. edge.states<-vector()
  1709. for(i in 1:length(residuals.MB)){
  1710. edge.states[i]<-round((residuals.MB[i]-min.sig2)/
  1711. (max.sig2-min.sig2)*999)+1
  1712. }
  1713. tree<-paintBranches(fit.HeliconiiniMB$tree,edge=fit.HeliconiiniMB$tree$edge[1,2],
  1714. state=edge.states[1])
  1715. for(i in 2:length(edge.states))
  1716. tree<-paintBranches(tree,edge=tree$edge[i,2],
  1717. state=edge.states[i])
  1718. nticks<-10
  1719. ticks<-seq(min(residuals.MB),max(residuals.MB),
  1720. length.out=nticks)
  1721. object<-list(tree=tree,cols=cols,ticks=ticks)
  1722. class(object)<-"multirateBM_plot"
  1723. plot(object,outline=FALSE)
  1724. invisible(object)
  1725. ## plot the residuals along branches. AOTU normal
  1726. plot<- TRUE
  1727. cols<-setNames(wes_palette("Zissou1", 1000, type = "continuous"),
  1728. 1:1000)
  1729. min.sig2<-min(residuals.AOTU)
  1730. max.sig2<-max(residuals.AOTU)
  1731. edge.states<-vector()
  1732. for(i in 1:length(residuals.AOTU)){
  1733. edge.states[i]<-round((residuals.AOTU[i]-min.sig2)/
  1734. (max.sig2-min.sig2)*999)+1
  1735. }
  1736. tree<-paintBranches(fit.HeliconiiniAOTU$tree,edge=fit.HeliconiiniAOTU$tree$edge[1,2],
  1737. state=edge.states[1])
  1738. for(i in 2:length(edge.states))
  1739. tree<-paintBranches(tree,edge=tree$edge[i,2],
  1740. state=edge.states[i])
  1741. nticks<-10
  1742. ticks<-seq(min(residuals.AOTU),max(residuals.AOTU),
  1743. length.out=nticks)
  1744. object<-list(tree=tree,cols=cols,ticks=ticks)
  1745. class(object)<-"multirateBM_plot"
  1746. plot(object,outline=FALSE)
  1747. invisible(object)
  1748. ## plot the residuals along branches. POTU normal
  1749. plot<- TRUE
  1750. cols<-setNames(wes_palette("Zissou1", 1000, type = "continuous"),
  1751. 1:1000)
  1752. min.sig2<-min(residuals.POTU)
  1753. max.sig2<-max(residuals.POTU)
  1754. edge.states<-vector()
  1755. for(i in 1:length(residuals.POTU)){
  1756. edge.states[i]<-round((residuals.POTU[i]-min.sig2)/
  1757. (max.sig2-min.sig2)*999)+1
  1758. }
  1759. tree<-paintBranches(fit.HeliconiiniPOTU$tree,edge=fit.HeliconiiniPOTU$tree$edge[1,2],
  1760. state=edge.states[1])
  1761. for(i in 2:length(edge.states))
  1762. tree<-paintBranches(tree,edge=tree$edge[i,2],
  1763. state=edge.states[i])
  1764. nticks<-10
  1765. ticks<-seq(min(residuals.POTU),max(residuals.POTU),
  1766. length.out=nticks)
  1767. object<-list(tree=tree,cols=cols,ticks=ticks)
  1768. class(object)<-"multirateBM_plot"
  1769. plot(object,outline=FALSE)
  1770. invisible(object)
  1771. #plot rates
  1772. rate.data.mod=data.frame(CX.sig2, rCBR.sig2,residuals)
  1773. str(rate.data.mod)
  1774. rate.plot=ggplot(rate.data.mod,aes(x=rCBR.sig2, y=CX.sig2))+geom_point(alpha=0.4,size=4)
  1775. rate.plot
  1776. rate.plot2=rate.plot+ geom_smooth(method = "lm",size=3) + theme_minimal()
  1777. rate.plot2
  1778. ggplotly(rate.plot2)
  1779. summary(CX.rCBR)
  1780. ##### ER neuron cell count (Figure 6) #####
  1781. setwd("C:/R-Analysis")
  1782. cellcount.data=read.table(file="cellcounts_.txt", sep="\t", header=TRUE)
  1783. str(cellcount.data)
  1784. hel.data=subset(cellcount.data, species == "hel")
  1785. iulia.data=subset(cellcount.data, species == "iulia")
  1786. count.lm.iul=lm(cell_count~no_sections, iulia.data)
  1787. count.lm.hel=lm(cell_count~no_sections, hel.data)
  1788. summary(count.lm.iul)
  1789. summary(count.lm.hel)
  1790. count.lm=lm(cell_count~no_sections, cellcount.data)
  1791. summary(count.lm)
  1792. #no of sections that were merged does not influence number of cells.
  1793. #cell numbers in GAD in cx
  1794. setwd("C:/R-Analysis")
  1795. count.data=read.table(file="Cell-count_CX.txt", sep="\t", header=TRUE)
  1796. str(count.data)
  1797. count.ER.lm=lm(number~spec+sex,data=count.data)
  1798. summary(count.ER.lm)
  1799. count.plot=ggplot(count.data, aes(x=spec,y=number,fill=spec))
  1800. count.plot
  1801. count.plot2=count.plot+theme_minimal()+geom_dotplot(binaxis='y', stackdir='center',stackratio=1.5, dotsize=1.2)
  1802. count.plot2
  1803. count.plot3=count.plot2+scale_fill_manual(values = c("#1293b9ff", "#cb8781ff"))
  1804. count.plot3
  1805. ##### bulb quantification (Figure 7) #####
  1806. setwd("C:/R-Analysis")
  1807. bulb.data=read.table(file="Bulb_quant.txt", sep="\t", header=TRUE)
  1808. str(bulb.data)
  1809. bulb.pers=lm(log10_bulb.vol~bulb.MF.TH+spec+sex,data=bulb.data)
  1810. MG.pers=lm(MG.AVG~MG.MF.TH+spec+sex,data=bulb.data)
  1811. summary(bulb.pers)
  1812. summary(MG.pers)
  1813. #person doing segmentations does not harbour specific information.
  1814. #are there species and sex differences? we dont expect these two factors to interact in a two-species comparison.
  1815. bulb.spec=lm(log10_bulb.vol~spec+sex,data=bulb.data)
  1816. summary(bulb.spec)
  1817. #no species nor sex differences.
  1818. #is total MG no predicted by avg mg size, or bulb volume?
  1819. total.MG.no=lm(No_MG.bulb~log10_bulb.vol+MG.AVG+spec+sex,data=bulb.data)
  1820. summary(total.MG.no)
  1821. #bulb volume and avg MG are predictors of total MG no, which makes sense, as this a pure mathematical value and derived from them.
  1822. #does ER neuron number predict bulb vol, or total MG no, or avg MG size (which is a reasonable assumption as neuron number might predict these metrics)?
  1823. bulb.ER=lm(log10_bulb.vol~ER.no+spec+sex,data=bulb.data)
  1824. summary(bulb.ER)
  1825. MGno.ER=lm(No_MG.bulb~ER.no+spec+sex,data=bulb.data)
  1826. summary(MGno.ER)
  1827. MGavg.ER=lm(MG.AVG~ER.no+spec+sex,data=bulb.data)
  1828. summary(MGavg.ER)
  1829. #none of them do. So, it seems like ER neuron number is largely independent in this case, from these bulb related metrics.
  1830. #plotting
  1831. bulb.plot=ggplot(bulb.data, aes(x=spec,y=log10_bulb.vol,fill=spec))
  1832. bulb.plot
  1833. bulb.plot2=bulb.plot+theme_minimal()+geom_dotplot(binaxis='y', stackdir='center',stackratio=1.5, dotsize=1.2)
  1834. bulb.plot2
  1835. bulb.plot3=bulb.plot2+scale_fill_manual(values = c("#1293b9ff", "#cb8781ff"))
  1836. bulb.plot3
  1837. MGno.plot=ggplot(bulb.data, aes(x=spec,y=No_MG.bulb,fill=spec))
  1838. MGno.plot
  1839. MGno.plot2=MGno.plot+theme_minimal()+geom_dotplot(binaxis='y', stackdir='center',stackratio=1.5, dotsize=1.2)
  1840. MGno.plot2
  1841. MGno.plot3=MGno.plot2+scale_fill_manual(values = c("#1293b9ff", "#cb8781ff"))
  1842. MGno.plot3
  1843. #to plot MG sizes
  1844. setwd("C:/R-Analysis")
  1845. MG_avg.data=read.table(file="MG.avg.txt", sep="\t", header=TRUE)
  1846. str(MG_avg.data)
  1847. MGsize.plot=ggplot(MG_avg.data, aes(x=spec,y=MG.size,fill=spec))
  1848. MGsize.plot
  1849. MGsize.plot2=MGsize.plot+theme_minimal()+geom_dotplot(binaxis='y', stackdir='center',stackratio=1.5, dotsize=1.2)
  1850. MGsize.plot2
  1851. MGsize.plot3=MGsize.plot2+scale_fill_manual(values = c("#1293b9ff", "#cb8781ff"))
  1852. MGsize.plot3
  1853. bulb.mg.plot=ggarrange(MGno.plot3,MGsize.plot3,bulb.plot3,
  1854. ncol = 3, nrow = 1,common.legend = TRUE, legend="bottom")
  1855. bulb.mg.plot

Heliconiini-CX_SCRIPT.R, under CC-BY-4.0 · at the source

Overview

  1. School of Biological Sciences, University of Bristol, Bristol, United Kingdom
  2. Behaviour and Speciation, Faculty of Biology, Ludwig-Maximilians-Universität München, Munich, Germany
  3. Department of Biology, Norwegian University of Science and Technology, Trondheim, Norway
  4. Institute of Biology and Environmental Sciences, Carl von Ossietzky Universität Oldenburg, Oldenburg, Germany
Journal: eLife, volume 14, article RP107589
Dates: published online 1 June 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.7554/elife.107589 · PMID 42223014 · PMCID PMC13225844 · OpenAlex W4414262609
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: other (organism)
Methods: Statistics
Keywords: Other
MeSH: Biological Evolution*, Butterflies*, Mushroom Bodies*, Animals, Neuropeptides (* major topic)
Topic: Plant and animal studies (Ecology, Evolution, Behavior and Systematics, Agricultural and Biological Sciences), according to OpenAlex
Funding: European Research Council (Starter Grant 851040, to Richard M Merrill, 851040, Starter Grant 758508, 758508); Natural Environment Research Council (Independent Research Fellowship NE/N014936/1); Human Frontier Science Program (Project Grant RGP0029/2022); Medical Research Council (DTP studentship MR/W006308/1); University of Bristol (Student Scholarship); Deutsche Forschungsgemeinschaft (Walter-Benjamin Fellowship FA 1818/1-1)
Citations: cited by 1 paper (Europe PMC); 110 references in the paper
Research resources: Anti-FASII (mouse; monoclonal) RRID:AB_10805878, Anti-mouse-Cyanine-2 (goat; polyclonal) RRID:AB_2307343, Anti-rabbit-Cyanine-3 (goat; polyclonal) RRID:AB_2338006, Anti-rabbit-Cyanine-2 (goat; polyclonal) RRID:AB_2338021, Anti-mouse-Cyanine-3 (goat; polyclonal) RRID:AB_2338680, Anti-HRP (rabbit; polyclonal) RRID:AB_261181, Anti-TH (rabbit; polyclonal) RRID:AB_390204, Anti-GAD (rabbit; polyclonal) RRID:AB_477019, Anti-SYNORF1 (mouse; monoclonal) RRID:AB_528479, Anti-5-HT (rabbit; polyclonal) RRID:AB_572263, Anti-acTUB (mouse; monoclonal) RRID:AB_609894, R Studio 2023.06.0 RRID:SCR_000432, R 4.3.1 RRID:SCR_001905, Fiji 1.54 RRID:SCR_003070, Amira 2020.2/5.4.3/2021.1 RRID:SCR_007353

Abstract

Neural circuits evolved to produce variable cognitive processes through adaptive mechanisms operating within a background of developmental and functional constraints. Understanding how this conflict is resolved requires a comparative framework encapsulating clear behavioural variation. We leverage Heliconiini butterflies to examine how selection shaped the evolution of the central complex and mushroom bodies, two insect integration centres involved in navigation. The evolution of systematic spatial foraging in Heliconius has led to changes in brain morphology and learning and memory profiles over a short evolutionary timescale. Here, we show that in contrast to massively expanded mushroom bodies, the central complex is strongly conserved in size and general architecture. However, we identify divergences in the expression of a neuropeptide, Allatostatin A, in the noduli, and in the numbers of GABA-ergic ring neurons and their branching in the fan-shaped body, which are essential members of the anterior compass pathway. These differences are rare examples of divergence inside the central complex network matching expectations of where evolutionary adaptability might occur. We conclude that due to the contrasting volumetric conservation of the central complex, and the massive differences in the mushroom bodies, their circuit logics must determine distinct responses to selection associated with divergent foraging behaviours.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repository

Its files are read in the Code ↔ Paper reader above, with 3 matches between paragraphs and lines of code.

Zenodo 15304965

License: CC-BY-4.0
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Languages: R (1)
Size: 10 files, 1 script
Software Heritage: not checked
Found in: the text, “Statistical tests of volumetric dataset”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: emmeans (1 file), ggpubr (1 file), Plotly (1 file), tidyverse (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
  • 27 September 2026: the link answers (HTTP 200)
1 file

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 1 script, each with its path and the digest of its content;
  • 3 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data availability

Data, R script and readme files associated with this publication is publicly available at https://doi.org/10.5281/zenodo.15304965.

The following dataset was generated:

Farnworth MS. 2025. Dataset associated with publication of Farnworth et al "Distinct evolutionary trajectories of two integration centres, the central complex and mushroom bodies, across Heliconiini butterflies". Zenodo.

The following previously published dataset was used:

Couto A, Young F, Atzeni D, Marty S, Melo-Flórez L, Hebberecht L, Monllor M, Neal C, Cicconardi F, McMillan W, Montgomery SH. 2023. Data From: Rapid expansion and visual specialisation of learning and memory centers in the brains of Heliconiini butterflies. Dryad Digital Repository.

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 27 September 2026: the first record

Recorded: type, language, journal, volume, pages, dates, 6 authors, 1 keyword, 5 MeSH terms, 6 funders, 108 references, 15 RRIDs.

Cite

This paper

Farnworth, M. S., Toh, Y. P., Loupasaki, T., Hodge, E. A., el Jundi, B., & Montgomery, S. H. (2026). Distinct evolutionary trajectories of two integration centres, the central complex and mushroom bodies, across Heliconiini butterflies. eLife, 14, RP107589. https://doi.org/10.7554/elife.107589

BibTeX

@article{farnworth2026distinct,
author = {Farnworth, Max S and Toh, Yi Peng and Loupasaki, Theodora and Hodge, Elizabeth A and el Jundi, Basil and Montgomery, Stephen H},
title = {{Distinct evolutionary trajectories of two integration centres, the central complex and mushroom bodies, across Heliconiini butterflies}},
journal = {eLife},
year = {2026},
month = jun,
volume = {14},
pages = {RP107589},
publisher = {eLife Sciences Publications, Ltd},
issn = {2050-084X},
doi = {10.7554/elife.107589},
url = {https://doi.org/10.7554/elife.107589},
pmid = {42223014},
pmcid = {PMC13225844}
}

RIS

TY - JOUR
AU - Farnworth, Max S
AU - Toh, Yi Peng
AU - Loupasaki, Theodora
AU - Hodge, Elizabeth A
AU - el Jundi, Basil
AU - Montgomery, Stephen H
TI - Distinct evolutionary trajectories of two integration centres, the central complex and mushroom bodies, across Heliconiini butterflies
T2 - eLife
J2 - eLife
PY - 2026
DA - 2026/06/01
VL - 14
SP - RP107589
SN - 2050-084X
PB - eLife Sciences Publications, Ltd
DO - 10.7554/elife.107589
UR - https://doi.org/10.7554/elife.107589
LA - en
ER -

CSL-JSON

{
"id": "10.7554/elife.107589",
"type": "article-journal",
"title": "Distinct evolutionary trajectories of two integration centres, the central complex and mushroom bodies, across Heliconiini butterflies",
"container-title": "eLife",
"author": [
{
"family": "Farnworth",
"given": "Max S"
},
{
"family": "Toh",
"given": "Yi Peng"
},
{
"family": "Loupasaki",
"given": "Theodora"
},
{
"family": "Hodge",
"given": "Elizabeth A"
},
{
"family": "el Jundi",
"given": "Basil"
},
{
"family": "Montgomery",
"given": "Stephen H"
}
],
"container-title-short": "eLife",
"volume": "14",
"page": "RP107589",
"DOI": "10.7554/elife.107589",
"PMID": "42223014",
"PMCID": "PMC13225844",
"ISSN": "2050-084X",
"publisher": "eLife Sciences Publications, Ltd",
"URL": "https://doi.org/10.7554/elife.107589",
"language": "en",
"issued": {
"date-parts": [
[
2026,
6,
1
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.3389/fnsys.2026.1822122 [code]
Convergence-divergence circuits for multimodal integration of innate and learned opponent valences.
Journal: Frontiers in systems neuroscience
In common: Plotly, 15 references
[2] doi:10.1038/s41586-026-10827-7 [code]
A vector-based strategy for olfactory navigation in Drosophila.
Journal: Nature
In common: 11 references
[3] doi:10.1038/s41586-026-10735-w [code]
Distributed control circuits across a brain-and-cord connectome.
Journal: Nature
In common: Plotly, ggpubr, tidyverse, 8 references
[4] doi:10.1038/s41467-026-75945-2 [code]
Neural dynamics for working memory and evidence integration during olfactory navigation in Drosophila.
Journal: Nature communications
In common: 10 references
[5] doi:10.1016/j.isci.2026.116039 [code]
Caste- and sex-specific differential investment in brain regions of Australian ants.
Journal: iScience
In common: other, 9 references
[6] doi:10.1126/sciadv.aeh7220 [code]
Central complex representations of self-movement are sufficient to compute wind direction in flight.
Journal: Science advances
In common: 7 references
[7] doi:10.1073/pnas.2609141123
Odor tracking in flying &lt;i&gt;Drosophila&lt;/i&gt; requires visual reafference and compass neurons.
Journal: Proceedings of the National Academy of Sciences of the United States of America
In common: 6 references
[8] doi:10.1038/s41586-026-10526-3
Transcription factor codes patterning neuronal groundplans of the cerebrum.
Journal: Nature
In common: 4 references
[9] doi:10.7554/elife.96084 [code]
Organization of circuits linking descending input to motor output in the &lt;i&gt;Drosophila&lt;/i&gt; Male Adult Nerve Cord connectome.
Journal: eLife
In common: ggpubr, tidyverse, 3 references
[10] doi:10.1038/s41586-026-10747-6 [code]
Ancient feeding-related neuropeptides regulate alloparenting in ants.
Journal: Nature
In common: ggpubr, tidyverse, other, 2 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.