SEARCH SEARCH

Article Search

Variation of the area measured from each specimen in mm2

Importing the data:

# Clean previous loaded data
rm(list=ls()) 
# Setting the workind directory:
setwd("F:/Documentos/1.1.Proyectos/16. Patterns of variation in the ammonoid cross section/Data")

#Loading supplementary data
df<-read.csv2("SuppData1.csv", dec =".")

Relationship between area measured from each specimen and morphometric parameters

Area vs whorl height (wh or H)

library(ggplot2)
ggplot(df, aes(H,A)) + 
  geom_point(aes(), size = 1) +
  labs(title="Area vs Whorl Height",
       x=expression("H (mm)"),
       y=expression("Area"))+
  theme(plot.title = element_text(family = "serif", face = "bold", hjust = 0.5))+
  coord_trans(y = "log",x = "log" )+theme_bw()

Area vs Diameter (D)

df2<- df[-c(16, 27, 76, 87, 106, 108, 118, 126, 228, 232, 276, 280), ]
ggplot(df2, aes(as.numeric(D),A)) + 
  geom_point(aes(), size = 1) +
  labs(title="Area - Diameter",
       x=expression("D (mm)"),
       y=expression("Area"))+
  theme(plot.title = element_text(family = "serif", face = "bold", hjust = 0.5))+
  coord_trans(y = "log",x = "log" )+theme_bw()

Area vs Centroid Size (scale factor)

ggplot(df, aes(CS,A)) + 
  geom_point(aes(), size = 1) +
  labs(title="Area - Centroid Size",
       x=expression("CS (mm)"),
       y=expression("Area"))+
  theme(plot.title = element_text(family = "serif", face = "bold", hjust = 0.5))+
  coord_trans(y = "log",x = "log" )+theme_bw()

Relationship between area and other variables

Area vs Subtaxa

ggplot(df, aes(log(A),ST)) + geom_boxplot()+ geom_point(aes(), size = 0.7) +
  labs(title="Area - ST",
       x=expression("Area"),
       y=expression("ST"))+
  theme(plot.title = element_text(family = "serif", face = "bold", hjust = 0.5))+theme_bw()

Area vs Paleolatitude

ggplot(df, aes(log(A),PLAT)) + 
  geom_point(aes(), size = 1) +
  labs(title="Area - PLAT",
       x=expression("log(A)"),
       y=expression("PLAT"))+
  theme(plot.title = element_text(family = "serif", face = "bold", hjust = 0.5))+theme_bw()

Statistical models

Given that the area only takes infinite positive values, the ideal statistical distribution is a gamma distribution.

Model between area and centroid size

library(glmmTMB)
df$logCS<-log(df$CS)
m1<-glmmTMB(A~logCS,family=Gamma(link="log"), data=df)
summary(m1)
##  Family: Gamma  ( log )
## Formula:          A ~ logCS
## Data: df
## 
##      AIC      BIC   logLik deviance df.resid 
##   3834.5   3845.7  -1914.3   3828.5      297 
## 
## 
## Dispersion estimate for Gamma family (sigma^2): 0.313 
## 
## Conditional model:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -1.38207    0.14457   -9.56   <2e-16 ***
## logCS        1.83564    0.03675   49.94   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Testing the adjusted distribution using DHARMa

library(DHARMa)
## This is DHARMa 0.4.5. For overview type '?DHARMa'. For recent changes, type news(package = 'DHARMa')
sim <- simulateResiduals(fittedModel = m1, plot = T)

library(sjPlot)
## Learn more about sjPlot with 'browseVignettes("sjPlot")'.
tab_model(m1)
## Random effect variances not available. Returned R2 does not account for random effects.
 A
Predictors Estimates CI p
(Intercept) 0.25 0.19 – 0.33 <0.001
logCS 6.27 5.83 – 6.74 <0.001
Observations 300
R2 conditional / R2 marginal NA / 0.732

Testing the interaction between variables

#plotting the results
ggplot(df, aes(log(CS),log(A))) + 
  geom_point(aes(), size = 0.7, color="grey") +
  labs(title="Area - Centroid Size",
       x=expression("log(CS)"),
       y=expression("log(A)"))+
  theme(plot.title = element_text(family = "serif", face = "bold", hjust = 0.5))+geom_abline(slope = 1.83564,intercept = -1.38207, size=0.8)+geom_abline(slope = 1.763017,intercept = -1.66073120682,linetype="dotted", size=0.65)+geom_abline(slope = 1.9080599,intercept = -1.1086626,linetype="dotted", size=0.65)+theme_bw()

Relationship between area and diameter

library(glmmTMB)
df2$logD<-log(as.numeric(df2$D))
m2<-glmmTMB(A~logD,family=Gamma(link="log"), data=df2)
summary(m2)
##  Family: Gamma  ( log )
## Formula:          A ~ logD
## Data: df2
## 
##      AIC      BIC   logLik deviance df.resid 
##   3510.7   3521.7  -1752.3   3504.7      285 
## 
## 
## Dispersion estimate for Gamma family (sigma^2): 0.177 
## 
## Conditional model:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -1.56666    0.10999  -14.24   <2e-16 ***
## logD         1.88091    0.02815   66.81   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(DHARMa)
sim <- simulateResiduals(fittedModel = m2, plot = T)

library(sjPlot)
tab_model(m2)
## Random effect variances not available. Returned R2 does not account for random effects.
 A
Predictors Estimates CI p
(Intercept) 0.21 0.17 – 0.26 <0.001
logD 6.56 6.21 – 6.93 <0.001
Observations 288
R2 conditional / R2 marginal NA / 0.735
#plotting the results
ggplot(df2, aes(log(as.numeric(D)),log(A))) + 
  geom_point(aes(), size = 0.7, color="grey") +
  labs(title="Area - Diameter",
       x=expression("log(D)"),
       y=expression("log(A)"))+
  theme(plot.title = element_text(family = "serif", face = "bold", hjust = 0.5))+geom_abline(slope = 1.88091,intercept = -1.56666, size=0.8)+geom_abline(slope = 1.82616,intercept = -1.7719568,linetype="dotted", size=0.65)+geom_abline(slope = 1.935859,intercept = -1.3470736,linetype="dotted", size=0.65)+theme_bw()

Relationship between area and whorl height

library(glmmTMB)
df$logH<-log(df$H)
m3<-glmmTMB(A~logH,family=Gamma(link="log"), data=df)
summary(m3)
##  Family: Gamma  ( log )
## Formula:          A ~ logH
## Data: df
## 
##      AIC      BIC   logLik deviance df.resid 
##   3605.5   3616.6  -1799.7   3599.5      297 
## 
## 
## Dispersion estimate for Gamma family (sigma^2): 0.154 
## 
## Conditional model:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -0.03057    0.07882   -0.39    0.698    
## logH         1.87022    0.02521   74.18   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(DHARMa)
sim <- simulateResiduals(fittedModel = m3, plot = T)

# there is a warning but the test is not significant
library(sjPlot)
tab_model(m3)
## Random effect variances not available. Returned R2 does not account for random effects.
 A
Predictors Estimates CI p
(Intercept) 0.97 0.83 – 1.13 0.698
logH 6.49 6.18 – 6.82 <0.001
Observations 300
R2 conditional / R2 marginal NA / 0.740
#plotting the results
ggplot(df2, aes(log(H),log(A))) + 
  geom_point(aes(), size = 0.7, color="grey") +
  labs(title="Area - Whorl height",
       x=expression("log(H)"),
       y=expression("log(A)"))+
  theme(plot.title = element_text(family = "serif", face = "bold", hjust = 0.5))+geom_abline(slope = 1.87026253,intercept = -0.0304592, size=0.8)+geom_abline(slope = 1.821318,intercept = -0.186329,linetype="dotted", size=0.65)+geom_abline(slope = 1.919859,intercept = 0.12221763,linetype="dotted", size=0.65)+theme_bw()

Relationship between area measured and subtaxa controling by the scale factor

library(glmmTMB)
m4<-glmmTMB(A~ST+logCS,family=Gamma(link="log"), data=df)
summary(m4)
##  Family: Gamma  ( log )
## Formula:          A ~ ST + logCS
## Data: df
## 
##      AIC      BIC   logLik deviance df.resid 
##   3813.2   3857.6  -1894.6   3789.2      288 
## 
## 
## Dispersion estimate for Gamma family (sigma^2): 0.277 
## 
## Conditional model:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)          -1.40581    0.20900   -6.73 1.74e-11 ***
## ST1. Goniatitina      0.07184    0.17171    0.42  0.67566    
## ST2. Tornoceratina   -0.12740    0.18695   -0.68  0.49558    
## ST3. Clymeniida       0.03398    0.24124    0.14  0.88800    
## ST4. Prolecanitida   -0.07538    0.25184   -0.30  0.76469    
## ST5. Ceratitida       0.12886    0.17562    0.73  0.46312    
## ST6. Phylloceratida   0.01753    0.24117    0.07  0.94207    
## ST7. Lytoceratina     0.54777    0.26376    2.08  0.03782 *  
## ST8. Ammonitina       0.38277    0.15922    2.40  0.01622 *  
## ST9. Ancyloceratina   0.54932    0.18622    2.95  0.00318 ** 
## logCS                 1.77530    0.03773   47.05  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(DHARMa)
sim <- simulateResiduals(fittedModel = m4, plot = T)

library(sjPlot)
tab_model(m4)
## Random effect variances not available. Returned R2 does not account for random effects.
 A
Predictors Estimates CI p
(Intercept) 0.25 0.16 – 0.37 <0.001
ST [1. Goniatitina] 1.07 0.77 – 1.50 0.676
ST [2. Tornoceratina] 0.88 0.61 – 1.27 0.496
ST [3. Clymeniida] 1.03 0.64 – 1.66 0.888
ST [4. Prolecanitida] 0.93 0.57 – 1.52 0.765
ST [5. Ceratitida] 1.14 0.81 – 1.60 0.463
ST [6. Phylloceratida] 1.02 0.63 – 1.63 0.942
ST [7. Lytoceratina] 1.73 1.03 – 2.90 0.038
ST [8. Ammonitina] 1.47 1.07 – 2.00 0.016
ST9 Ancyloceratina 1.73 1.20 – 2.50 0.003
logCS 5.90 5.48 – 6.36 <0.001
Observations 300
R2 conditional / R2 marginal NA / 0.731
library(emmeans)
Comparaciones <- emmeans(m4, pairwise ~ ST|logCS)
Comparaciones 
## $emmeans
## logCS = 3.83:
##  ST                 emmean     SE  df lower.CL upper.CL
##  0. Agoniatitida      5.40 0.1521 288     5.10     5.70
##  1. Goniatitina       5.47 0.0799 288     5.32     5.63
##  2. Tornoceratina     5.27 0.1091 288     5.06     5.49
##  3. Clymeniida        5.43 0.1874 288     5.07     5.80
##  4. Prolecanitida     5.33 0.2009 288     4.93     5.72
##  5. Ceratitida        5.53 0.0878 288     5.36     5.70
##  6. Phylloceratida    5.42 0.1871 288     5.05     5.79
##  7. Lytoceratina      5.95 0.2154 288     5.52     6.37
##  8. Ammonitina        5.78 0.0470 288     5.69     5.88
##  9. Ancyloceratina    5.95 0.1075 288     5.74     6.16
## 
## Results are given on the log (not the response) scale. 
## Confidence level used: 0.95 
## 
## $contrasts
## logCS = 3.83:
##  contrast                               estimate     SE  df t.ratio p.value
##  0. Agoniatitida - 1. Goniatitina       -0.07184 0.1717 288  -0.418  1.0000
##  0. Agoniatitida - 2. Tornoceratina      0.12740 0.1869 288   0.681  0.9996
##  0. Agoniatitida - 3. Clymeniida        -0.03398 0.2412 288  -0.141  1.0000
##  0. Agoniatitida - 4. Prolecanitida      0.07538 0.2518 288   0.299  1.0000
##  0. Agoniatitida - 5. Ceratitida        -0.12886 0.1756 288  -0.734  0.9993
##  0. Agoniatitida - 6. Phylloceratida    -0.01753 0.2412 288  -0.073  1.0000
##  0. Agoniatitida - 7. Lytoceratina      -0.54777 0.2638 288  -2.077  0.5455
##  0. Agoniatitida - 8. Ammonitina        -0.38277 0.1592 288  -2.404  0.3274
##  0. Agoniatitida - 9. Ancyloceratina    -0.54932 0.1862 288  -2.950  0.0970
##  1. Goniatitina - 2. Tornoceratina       0.19924 0.1333 288   1.494  0.8936
##  1. Goniatitina - 3. Clymeniida          0.03786 0.2028 288   0.187  1.0000
##  1. Goniatitina - 4. Prolecanitida       0.14722 0.2151 288   0.684  0.9996
##  1. Goniatitina - 5. Ceratitida         -0.05702 0.1190 288  -0.479  1.0000
##  1. Goniatitina - 6. Phylloceratida      0.05431 0.2042 288   0.266  1.0000
##  1. Goniatitina - 7. Lytoceratina       -0.47592 0.2303 288  -2.066  0.5528
##  1. Goniatitina - 8. Ammonitina         -0.31093 0.0936 288  -3.323  0.0334
##  1. Goniatitina - 9. Ancyloceratina     -0.47748 0.1340 288  -3.564  0.0153
##  2. Tornoceratina - 3. Clymeniida       -0.16137 0.2141 288  -0.754  0.9991
##  2. Tornoceratina - 4. Prolecanitida    -0.05202 0.2252 288  -0.231  1.0000
##  2. Tornoceratina - 5. Ceratitida       -0.25626 0.1407 288  -1.821  0.7212
##  2. Tornoceratina - 6. Phylloceratida   -0.14492 0.2189 288  -0.662  0.9997
##  2. Tornoceratina - 7. Lytoceratina     -0.67516 0.2431 288  -2.778  0.1491
##  2. Tornoceratina - 8. Ammonitina       -0.51017 0.1209 288  -4.221  0.0013
##  2. Tornoceratina - 9. Ancyloceratina   -0.67672 0.1532 288  -4.417  0.0006
##  3. Clymeniida - 4. Prolecanitida        0.10936 0.2727 288   0.401  1.0000
##  3. Clymeniida - 5. Ceratitida          -0.09488 0.2073 288  -0.458  1.0000
##  3. Clymeniida - 6. Phylloceratida       0.01645 0.2663 288   0.062  1.0000
##  3. Clymeniida - 7. Lytoceratina        -0.51379 0.2866 288  -1.793  0.7393
##  3. Clymeniida - 8. Ammonitina          -0.34879 0.1942 288  -1.796  0.7374
##  3. Clymeniida - 9. Ancyloceratina      -0.51535 0.2161 288  -2.385  0.3390
##  4. Prolecanitida - 5. Ceratitida       -0.20424 0.2197 288  -0.930  0.9954
##  4. Prolecanitida - 6. Phylloceratida   -0.09291 0.2763 288  -0.336  1.0000
##  4. Prolecanitida - 7. Lytoceratina     -0.62315 0.2958 288  -2.106  0.5245
##  4. Prolecanitida - 8. Ammonitina       -0.45815 0.2075 288  -2.208  0.4538
##  4. Prolecanitida - 9. Ancyloceratina   -0.62471 0.2279 288  -2.741  0.1626
##  5. Ceratitida - 6. Phylloceratida       0.11133 0.2064 288   0.539  0.9999
##  5. Ceratitida - 7. Lytoceratina        -0.41891 0.2325 288  -1.802  0.7336
##  5. Ceratitida - 8. Ammonitina          -0.25391 0.0994 288  -2.556  0.2440
##  5. Ceratitida - 9. Ancyloceratina      -0.42047 0.1388 288  -3.029  0.0786
##  6. Phylloceratida - 7. Lytoceratina    -0.53024 0.2845 288  -1.864  0.6934
##  6. Phylloceratida - 8. Ammonitina      -0.36524 0.1921 288  -1.902  0.6681
##  6. Phylloceratida - 9. Ancyloceratina  -0.53180 0.2157 288  -2.465  0.2921
##  7. Lytoceratina - 8. Ammonitina         0.16500 0.2200 288   0.750  0.9991
##  7. Lytoceratina - 9. Ancyloceratina    -0.00156 0.2408 288  -0.006  1.0000
##  8. Ammonitina - 9. Ancyloceratina      -0.16656 0.1173 288  -1.420  0.9203
## 
## Results are given on the log (not the response) scale. 
## P value adjustment: tukey method for comparing a family of 10 estimates
plot(Comparaciones, comparisons = TRUE)
## I bet you wanted to call this with just object[[1]] - use '[[]]' or which' if I'm wrong.
## See '? emm_list' for more information
## Warning: Comparison discrepancy in group "3.83407153764674", 1. Goniatitina - 8. Ammonitina:
##     Target overlap = -0.0421, overlap on graph = 0.0177

library(ggeffects)

ggpredict(m4,terms = c("ST"))
## # Predicted values of A
## 
## ST               | Predicted |           95% CI
## -----------------------------------------------
## 8. Ammonitina    |    324.92 | [296.31, 356.28]
## 0. Agoniatitida  |    221.58 | [164.48, 298.51]
## 2. Tornoceratina |    195.08 | [157.52, 241.58]
## 5. Ceratitida    |    252.06 | [212.19, 299.41]
## 1. Goniatitina   |    238.09 | [203.57, 278.46]
## 7. Lytoceratina  |    383.20 | [251.21, 584.54]
## 4. Prolecanitida |    205.49 | [138.60, 304.67]
## 3. Clymeniida    |    229.24 | [158.76, 331.01]
## 
## Adjusted for:
## * logCS = 3.83
p<-ggpredict(m4,terms = c("ST"))
p$x <- factor(p$x, levels=c("0. Agoniatitida", "1. Goniatitina", "2. Tornoceratina", "3. Clymeniida", "4. Prolecanitida", "5. Ceratitida", "6. Phylloceratida","7. Lytoceratina", "8. Ammonitina","9. Ancyloceratina "))
p <- p[order(levels(p$x)),]
p
## # Predicted values of A
## 
## ST               | Predicted |           95% CI
## -----------------------------------------------
## 8. Ammonitina    |    324.92 | [296.31, 356.28]
## 0. Agoniatitida  |    221.58 | [164.48, 298.51]
## 2. Tornoceratina |    195.08 | [157.52, 241.58]
## 5. Ceratitida    |    252.06 | [212.19, 299.41]
## 1. Goniatitina   |    238.09 | [203.57, 278.46]
## 7. Lytoceratina  |    383.20 | [251.21, 584.54]
## 4. Prolecanitida |    205.49 | [138.60, 304.67]
## 3. Clymeniida    |    229.24 | [158.76, 331.01]
## 
## Adjusted for:
## * logCS = 3.83
plot(p)+coord_flip(xlim = NULL, ylim = NULL, expand = TRUE, clip = "on")+theme_bw()