Feinberg et al. (2014) examined morphological, genetic, and acoustic (call) criteria in four species of leopard frogs (Rana sphenocephala, R. pipiens, R. palustris, and a new species named R. kauffeldi) and an acoustically similar congener R. sylvatica (acoustic criteria only). For 283 museum specimens across the first four species, they measured size (snout-vent length) and 12 other morphological characteristics: head length, head width, eye diameter, tympanum diameter, foot length, eye to naris distance, naris to snout distance, thigh length, internarial distance, interorbital distance, shank length, and dorsal snout angle. Foot length was not recorded for 19 specimens, so these were excluded from the analysis. They also recorded seven call characteristics (call length, call rate, call rise time, call duty cycle, pulse number, pulse rate, and dominant frequency) from 45 frogs in the field across the five species. Call rate and call length were both adjusted based on regressions against temperature to a standard 14°C. We will not cover the genetic analysis here, and we will use LDA to examine the different species in multivariate space and see if the proposed new species was distinguishable morphologically or acoustically.

Rana sphenocephala. Bob Warrick, , via Wikimedia Commons

Rana pipiens. Ryan Hodnett, , via Wikimedia Commons

Rana kauffeldi. Brian R. Curry, , via Wikimedia Commons

The paper is here and the data sets for this example are morphological feinmorph.csv and we also use the acoustic variables feinacoust.csv

Feinberg, J. A., Newman, C. E., Watkins-Colwell, G. J., Schlesinger, M. D., Zarate, B., Curry, B. R., Shaffer, H. B. & Burger, J. (2014). Cryptic diversity in metropolis: confirmation of a new leopard frog species (Anura: Ranidae) from New York City and surrounding Atlantic coast regions. PLoS One, 9, e108213.

Preliminaries

Load required packages

# packages: vegan, car
devtools::source_url("https://raw.githubusercontent.com/mjkeough/mjkeough.github.io/refs/heads/main/R/libraries.R")   #This loads a set of packages used often
library(vegan)
library(DAAG)

Read in data files

feinmorph <- read_csv("../data/feinmorph.csv")
New names:Rows: 264 Columns: 24── Column specification ────────────────────────────────────────────────────────────
Delimiter: ","
chr  (1): spp
dbl (13): svl, hw, hl, td, ew, tl, sl, fl, end, nsd, iod, ind, dsa
lgl (10): ...15, ...16, ...17, ...18, ...19, ...20, ...21, ...22, ...23, ...24
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
feinacoust<-read_csv("../data/feinacoust.csv")
Rows: 45 Columns: 8── Column specification ────────────────────────────────────────────────────────────
Delimiter: ","
chr (1): spp
dbl (7): frogid, crt, cdc, pn, df, tcl, tcr
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Check linearity and distributions

scatterplotMatrix(~hw+hl+td+ew+tl+sl+fl+end+nsd+iod+ind+dsa,data=feinmorph,diagonal=list(method='boxplot'))

Standardize variables

feinmorph$hw <- scale(feinmorph$hw)
feinmorph$hl <- scale(feinmorph$hl)
feinmorph$td <- scale(feinmorph$td)
feinmorph$ew <- scale(feinmorph$ew)
feinmorph$tl <- scale(feinmorph$tl)
feinmorph$sl <- scale(feinmorph$sl)
feinmorph$fl <- scale(feinmorph$fl)
feinmorph$end <- scale(feinmorph$end)
feinmorph$nsd <- scale(feinmorph$nsd)
feinmorph$iod <- scale(feinmorph$iod)
feinmorph$ind <- scale(feinmorph$ind)
feinmorph$dsa <- scale(feinmorph$dsa)

Check homog variances and covariances

feinmorph.dist <- dist(feinmorph[,-(1:2)])
feinmorph.disp <- betadisper(feinmorph.dist,feinmorph$spp)
permutest(feinmorph.disp)

Permutation test for homogeneity of multivariate dispersions
Permutation: free
Number of permutations: 999

Response: Distances
           Df     Sum Sq   Mean Sq       F N.Perm Pr(>F)
Groups      3   11.11472 3.7049065 0.86298    999  0.479
Residuals 260 1116.21959 4.2931523                      
anova(feinmorph.disp)
Analysis of Variance Table

Response: Distances
           Df     Sum Sq   Mean Sq F value  Pr(>F)
Groups      3   11.11472 3.7049065 0.86298 0.46082
Residuals 260 1116.21959 4.2931523                

LDA with jackknife CV

feinmorphjac.lda <- lda(spp~hw+hl+td+ew+tl+sl+fl+end+nsd+iod+ind+dsa, data=feinmorph, CV=TRUE)
print(feinmorphjac.lda)
$class
  [1] rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk  
 [16] rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk  
 [31] rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk  
 [46] rk   rk   rk   rpa  rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk  
 [61] rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk  
 [76] rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk  
 [91] rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rpa  rk   rk  
[106] rk   rk   rk   rk   rpa  rk   rk   rk   rk   rk   rk   rk   rk   rk   rk  
[121] rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk  
[136] rpa  rk   rk   rpa  rk   rk   rk   rsph rpi  rsph rk   rk   rk   rsph rpi 
[151] rk   rk   rk   rk   rk   rk   rk   rk   rk   rpi  rpi  rk   rk   rpi  rpi 
[166] rpa  rpi  rpa  rpa  rk   rpa  rk   rk   rk   rk   rpa  rk   rk   rpa  rk  
[181] rpa  rk   rpa  rpa  rpa  rk   rk   rpi  rpi  rpi  rk   rpa  rpi  rsph rpi 
[196] rpi  rpi  rpi  rk   rpi  rpi  rk   rpa  rpi  rpi  rpa  rpi  rpi  rk   rpi 
[211] rpi  rpi  rpi  rpi  rpi  rpi  rpi  rpi  rsph rsph rsph rsph rsph rsph rsph
[226] rk   rsph rsph rsph rsph rsph rsph rsph rk   rk   rsph rk   rk   rk   rk  
[241] rsph rk   rk   rsph rk   rk   rk   rsph rsph rsph rsph rsph rk   rsph rsph
[256] rsph rk   rsph rk   rsph rsph rk   rsph rsph
Levels: rk rpa rpi rsph

$posterior
                 rk             rpa             rpi            rsph
1   9.679694276e-01 2.579915672e-02 1.615651326e-05 6.215259138e-03
2   9.494837276e-01 3.375839543e-02 1.214560099e-05 1.674573138e-02
3   8.159115579e-01 1.835868827e-01 2.320593924e-06 4.992387591e-04
4   9.734630073e-01 1.777462986e-02 1.894462346e-03 6.867900529e-03
5   9.843492859e-01 1.403173947e-02 1.008866182e-03 6.101084658e-04
6   9.215138792e-01 2.441267085e-02 8.897242351e-04 5.318372575e-02
7   9.461642565e-01 9.189550367e-03 2.014585984e-05 4.462604729e-02
8   9.338832837e-01 6.261249347e-02 9.868158834e-05 3.405541256e-03
9   9.416137740e-01 5.661178014e-02 2.137874501e-04 1.560658378e-03
10  9.562048917e-01 4.138840569e-02 1.746115824e-03 6.605867546e-04
11  9.800413320e-01 1.286701290e-02 3.500022323e-03 3.591632773e-03
12  9.063370840e-01 7.049450744e-02 1.366437127e-04 2.303176487e-02
13  5.533817401e-01 2.969683400e-01 1.057103474e-01 4.393957253e-02
14  9.576096351e-01 6.488071624e-04 3.364608963e-05 4.170791168e-02
15  9.210554909e-01 4.153010480e-02 2.994020293e-04 3.711500227e-02
16  8.916233800e-01 2.834504741e-02 1.360939714e-05 8.001796315e-02
17  7.289370200e-01 2.694666618e-02 2.733151877e-03 2.413831619e-01
18  9.300095056e-01 2.381948747e-02 2.265852197e-04 4.594442174e-02
19  8.357016583e-01 8.476414439e-02 1.490922005e-03 7.804327535e-02
20  6.289058882e-01 5.242061349e-03 1.761681634e-02 3.482352341e-01
21  9.774927866e-01 1.929659973e-02 6.406497048e-06 3.204207180e-03
22  6.705474480e-01 8.374709361e-04 5.159547673e-06 3.286099215e-01
23  9.966701674e-01 1.520579760e-04 3.554795350e-08 3.177739054e-03
24  9.655958343e-01 3.353586594e-02 2.433131663e-06 8.658665981e-04
25  9.604812646e-01 5.505829176e-04 8.733188637e-03 3.023496384e-02
26  9.802274546e-01 1.538603996e-03 1.103985082e-05 1.822290160e-02
27  8.618081418e-01 7.203120402e-02 1.712642846e-04 6.598938985e-02
28  8.916599005e-01 9.686557506e-02 3.497621397e-04 1.112476231e-02
29  9.231893503e-01 4.379044955e-02 1.679444073e-02 1.622575941e-02
30  9.953266287e-01 1.259848323e-03 1.784117865e-06 3.411738896e-03
31  7.060605895e-01 1.053329391e-02 2.791434252e-01 4.262691387e-03
32  9.455053629e-01 3.550202279e-02 1.870562505e-04 1.880555805e-02
33  9.820758868e-01 6.760216455e-03 3.514850814e-05 1.112874828e-02
34  9.738090736e-01 1.812946420e-02 8.619516886e-05 7.975267065e-03
35  9.885337468e-01 7.286483568e-03 1.344107274e-05 4.166328603e-03
36  9.512864821e-01 3.823579807e-02 3.003799959e-03 7.473919924e-03
37  9.292301517e-01 7.026604159e-02 1.682461322e-04 3.355605290e-04
38  9.382628461e-01 5.848121132e-02 2.508696199e-03 7.472463816e-04
39  8.641909007e-01 9.364501093e-02 7.056945802e-05 4.209351889e-02
40  6.686752532e-01 3.183005067e-01 1.384098906e-03 1.164014122e-02
41  7.839242349e-01 2.154989201e-01 7.150712462e-05 5.053379291e-04
42  8.083505332e-01 1.888679482e-01 6.032458920e-04 2.178272666e-03
43  7.601964240e-01 1.826453170e-01 4.133439085e-04 5.674491513e-02
44  9.586742243e-01 3.190684868e-03 3.248430286e-06 3.813184239e-02
45  9.428559711e-01 5.381699151e-02 2.827311618e-05 3.298764258e-03
46  7.666119300e-01 1.379933222e-01 6.865401414e-02 2.674073367e-02
47  9.930614583e-01 5.045815707e-03 1.865388326e-05 1.874072134e-03
48  9.871993740e-01 8.635766883e-03 1.512868392e-06 4.163346227e-03
49  1.534726580e-01 8.442783655e-01 2.716474554e-04 1.977328992e-03
50  9.303749414e-01 6.582161654e-02 4.415846594e-04 3.361857393e-03
51  9.992895117e-01 5.520519754e-05 4.158920917e-07 6.548672322e-04
52  9.953719676e-01 1.969769126e-03 1.583186254e-04 2.499944653e-03
53  8.914145292e-01 6.880718696e-02 2.171044741e-04 3.956117932e-02
54  9.613432619e-01 2.347160560e-02 4.383448010e-03 1.080168448e-02
55  9.868027679e-01 2.421616109e-03 1.485441439e-06 1.077413052e-02
56  9.974240985e-01 2.361305348e-03 1.064099449e-05 2.039551938e-04
57  9.928313659e-01 5.832869724e-03 1.128643413e-04 1.222900068e-03
58  9.979705361e-01 1.905248315e-03 5.001155896e-06 1.192144281e-04
59  8.697217713e-01 8.031799161e-02 4.922196712e-02 7.382699702e-04
60  9.202666625e-01 6.786555892e-02 8.346042242e-03 3.521736362e-03
61  9.848835771e-01 9.205632163e-03 1.167546221e-04 5.794036124e-03
62  8.894898334e-01 6.405949436e-02 7.624862970e-03 3.882580931e-02
63  9.765740630e-01 2.286632917e-02 3.219096695e-05 5.274168933e-04
64  9.699305688e-01 1.978068155e-02 1.836351969e-03 8.452397663e-03
65  9.983080835e-01 1.616628208e-03 9.532663234e-06 6.575561415e-05
66  9.982098307e-01 1.373452298e-03 5.743320886e-05 3.592837864e-04
67  9.739347927e-01 2.079125157e-02 6.303551395e-04 4.643600555e-03
68  9.794491830e-01 1.936498966e-02 8.787782144e-04 3.070491503e-04
69  8.663352796e-01 1.309339579e-01 9.141081979e-05 2.639351648e-03
70  9.697182679e-01 2.931734053e-02 4.698642792e-06 9.596929033e-04
71  9.745777166e-01 2.202119915e-02 2.531937594e-05 3.375764904e-03
72  9.368911914e-01 6.177425837e-02 3.482617253e-05 1.299724041e-03
73  8.927050943e-01 8.771010232e-02 6.393061877e-03 1.319174150e-02
74  7.726912930e-01 1.486859685e-01 5.474508825e-03 7.314822972e-02
75  9.922377834e-01 2.679970397e-03 2.610556823e-05 5.056140604e-03
76  6.199375074e-01 3.104634853e-02 2.098787048e-05 3.489951562e-01
77  8.710599150e-01 5.797049689e-02 1.727154879e-04 7.079687266e-02
78  9.942602948e-01 9.586605262e-04 1.967744370e-07 4.780847925e-03
79  6.255838041e-01 1.728473621e-01 5.219742519e-03 1.963490913e-01
80  8.736588351e-01 1.739610320e-02 1.003443532e-03 1.079416181e-01
81  9.461487049e-01 9.742043429e-03 1.788509141e-03 4.232074256e-02
82  8.176066712e-01 3.688666992e-02 4.202356921e-03 1.413043019e-01
83  9.900375980e-01 8.319745861e-03 1.910641571e-05 1.623549693e-03
84  9.874237633e-01 6.547558013e-03 2.087395272e-04 5.819939120e-03
85  9.004195394e-01 4.007177610e-02 8.347820425e-06 5.950033672e-02
86  9.733716034e-01 1.665629056e-02 7.234795978e-04 9.248626487e-03
87  9.927426758e-01 4.088686907e-03 3.670837714e-05 3.131928914e-03
88  9.587817965e-01 2.292865878e-02 1.932776000e-03 1.635676875e-02
89  8.349291461e-01 1.057150965e-01 2.941143157e-02 2.994432578e-02
90  9.849197572e-01 3.997411885e-03 4.547700935e-06 1.107828318e-02
91  9.929019275e-01 6.941151391e-03 3.314686341e-05 1.237742363e-04
92  9.968758917e-01 1.469796439e-03 1.115306111e-07 1.654200359e-03
93  9.960529026e-01 3.186177407e-03 2.700453283e-04 4.908746838e-04
94  8.746011572e-01 2.099766308e-02 7.900603831e-03 9.650057586e-02
95  8.072599575e-01 1.336993139e-01 3.374218553e-05 5.900698642e-02
96  9.943254112e-01 4.438779128e-03 6.764563194e-05 1.168164048e-03
97  9.891564603e-01 6.956592603e-04 5.763494542e-07 1.014730413e-02
98  9.363412927e-01 9.169973481e-03 7.145451739e-06 5.448158840e-02
99  9.883028441e-01 5.259267340e-03 3.110106564e-03 3.327781999e-03
100 9.802770150e-01 1.852045219e-02 3.978705738e-06 1.198554155e-03
101 6.382568831e-01 3.143668170e-01 4.986173762e-07 4.737580136e-02
102 8.414891286e-01 1.376936805e-01 2.062792174e-04 2.061091168e-02
103 7.945786216e-02 6.484268810e-01 1.023105192e-03 2.710921517e-01
104 6.860033474e-01 2.230082647e-01 2.572661462e-03 8.841572650e-02
105 5.698477030e-01 8.408966933e-03 4.936086486e-05 4.216939692e-01
106 7.121479656e-01 2.552502489e-02 1.349686329e-05 2.623135126e-01
107 7.916541978e-01 1.695692029e-02 9.278735954e-05 1.912960946e-01
108 8.779507750e-01 2.211652339e-02 3.071361860e-04 9.962556546e-02
109 8.059997888e-01 1.068359994e-02 1.636074509e-05 1.833002505e-01
110 1.149662030e-01 8.831887864e-01 4.292779736e-04 1.415732675e-03
111 9.975486551e-01 2.405611659e-03 1.182347461e-06 4.455085552e-05
112 8.435261090e-01 1.337298795e-01 7.001217364e-04 2.204388979e-02
113 9.996415351e-01 1.410460090e-04 2.497117218e-06 2.149217375e-04
114 9.698140282e-01 1.102481513e-02 4.491304780e-05 1.911624365e-02
115 9.650574814e-01 7.570303435e-03 1.279416197e-04 2.724427351e-02
116 9.875295597e-01 5.414243067e-03 2.513038693e-05 7.031066825e-03
117 9.381750507e-01 5.241094622e-02 9.056360938e-04 8.508366973e-03
118 5.945719951e-01 4.026768331e-01 1.153763791e-03 1.597408009e-03
119 8.661035150e-01 1.131663585e-01 1.198198109e-03 1.953192838e-02
120 6.885759346e-01 2.788275250e-01 2.434966621e-03 3.016157377e-02
121 9.553378104e-01 2.833955708e-02 2.724023038e-06 1.631990846e-02
122 8.296514180e-01 1.492213932e-01 5.822788306e-04 2.054490998e-02
123 8.969195194e-01 9.733411522e-02 1.194159657e-04 5.626949414e-03
124 6.935623922e-01 3.001743457e-01 8.280906725e-05 6.180453122e-03
125 7.712590371e-01 2.116587631e-01 3.976246846e-04 1.668457516e-02
126 7.148883358e-01 9.484852467e-02 4.793961499e-03 1.854691780e-01
127 9.375664030e-01 5.559157465e-02 5.801773787e-04 6.261844954e-03
128 8.170700051e-01 1.384246500e-01 1.863270848e-02 2.587263640e-02
129 5.859668359e-01 5.613942102e-02 8.951196608e-04 3.569986234e-01
130 8.483646852e-01 9.406763171e-02 1.553815690e-04 5.741230150e-02
131 6.654795538e-01 4.980070445e-02 2.745199649e-05 2.846922898e-01
132 7.637131187e-01 1.975737065e-01 2.461224269e-04 3.846705237e-02
133 9.309373703e-01 3.818402939e-02 2.721381380e-04 3.060646217e-02
134 9.298444405e-01 2.013290181e-02 1.092580682e-05 5.001173191e-02
135 7.349206535e-01 2.629215354e-01 1.137078018e-04 2.044103316e-03
136 1.962840797e-04 9.992839744e-01 5.052527155e-04 1.448884334e-05
137 7.352583565e-01 8.923877590e-03 9.568677614e-04 2.548608981e-01
138 9.840078656e-01 3.984714263e-03 9.596974670e-05 1.191145038e-02
139 2.976153720e-02 9.689479607e-01 5.895479564e-05 1.231547293e-03
140 9.187499140e-01 6.892193357e-02 6.821455104e-06 1.232133098e-02
141 6.774503797e-01 3.080690821e-01 1.127128350e-02 3.209254692e-03
142 9.555353498e-01 3.240636077e-02 1.353646685e-03 1.070464274e-02
143 1.862374094e-01 1.392521555e-02 6.658064008e-02 7.332567349e-01
144 3.093383063e-01 4.551932221e-02 4.601934297e-01 1.849489418e-01
145 2.530517054e-01 2.939120443e-02 8.495476181e-04 7.167075425e-01
146 6.931164129e-01 1.634737481e-02 4.006242849e-04 2.901355880e-01
147 4.888025844e-01 1.109361609e-01 1.684861606e-03 3.985763931e-01
148 4.946714380e-01 9.532778786e-02 8.264241863e-03 4.017365323e-01
149 1.125394828e-01 1.206616257e-02 2.235427525e-04 8.751708119e-01
150 1.027090744e-01 1.699940420e-01 7.272729162e-01 2.396744820e-05
151 9.594907769e-01 3.836908512e-02 4.724110814e-04 1.667726917e-03
152 8.215108484e-01 5.159884993e-02 9.268685224e-03 1.176216165e-01
153 8.972206557e-01 7.441518844e-02 4.610861131e-03 2.375329474e-02
154 9.959719111e-01 2.227706494e-03 3.183151622e-04 1.482067231e-03
155 8.790478728e-01 1.235997805e-02 4.769798803e-03 1.038223504e-01
156 9.824202232e-01 1.414738399e-02 5.748145293e-06 3.426644665e-03
157 8.993405442e-01 9.743943620e-02 1.767552513e-04 3.043264306e-03
158 7.029920853e-01 2.681871935e-01 1.236049497e-02 1.646022624e-02
159 6.332022299e-01 3.581717608e-01 1.576575301e-05 8.610243513e-03
160 4.484880614e-04 8.387226966e-04 9.945104956e-01 4.202293594e-03
161 3.400043414e-02 5.596350885e-02 9.026779919e-01 7.358065097e-03
162 4.144570867e-01 3.595212793e-01 3.127702256e-05 2.259903570e-01
163 8.141092175e-01 1.319194625e-01 8.485003113e-04 5.312281966e-02
164 6.717553426e-02 1.263997942e-01 7.490178923e-01 5.740677922e-02
165 9.142275218e-04 9.706273649e-03 9.893736479e-01 5.850914171e-06
166 4.205824325e-01 4.739621338e-01 9.825073200e-02 7.204701681e-03
167 3.541362683e-03 1.990623867e-01 7.900718988e-01 7.324351817e-03
168 1.374551376e-01 7.131787692e-01 1.373912566e-01 1.197483666e-02
169 2.988632334e-01 6.148087347e-01 1.004109558e-03 8.532392240e-02
170 7.902618234e-01 1.614077686e-01 8.071881996e-04 4.752321983e-02
171 1.699315826e-01 8.054555680e-01 4.529097403e-04 2.415993964e-02
172 6.464310056e-01 3.494844486e-01 1.928517755e-03 2.156028016e-03
173 9.532596827e-01 4.528721188e-02 1.762238632e-04 1.276881602e-03
174 8.479995549e-01 1.136988509e-01 9.288578878e-05 3.820870850e-02
175 8.502047219e-01 8.881519632e-02 5.854846714e-05 6.092153335e-02
176 4.059545259e-01 5.688141367e-01 5.552332550e-04 2.467610413e-02
177 9.571204228e-01 2.523527394e-02 4.624104423e-05 1.759806222e-02
178 8.482745868e-01 7.030235855e-02 7.633093795e-03 7.378996082e-02
179 3.806936632e-01 5.783214624e-01 1.129601889e-03 3.985527243e-02
180 5.943510066e-01 2.221272287e-01 1.277148503e-02 1.707502797e-01
181 1.839472481e-01 8.039265740e-01 6.843927954e-05 1.205773865e-02
182 6.453958409e-01 3.274990468e-01 6.638617288e-05 2.703872609e-02
183 1.366362490e-01 8.608602693e-01 1.079096962e-03 1.424384825e-03
184 2.462999099e-02 8.542249269e-01 1.079942030e-01 1.315087909e-02
185 2.865455938e-01 6.843375835e-01 2.426812632e-02 4.848696391e-03
186 8.498993502e-01 1.473115784e-01 7.179574081e-04 2.071113981e-03
187 9.505366614e-01 4.238356654e-02 2.512805529e-04 6.828491492e-03
188 7.499580445e-03 5.791083310e-03 7.165033511e-01 2.702059851e-01
189 1.439343773e-02 5.997618402e-02 9.111565968e-01 1.447378141e-02
190 2.996945668e-04 2.220120104e-04 9.994346353e-01 4.365813436e-05
191 8.257100248e-01 1.583541836e-01 2.770130815e-03 1.316566082e-02
192 2.113472365e-02 6.345732985e-01 2.595058049e-01 8.478617294e-02
193 1.229653422e-02 2.838833931e-03 9.756533411e-01 9.211290749e-03
194 1.085572026e-01 4.012585300e-03 1.287313078e-02 8.745570813e-01
195 1.902827395e-02 1.738828499e-03 8.066158844e-01 1.726170131e-01
196 5.429216500e-06 3.594832803e-05 9.986925378e-01 1.266084705e-03
197 4.102980014e-04 5.943276625e-04 9.988611514e-01 1.342229645e-04
198 5.084349731e-03 2.944277073e-02 9.617207982e-01 3.752081316e-03
199 3.252700185e-01 2.977903342e-01 2.326395236e-01 1.443001237e-01
200 1.711322280e-01 1.877054063e-01 5.769458297e-01 6.421653602e-02
201 3.159205049e-04 1.322462117e-03 9.983404786e-01 2.113876877e-05
202 4.855112576e-01 7.778560991e-02 1.569074858e-01 2.797956468e-01
203 7.020444991e-02 6.000913852e-01 3.238064943e-01 5.897670532e-03
204 2.284952417e-05 5.407955947e-04 9.994063226e-01 3.003223453e-05
205 1.001769877e-04 6.852314755e-05 9.997458858e-01 8.541410499e-05
206 2.789747692e-01 5.551991664e-01 1.626480403e-01 3.178024083e-03
207 3.539479790e-03 9.167856783e-03 9.858997931e-01 1.392870353e-03
208 2.498602994e-04 3.330331685e-03 9.964099492e-01 9.858811311e-06
209 8.048320486e-01 9.971882660e-02 7.087192105e-02 2.457720375e-02
210 3.803231417e-04 3.370096459e-04 9.991902908e-01 9.237640558e-05
211 7.085660266e-04 3.357836106e-03 9.957509787e-01 1.826191348e-04
212 3.008294391e-05 3.717977379e-03 9.962074778e-01 4.446192619e-05
213 3.715624814e-03 6.910522383e-03 9.842509539e-01 5.122898888e-03
214 2.568726815e-02 1.496900185e-03 9.722441731e-01 5.716585203e-04
215 2.536108509e-05 8.979544386e-04 9.981623497e-01 9.143347409e-04
216 4.993814573e-02 1.777158987e-01 7.499797184e-01 2.236623716e-02
217 1.402336700e-02 3.963851207e-02 9.422960979e-01 4.042023030e-03
218 1.399132415e-04 1.214354934e-03 9.982352533e-01 4.104785113e-04
219 5.029056836e-03 1.676463535e-02 4.714909995e-05 9.781591587e-01
220 1.283175693e-04 5.966512345e-05 2.466467015e-01 7.531653158e-01
221 2.010384102e-03 9.861727144e-04 2.412027165e-01 7.558007267e-01
222 2.283678934e-07 3.032114513e-07 4.372545316e-08 9.999994247e-01
223 5.644141069e-02 1.484169397e-01 1.113861794e-01 6.837554702e-01
224 1.257763750e-05 2.585447596e-06 1.727889351e-07 9.999846641e-01
225 3.076607713e-02 1.770029772e-03 1.168102426e-02 9.557828688e-01
226 4.918046789e-01 9.669281969e-02 3.725021305e-02 3.742522883e-01
227 7.562449045e-02 3.647615428e-03 5.690105488e-04 9.201588836e-01
228 3.146066392e-02 5.328318365e-03 2.934149364e-03 9.602768684e-01
229 1.743447265e-02 5.958507318e-02 4.102331267e-02 8.819571415e-01
230 1.181381048e-01 4.842685331e-02 2.158132063e-02 8.118537213e-01
231 1.207799743e-02 2.211363353e-02 3.542188391e-02 9.303864851e-01
232 2.575176256e-02 5.606769031e-03 2.733103074e-04 9.683681581e-01
233 2.776127714e-02 5.411628319e-03 3.588832672e-03 9.632382619e-01
234 6.778487938e-01 5.711238574e-02 2.577795981e-03 2.624610245e-01
235 6.816072477e-01 3.645850614e-02 3.084328845e-04 2.816258133e-01
236 1.173750323e-01 2.699472213e-03 3.291482777e-06 8.799222040e-01
237 5.985768287e-01 1.797248360e-01 1.314083278e-01 9.029000756e-02
238 7.474572171e-01 1.635572110e-01 5.340295002e-03 8.364527686e-02
239 5.653863095e-01 1.500082844e-01 8.360896821e-04 2.837693164e-01
240 9.515217655e-01 6.162364375e-03 2.724846478e-05 4.228862167e-02
241 4.260686461e-01 9.314930714e-02 2.743881593e-04 4.805076586e-01
242 9.746154800e-01 2.059231883e-02 8.146565033e-06 4.784054586e-03
243 9.045677769e-01 8.856575439e-02 2.550697967e-04 6.611398920e-03
244 6.978364770e-02 7.153033515e-02 4.631561588e-05 8.586397015e-01
245 9.494355260e-01 4.979839219e-02 1.626523905e-05 7.498165965e-04
246 8.464674535e-01 1.369476282e-01 3.557976556e-04 1.622912068e-02
247 5.197162690e-01 2.784668329e-01 2.088349010e-02 1.809334080e-01
248 1.473257290e-01 5.759190343e-03 3.416740888e-02 8.127476717e-01
249 3.430818779e-02 6.669763557e-03 1.280825273e-02 9.462137959e-01
250 4.368874218e-03 5.505365547e-04 3.292703603e-05 9.950476622e-01
 [ reached getOption("max.print") -- omitted 14 rows ]

$terms
spp ~ hw + hl + td + ew + tl + sl + fl + end + nsd + iod + ind + 
    dsa
attr(,"variables")
list(spp, hw, hl, td, ew, tl, sl, fl, end, nsd, iod, ind, dsa)
attr(,"factors")
    hw hl td ew tl sl fl end nsd iod ind dsa
spp  0  0  0  0  0  0  0   0   0   0   0   0
hw   1  0  0  0  0  0  0   0   0   0   0   0
hl   0  1  0  0  0  0  0   0   0   0   0   0
td   0  0  1  0  0  0  0   0   0   0   0   0
ew   0  0  0  1  0  0  0   0   0   0   0   0
tl   0  0  0  0  1  0  0   0   0   0   0   0
sl   0  0  0  0  0  1  0   0   0   0   0   0
fl   0  0  0  0  0  0  1   0   0   0   0   0
end  0  0  0  0  0  0  0   1   0   0   0   0
nsd  0  0  0  0  0  0  0   0   1   0   0   0
iod  0  0  0  0  0  0  0   0   0   1   0   0
ind  0  0  0  0  0  0  0   0   0   0   1   0
dsa  0  0  0  0  0  0  0   0   0   0   0   1
attr(,"term.labels")
 [1] "hw"  "hl"  "td"  "ew"  "tl"  "sl"  "fl"  "end" "nsd" "iod" "ind" "dsa"
attr(,"order")
 [1] 1 1 1 1 1 1 1 1 1 1 1 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
attr(,"predvars")
list(spp, hw, hl, td, ew, tl, sl, fl, end, nsd, iod, ind, dsa)
attr(,"dataClasses")
        spp          hw          hl          td          ew          tl          sl 
"character" "nmatrix.1" "nmatrix.1" "nmatrix.1" "nmatrix.1" "nmatrix.1" "nmatrix.1" 
         fl         end         nsd         iod         ind         dsa 
"nmatrix.1" "nmatrix.1" "nmatrix.1" "nmatrix.1" "nmatrix.1" "nmatrix.1" 

$call
lda(formula = spp ~ hw + hl + td + ew + tl + sl + fl + end + 
    nsd + iod + ind + dsa, data = feinmorph, CV = TRUE)

$xlevels
named list()
table(feinmorph$spp,feinmorphjac.lda$class)
      
        rk rpa rpi rsph
  rk   147   5   2    3
  rpa   15  10   5    0
  rpi    4   3  23    1
  rsph  16   0   0   30

Use Borcard code to get props correct

feinmorphjac.class <- feinmorphjac.lda$class
feinmorphjac.table <- table(feinmorph$spp, feinmorphjac.class)
diag(prop.table(feinmorphjac.table,1))
          rk          rpa          rpi         rsph 
0.9363057325 0.3333333333 0.7419354839 0.6521739130 

Use DAAG confusion to get overall accuracy

confusion(feinmorphjac.lda$class,feinmorph$spp)
Overall accuracy = 0.795 

Confusion matrix 
      Predicted (cv)
Actual    rk   rpa   rpi  rsph
  rk   0.808 0.082 0.022 0.088
  rpa  0.278 0.556 0.167 0.000
  rpi  0.067 0.167 0.767 0.000
  rsph 0.088 0.000 0.029 0.882

LDA

feinmorph.lda <- lda(spp~hw+hl+td+ew+tl+sl+fl+end+nsd+iod+ind+dsa, data=feinmorph)
print(feinmorph.lda)
Call:
lda(spp ~ hw + hl + td + ew + tl + sl + fl + end + nsd + iod + 
    ind + dsa, data = feinmorph)

Prior probabilities of groups:
          rk          rpa          rpi         rsph 
0.5946969697 0.1136363636 0.1174242424 0.1742424242 

Group means:
                 hw             hl             td            ew            tl
rk    0.08366676407 -0.03256675401  0.19707719895 -0.2471177720 -0.1837570463
rpa  -0.37189624782 -0.44520646541 -0.79330376345 -0.6000968296 -0.2106351906
rpi   0.18124952434 -0.05423267477 -0.28486193396  1.0944275180  0.5780074792
rsph -0.16516369085  0.43805189696  0.03671114395  0.4972422180  0.3750147856
                sl              fl           end           nsd           iod
rk   -0.1118112827 -0.006001005087 -0.2440088137 -0.1441491720  0.2796864871
rpa  -0.3019019106 -0.519708216901 -0.2210177611 -0.4383476579 -0.4208466581
rpi   0.5898685171  0.284031363375  0.3453905402  0.9233869697 -0.4624832717
rsph  0.1809892319  0.168009392197  0.7441915183  0.1555837756 -0.3684434197
                 ind           dsa
rk    0.002543489752  0.2006092493
rpa  -0.192988484707  0.0297115768
rpi   0.525260821320  0.4523707498
rsph -0.236799104583 -1.0089237540

Coefficients of linear discriminants:
                LD1             LD2            LD3
hw   0.005124574332  3.219607692568  3.09549965468
hl  -1.391561904148 -3.193657027257 -3.29366321185
td  -0.885275548531 -0.303543506213  0.66744309246
ew   0.706555098263 -0.135985982928  0.90487749362
tl   0.163823950975 -0.148065963695 -0.73714229434
sl   2.015825001259  1.230385548137 -0.85788736299
fl  -0.282281342005 -0.511230356880  1.23286785559
end  0.036033396184 -0.885369973881 -0.04145115345
nsd  0.458025297262  0.146626309193  0.56435205331
iod -0.450597709122 -0.006453278738  0.25655765625
ind -0.060662032332  0.534206402647 -0.34572487519
dsa -0.254631227889 -0.896795086161 -1.64154585681

Proportion of trace:
   LD1    LD2    LD3 
0.5959 0.3044 0.0996 
# get predictions from this LDA
feinmorph.pred <- predict(feinmorph.lda)
table(feinmorph$spp,feinmorph.pred$class)
      
        rk rpa rpi rsph
  rk   148   5   1    3
  rpa   14  11   5    0
  rpi    3   2  25    1
  rsph  14   0   0   32
# plot LDA
plot(feinmorph.lda, dimen=2)

Now analyse acoustic data as for morphology

Diagnostics

# check linearity and distributions
scatterplotMatrix(~crt+cdc+pn+df+tcl+tcr,data=feinacoust,diagonal=list(method='boxplot'))

# standardize variables
feinacoust$crt <- scale(feinacoust$crt)
feinacoust$cdc <- scale(feinacoust$cdc)
feinacoust$pn <- scale(feinacoust$pn)
feinacoust$df <- scale(feinacoust$df)
feinacoust$tcl <- scale(feinacoust$tcl)
feinacoust$tcr <- scale(feinacoust$tcr)
# check var-cov homogeneity
feinacoust.dist <- dist(feinacoust[,-(1:2)])
feinacoust.disp <- betadisper(feinacoust.dist,feinacoust$spp)
permutest(feinacoust.disp)

Permutation test for homogeneity of multivariate dispersions
Permutation: free
Number of permutations: 999

Response: Distances
          Df     Sum Sq    Mean Sq      F N.Perm Pr(>F)  
Groups     4  5.9299388 1.48248470 4.0244    999  0.014 *
Residuals 40 14.7349646 0.36837411                       
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

LDA with jackknife CV

feinacoustjac.lda <- lda(spp~crt+cdc+pn+df+tcl+tcr, CV=TRUE, data=feinacoust)
print(feinacoustjac.lda)
$class
 [1] rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rk   rp   rp   rp  
[17] rp   rsph rsph rsph rsph rsph rsph rsph rsph rsyl rsyl rsyl rsyl rk   rsyl rsyl
[33] rk   rsyl rpal rpal rpal rpal rpal rpal rpal rpal rpal rpal rpal
Levels: rk rp rpal rsph rsyl

$posterior
                 rk              rp            rpal            rsph            rsyl
1   9.999965022e-01 1.741548801e-43 6.237837719e-36 2.120194651e-15 3.497787666e-06
2   9.999900039e-01 2.047805057e-42 7.238754757e-36 1.526276215e-14 9.996054242e-06
3   9.999384711e-01 1.354196665e-42 2.182411295e-36 1.542073472e-14 6.152894517e-05
4   9.999986799e-01 2.358191213e-43 2.172190347e-35 4.665454400e-15 1.320069053e-06
5   9.999935271e-01 1.836561313e-42 8.319776960e-36 1.840695987e-14 6.472851152e-06
6   9.999983046e-01 5.650083933e-44 1.949530515e-35 3.738763492e-15 1.695426428e-06
7   9.999950849e-01 2.616311090e-42 2.251220453e-35 3.635271747e-14 4.915079226e-06
8   9.999944003e-01 2.536091579e-42 1.851921262e-35 6.172997087e-14 5.599729343e-06
9   9.999954560e-01 1.171483418e-45 1.462544203e-35 6.556730819e-16 4.544045296e-06
10  9.999877053e-01 3.204027791e-45 5.927063866e-36 8.159820999e-16 1.229471079e-05
11  9.999989588e-01 2.087590604e-44 3.360953458e-35 1.708181572e-15 1.041215615e-06
12  9.999995530e-01 1.435024571e-39 2.288866142e-33 9.356752746e-12 4.469557268e-07
13  9.999970316e-01 4.307482589e-43 4.979629980e-35 2.444588560e-14 2.968432829e-06
14  2.239323514e-39 1.000000000e+00 4.476319562e-33 2.944645745e-26 5.473386028e-32
15  6.804909671e-33 1.000000000e+00 1.459111546e-22 1.750533514e-21 1.454832712e-25
16  1.298192043e-33 1.000000000e+00 2.881066264e-28 1.909215064e-19 2.254081248e-25
17 3.484004230e-129 1.000000000e+00 1.852215709e-55 1.989244836e-74 1.556504252e-90
18  4.661995573e-10 1.054103029e-30 2.764633868e-33 9.999999960e-01 3.534380920e-09
19  3.559186080e-13 5.790718338e-28 2.935193813e-35 1.000000000e+00 1.142162906e-11
20  2.032295961e-17 4.057207137e-27 1.601762081e-36 1.000000000e+00 7.617734865e-15
21  3.439020182e-16 2.446330299e-27 1.557576718e-40 1.000000000e+00 7.158723187e-15
22  2.699161421e-17 2.254477739e-25 2.716951232e-32 1.000000000e+00 2.324902616e-13
23  3.799424336e-09 1.177664737e-28 4.054677823e-29 9.999998916e-01 1.045684348e-07
24  1.192289920e-13 1.366618684e-29 1.645690243e-31 9.999999998e-01 2.150001983e-10
25  4.969327492e-18 1.870096358e-28 1.929696028e-33 1.000000000e+00 3.181240910e-13
26  1.015747973e-03 3.385606650e-26 1.082441424e-31 2.832547809e-01 7.157294712e-01
27  5.420245541e-08 2.309018507e-32 1.795020745e-38 1.655749288e-08 9.999999292e-01
28  1.334784366e-07 9.549989013e-43 2.729039480e-41 8.128065423e-14 9.999998665e-01
29  3.929939069e-10 4.402127441e-38 1.192836661e-40 2.002128537e-10 9.999999994e-01
30  9.394179971e-01 4.390795144e-31 6.565432663e-33 2.723429552e-09 6.058200023e-02
31  4.897016541e-09 5.879873074e-48 4.167180136e-52 2.582437722e-21 9.999999951e-01
32  9.321038861e-04 1.354681330e-25 1.467401270e-35 1.828115090e-14 9.990678961e-01
33  9.971386329e-01 1.546085540e-32 8.336962026e-34 3.401945016e-12 2.861367141e-03
34  1.911467836e-10 2.904172407e-40 1.230310660e-49 1.305888649e-27 9.999999998e-01
35  2.680493018e-23 6.404405012e-22 1.000000000e+00 3.809024263e-22 8.654511952e-27
36  3.080853987e-36 1.820192451e-23 1.000000000e+00 7.898346139e-30 2.847580184e-37
37  1.495052230e-44 1.186878094e-40 1.000000000e+00 1.603890856e-40 2.220152455e-47
38  1.540190454e-28 3.089248362e-35 1.000000000e+00 1.661196102e-27 1.237405845e-32
39  5.619554016e-36 5.255507555e-38 1.000000000e+00 1.635438536e-32 1.291703961e-40
40  3.814240394e-36 3.452872211e-40 1.000000000e+00 1.807457168e-32 2.250430444e-39
41  2.637969789e-12 1.256704874e-08 9.999999874e-01 1.309897125e-13 5.178669038e-15
42  1.421063656e-53 2.299504447e-53 1.000000000e+00 2.455947887e-64 1.898966097e-62
43  1.342638323e-34 1.227400657e-29 1.000000000e+00 1.758758716e-34 6.087956497e-38
44  1.615868673e-71 6.002323551e-42 1.000000000e+00 2.359366039e-68 9.430976819e-77
45  5.493990821e-34 9.813480264e-33 1.000000000e+00 3.144016392e-36 1.367586471e-37

$terms
spp ~ crt + cdc + pn + df + tcl + tcr
attr(,"variables")
list(spp, crt, cdc, pn, df, tcl, tcr)
attr(,"factors")
    crt cdc pn df tcl tcr
spp   0   0  0  0   0   0
crt   1   0  0  0   0   0
cdc   0   1  0  0   0   0
pn    0   0  1  0   0   0
df    0   0  0  1   0   0
tcl   0   0  0  0   1   0
tcr   0   0  0  0   0   1
attr(,"term.labels")
[1] "crt" "cdc" "pn"  "df"  "tcl" "tcr"
attr(,"order")
[1] 1 1 1 1 1 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
attr(,"predvars")
list(spp, crt, cdc, pn, df, tcl, tcr)
attr(,"dataClasses")
        spp         crt         cdc          pn          df         tcl         tcr 
"character" "nmatrix.1" "nmatrix.1" "nmatrix.1" "nmatrix.1" "nmatrix.1" "nmatrix.1" 

$call
lda(formula = spp ~ crt + cdc + pn + df + tcl + tcr, data = feinacoust, 
    CV = TRUE)

$xlevels
named list()
table(feinacoust$spp,feinacoustjac.lda$class)
      
       rk rp rpal rsph rsyl
  rk   13  0    0    0    0
  rp    0  4    0    0    0
  rpal  0  0   11    0    0
  rsph  0  0    0    8    0
  rsyl  2  0    0    0    7
# use Borcard code to get props correct
feinacoustjac.class <- feinacoustjac.lda$class
feinacoustjac.table <- table(feinacoust$spp, feinacoustjac.class)
diag(prop.table(feinacoustjac.table,1))
          rk           rp         rpal         rsph         rsyl 
1.0000000000 1.0000000000 1.0000000000 1.0000000000 0.7777777778 
# use DAAG confusion to get overall accuracy
confusion(feinacoustjac.lda$class,feinacoust$spp)
Overall accuracy = 0.956 

Confusion matrix 
      Predicted (cv)
Actual    rk rp rpal rsph  rsyl
  rk   0.867  0    0    0 0.133
  rp   0.000  1    0    0 0.000
  rpal 0.000  0    1    0 0.000
  rsph 0.000  0    0    1 0.000
  rsyl 0.000  0    0    0 1.000

LDA

feinacoust.lda <- lda(spp~crt+cdc+pn+df+tcl+tcr, data=feinacoust)
print(feinacoust.lda)
Call:
lda(spp ~ crt + cdc + pn + df + tcl + tcr, data = feinacoust)

Prior probabilities of groups:
           rk            rp          rpal          rsph          rsyl 
0.28888888889 0.08888888889 0.24444444444 0.17777777778 0.20000000000 

Group means:
                crt            cdc            pn            df           tcl
rk   -0.93366042054 -0.93456112953 -0.7541837334  0.3291562592 -1.0047015556
rp    1.94321136783 -0.67132060741  0.7025557871 -0.6684747619  2.1167954452
rpal  0.93766355093 -0.09018089738  1.5619076919 -0.2395369173  0.8979370058
rsph -0.04637642113  1.60215497817 -0.4902710438 -0.4770699299 -0.2820316262
rsyl -0.61983863282  0.33436968438 -0.6960723194  0.5384814676 -0.3363461791
                tcr
rk    0.06289064217
rp   -0.98555665842
rpal -0.89405081849
rsph -0.17818804161
rsyl  1.59830129131

Coefficients of linear discriminants:
               LD1           LD2           LD3           LD4
crt  1.18113259492 -0.2609133133 -0.5610898063  2.0039090041
cdc -0.27842256245  1.1038183018  2.2834805491 -0.8304671236
pn  -4.99586734007 -5.1468681762  0.5727908181 -1.3885255872
df   0.05045751286 -0.5250488622 -0.1796522554 -0.1376678663
tcl -1.15352448536  5.4971090980 -1.5039903366 -1.6905936353
tcr  0.81995616897 -1.0649365468 -1.6867763642 -1.4631540413

Proportion of trace:
   LD1    LD2    LD3    LD4 
0.6118 0.2386 0.1063 0.0433 
# get eigenvalues (prop explained)
feinacoust.lda$svd
[1] 17.972853696 11.223199598  7.493413329  4.780693088
propexp <- feinacoust.lda$svd^2/sum(feinacoust.lda$svd^2)
propexp
[1] 0.61179852122 0.23856554369 0.10634907622 0.04328685887
feinacoust.pred <- predict(feinacoust.lda)
table(feinacoust$spp,feinacoust.pred$class)
      
       rk rp rpal rsph rsyl
  rk   13  0    0    0    0
  rp    0  4    0    0    0
  rpal  0  0   11    0    0
  rsph  0  0    0    8    0
  rsyl  2  0    0    0    7
plot(feinacoust.lda, dimen=2)

Finally, do MANOVAs

morph <- cbind(feinmorph$hw,feinmorph$hl,feinmorph$td,feinmorph$ew,feinmorph$tl,feinmorph$sl,feinmorph$fl,feinmorph$end,feinmorph$nsd,feinmorph$iod,feinmorph$ind,feinmorph$dsa)
feinmorph.man <- manova(morph~spp, data=feinmorph)
summary(feinmorph.man, test="Pillai")
           Df    Pillai  approx F num Df den Df     Pr(>F)    
spp         3 1.1978792 13.903419     36    753 < 2.22e-16 ***
Residuals 260                                                 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
acoust <- cbind(feinacoust$crt,feinacoust$cdc,feinacoust$pn,feinacoust$df,feinacoust$tcl,feinacoust$tcr)
feinacoust.man <- manova(acoust~spp, data=feinacoust)
summary(feinacoust.man, test="Pillai")
          Df   Pillai  approx F num Df den Df     Pr(>F)    
spp        4 3.440885 38.976366     24    152 < 2.22e-16 ***
Residuals 40                                                
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Better graphics

Plots used for QK use the ggplot classic theme, with some tweaks. Tweaks are consolidated into theme_QK; use this theme for figures and tweak the theme to avoid repetitive code changes.

devtools::source_url("https://raw.githubusercontent.com/mjkeough/mjkeough.github.io/refs/heads/main/R/appearance.R")  #Graphics tweaks
ℹ SHA-1 hash of file is "a6df54e0f71bb238af60abd3d8ca755800be0aeb"
lda.data <- cbind(feinmorph, predict(feinmorph.lda)$x)
#Get complex hulls
hull <- 
  lda.data %>%
  group_by(spp) %>% 
  slice(chull(LD1, LD2))
la=c("R.kauffeldi", "R. pipiens", "R. palustris", "R. spheno.", "R. sylvatica")
p1<-ggplot(lda.data, aes(LD1, LD2)) +
  geom_point(aes(shape = spp), show.legend=FALSE, size= ss/2)+
  scale_shape_manual(values=c(0:5))+
  geom_polygon(data=hull, aes(fill = spp,
                   ), color=lc,
               alpha = 0.3,
               show.legend = FALSE)+
  scale_fill_grey(start = 0.4, end = .9)
  
lda2.data <- cbind(feinacoust, predict(feinacoust.lda)$x)
#Get complex hulls
hull2 <- 
  lda2.data %>%
  drop_na() %>%
  group_by(spp) %>% 
  slice(chull(LD1, LD2))
p2<-ggplot(lda2.data, aes(LD1, LD2)) +
  geom_point(aes(shape = spp), size=ss/2)+
  scale_shape_manual(values=c(0:5),
                     name="Species",
                     labels=la,
                     guide =
                         guide_legend(label.theme = element_text(angle = 0, face = "italic", size=6),
                                    title=NULL))+
  labs(y=NULL)+
  geom_polygon(data=hull2, aes(fill = spp,
                   ), colour = "black",
               alpha = 0.3,
               show.legend = FALSE)+
  scale_fill_grey(start = 0.4, end = .9)
   
p3<-p1+p2 & theme_qk()
p3

Colour fig

p1a<-ggplot(lda.data, aes(LD1, LD2, colour=spp)) +
  geom_point(aes(), show.legend=FALSE, size= ss/2)+
  scale_color_viridis_d()+
  geom_polygon(data=hull, aes(fill = spp,
                   ), 
               alpha = 0.3,
               show.legend = FALSE)+
  scale_fill_viridis_d()
  
p2a<-ggplot(lda2.data, aes(LD1, LD2, colour=spp)) +
  geom_point(size=ss/2)+
  scale_color_viridis_d(
                     name="Species",
                     labels=la,
                     guide =
                         guide_legend(label.theme = element_text(angle = 0, face = "italic", size=6),
                                    title=NULL))+
  labs(y=NULL)+
  geom_polygon(data=hull2, aes(fill = spp,
                   ),
               alpha = 0.3,
               show.legend = FALSE)+
  scale_fill_viridis_d()
p3a<-p1a+p2a&theme_qk()   
p3a

LS0tCnRpdGxlOiAiUSAmIEsgQm94IDE1LjQiCm91dHB1dDoKICBodG1sX25vdGVib29rCi0tLQoKYGBge3Igc2V0dXAsIGluY2x1ZGU9RkFMU0V9CmtuaXRyOjpvcHRzX2NodW5rJHNldChlY2hvID0gVFJVRSkKYGBgCgpGZWluYmVyZyBldCBhbC4gKDIwMTQpIGV4YW1pbmVkIG1vcnBob2xvZ2ljYWwsIGdlbmV0aWMsIGFuZCBhY291c3RpYyAoY2FsbCkgY3JpdGVyaWEgaW4gZm91ciBzcGVjaWVzIG9mIGxlb3BhcmQgZnJvZ3MgKCpSYW5hIHNwaGVub2NlcGhhbGEqLCAqUi4gcGlwaWVucyosICpSLiBwYWx1c3RyaXMqLCBhbmQgYSBuZXcgc3BlY2llcyBuYW1lZCAqUi4ga2F1ZmZlbGRpKikgYW5kIGFuIGFjb3VzdGljYWxseSBzaW1pbGFyIGNvbmdlbmVyICpSLiBzeWx2YXRpY2EqIChhY291c3RpYyBjcml0ZXJpYSBvbmx5KS4gRm9yIDI4MyBtdXNldW0gc3BlY2ltZW5zIGFjcm9zcyB0aGUgZmlyc3QgZm91ciBzcGVjaWVzLCB0aGV5IG1lYXN1cmVkIHNpemUgKHNub3V0LXZlbnQgbGVuZ3RoKSBhbmQgMTIgb3RoZXIgbW9ycGhvbG9naWNhbCBjaGFyYWN0ZXJpc3RpY3M6IGhlYWQgbGVuZ3RoLCBoZWFkIHdpZHRoLCBleWUgZGlhbWV0ZXIsIHR5bXBhbnVtIGRpYW1ldGVyLCBmb290IGxlbmd0aCwgZXllIHRvIG5hcmlzIGRpc3RhbmNlLCBuYXJpcyB0byBzb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krCiAgZ2VvbV9wb2x5Z29uKGRhdGE9aHVsbCwgYWVzKGZpbGwgPSBzcHAsCiAgICAgICAgICAgICAgICAgICApLCAKICAgICAgICAgICAgICAgYWxwaGEgPSAwLjMsCiAgICAgICAgICAgICAgIHNob3cubGVnZW5kID0gRkFMU0UpKwogIHNjYWxlX2ZpbGxfdmlyaWRpc19kKCkKICAKcDJhPC1nZ3Bsb3QobGRhMi5kYXRhLCBhZXMoTEQxLCBMRDIsIGNvbG91cj1zcHApKSArCiAgZ2VvbV9wb2ludChzaXplPXNzLzIpKwogIHNjYWxlX2NvbG9yX3ZpcmlkaXNfZCgKICAgICAgICAgICAgICAgICAgICAgbmFtZT0iU3BlY2llcyIsCiAgICAgICAgICAgICAgICAgICAgIGxhYmVscz1sYSwKICAgICAgICAgICAgICAgICAgICAgZ3VpZGUgPQogICAgICAgICAgICAgICAgICAgICAgICAgZ3VpZGVfbGVnZW5kKGxhYmVsLnRoZW1lID0gZWxlbWVudF90ZXh0KGFuZ2xlID0gMCwgZmFjZSA9ICJpdGFsaWMiLCBzaXplPTYpLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aXRsZT1OVUxMKSkrCiAgbGFicyh5PU5VTEwpKwogIGdlb21fcG9seWdvbihkYXRhPWh1bGwyLCBhZXMoZmlsbCA9IHNwcCwKICAgICAgICAgICAgICAgICAgICksCiAgICAgICAgICAgICAgIGFscGhhID0gMC4zLAogICAgICAgICAgICAgICBzaG93LmxlZ2VuZCA9IEZBTFNFKSsKICBzY2FsZV9maWxsX3ZpcmlkaXNfZCgpCnAzYTwtcDFhK3AyYSZ0aGVtZV9xaygpICAgCnAzYQpgYGAK