In geomorph
, the main function for linear models. is
procD.lm
. This module focuses less on most of the results
procD.lm
produces, but focuses more on model comparisons
made available by anova
, maonova.update
, and
comprae.models
.
library(geomorph)
## Loading required package: RRPP
## Loading required package: rgl
## Loading required package: Matrix
data(pupfish) # GPA already performed
As a preliminary step, let’s fit 10 different models with these data.
fit0 <- procD.lm(coords ~ 1,
data = pupfish, iter = 999)
fit1 <- procD.lm(coords ~ log(CS),
data = pupfish, iter = 999)
fit2 <- procD.lm(coords ~ Sex,
data = pupfish, iter = 999)
fit3 <- procD.lm(coords ~ Pop,
data = pupfish, iter = 999)
fit4 <- procD.lm(coords ~ log(CS) + Sex,
data = pupfish, iter = 999)
fit5 <- procD.lm(coords ~ log(CS) + Pop,
data = pupfish, iter = 999)
fit6 <- procD.lm(coords ~ log(CS) * Sex,
data = pupfish, iter = 999)
fit7 <- procD.lm(coords ~ log(CS) * Pop,
data = pupfish, iter = 999)
fit8 <- procD.lm(coords ~ Sex * Pop,
data = pupfish, iter = 999)
fit9 <- procD.lm(coords ~ log(CS) + Sex*Pop,
data = pupfish, iter = 999)
fit10 <- procD.lm(coords ~ log(CS) * Sex*Pop,
data = pupfish, iter = 999)
Model that estimates a mean. \(\mathbf{X}\) is a vector of 1s and \(\hat{\boldsymbol{\beta}}\) is a vector of mean values for each variable.
# Model with just a mean
model.matrix(fit0)
## (Intercept)
## 1 1
## 2 1
## 3 1
## 4 1
## 5 1
## 6 1
## 7 1
## 8 1
## 9 1
## 10 1
## 11 1
## 12 1
## 13 1
## 14 1
## 15 1
## 16 1
## 17 1
## 18 1
## 19 1
## 20 1
## 21 1
## 22 1
## 23 1
## 24 1
## 25 1
## 26 1
## 27 1
## 28 1
## 29 1
## 30 1
## 31 1
## 32 1
## 33 1
## 34 1
## 35 1
## 36 1
## 37 1
## 38 1
## 39 1
## 40 1
## 41 1
## 42 1
## 43 1
## 44 1
## 45 1
## 46 1
## 47 1
## 48 1
## 49 1
## 50 1
## 51 1
## 52 1
## 53 1
## 54 1
## attr(,"assign")
## [1] 0
coef(fit0)
## [,1] [,2] [,3] [,4] [,5]
## (Intercept) -0.03947932 -0.07058758 -0.04146458 -0.03712504 0.09922309
## [,6] [,7] [,8] [,9] [,10] [,11]
## (Intercept) -0.07049983 -0.1740486 -0.002957713 0.04114024 0.05831862 0.1639149
## [,12] [,13] [,14] [,15] [,16] [,17]
## (Intercept) 0.02669391 0.2288507 0.01808171 0.2260918 -0.04801046 0.139466
## [,18] [,19] [,20] [,21] [,22]
## (Intercept) -0.05252247 -0.1324619 -0.0001930238 -0.159502 0.00806991
## [,23] [,24] [,25] [,26] [,27] [,28]
## (Intercept) -0.1474583 0.01609122 -0.1338297 0.0232014 -0.1194645 0.02907278
## [,29] [,30] [,31] [,32] [,33] [,34]
## (Intercept) -0.1046493 0.03450391 -0.08994229 0.0395097 -0.07434372 0.04479319
## [,35] [,36] [,37] [,38] [,39]
## (Intercept) -0.05872061 0.04954165 -0.04274082 0.05352692 -0.02598984
## [,40] [,41] [,42] [,43] [,44] [,45]
## (Intercept) 0.05648326 -0.008025095 0.05898195 0.01017487 0.05963072 0.02772749
## [,46] [,47] [,48] [,49] [,50] [,51]
## (Intercept) 0.05925944 0.05916601 0.05375747 0.07445374 0.0489664 0.0894286
## [,52] [,53] [,54] [,55] [,56] [,57]
## (Intercept) 0.04428606 0.1041109 0.0397228 0.1188267 0.03558288 0.1337509
## [,58] [,59] [,60] [,61] [,62] [,63]
## (Intercept) 0.03190393 0.148857 0.02911721 0.179124 0.0241227 0.194327
## [,64] [,65] [,66] [,67] [,68] [,69]
## (Intercept) 0.02136462 0.2103038 0.01896472 0.2136785 -0.04725024 0.2003582
## [,70] [,71] [,72] [,73] [,74] [,75]
## (Intercept) -0.04734453 0.1867839 -0.04822661 0.1722217 -0.04936049 0.1571274
## [,76] [,77] [,78] [,79] [,80]
## (Intercept) -0.05064406 -0.05505139 -0.00244577 -0.05289621 -0.01294389
## [,81] [,82] [,83] [,84] [,85]
## (Intercept) -0.05428773 -0.02536192 -0.06012081 -0.03814639 -0.06708141
## [,86] [,87] [,88] [,89] [,90]
## (Intercept) -0.04970174 -0.07499675 -0.05976109 -0.08502768 -0.06742116
## [,91] [,92] [,93] [,94] [,95]
## (Intercept) -0.0962085 -0.07103283 -0.1087612 -0.07010192 -0.1174578
## [,96] [,97] [,98] [,99] [,100] [,101]
## (Intercept) -0.06619454 -0.1316305 0.0178822 -0.1192173 0.01503803 -0.1115179
## [,102] [,103] [,104] [,105] [,106] [,107]
## (Intercept) 0.003145581 -0.1164532 -0.0119135 -0.1328963 -0.0194042 -0.1476051
## [,108] [,109] [,110] [,111] [,112]
## (Intercept) -0.01407205 -0.1516787 0.0005246936 -0.1440986 0.01308347
Model that estimates an intercept and a slope. \(\mathbf{X}\) comprises a vector of 1s and a vector of \(\log CS\). The coefficients comprise a (row) vector of intercept values and a (row) vector of slopes.
# Linear regression model
model.matrix(fit1)
## (Intercept) log(CS)
## 1 1 4.154712
## 2 1 4.189849
## 3 1 4.178185
## 4 1 4.228929
## 5 1 4.231914
## 6 1 4.288120
## 7 1 4.299237
## 8 1 4.267156
## 9 1 4.255943
## 10 1 4.254117
## 11 1 4.268744
## 12 1 4.304089
## 13 1 4.344199
## 14 1 4.303967
## 15 1 4.278805
## 16 1 4.349534
## 17 1 4.291258
## 18 1 4.185563
## 19 1 4.417932
## 20 1 4.408862
## 21 1 4.440260
## 22 1 4.424408
## 23 1 4.494542
## 24 1 4.524390
## 25 1 4.504465
## 26 1 4.507662
## 27 1 4.500064
## 28 1 4.538890
## 29 1 4.551579
## 30 1 3.848473
## 31 1 4.005189
## 32 1 4.054256
## 33 1 4.094385
## 34 1 4.106701
## 35 1 4.155869
## 36 1 4.132023
## 37 1 4.267254
## 38 1 4.217074
## 39 1 4.300586
## 40 1 4.291636
## 41 1 4.302187
## 42 1 4.058998
## 43 1 4.201192
## 44 1 4.236339
## 45 1 4.145057
## 46 1 4.191392
## 47 1 4.156158
## 48 1 4.279115
## 49 1 4.352771
## 50 1 4.305489
## 51 1 4.422570
## 52 1 4.456126
## 53 1 4.407286
## 54 1 4.365958
coef(fit1)
## [,1] [,2] [,3] [,4] [,5]
## (Intercept) 0.03825649 0.01443957 -0.002678365 0.08096039 0.122217596
## log(CS) -0.01814519 -0.01984714 -0.009053525 -0.02756364 -0.005367406
## [,6] [,7] [,8] [,9] [,10]
## (Intercept) -0.0009258683 -0.23049949 -0.012609131 0.11413850 -0.03037454
## log(CS) -0.0162400382 0.01317684 0.002252846 -0.01703934 0.02070286
## [,11] [,12] [,13] [,14] [,15]
## (Intercept) 0.193249954 -0.005993966 0.28227681 0.025391433 0.33060368
## log(CS) -0.006847428 0.007630042 -0.01247079 -0.001706244 -0.02439528
## [,16] [,17] [,18] [,19] [,20]
## (Intercept) 0.03997222 0.1410431572 0.01536798 -0.164982055 -0.0017651836
## log(CS) -0.02053702 -0.0003681431 -0.01584707 0.007590888 0.0003669754
## [,21] [,22] [,23] [,24] [,25]
## (Intercept) -0.177688764 0.04141684 -0.162929804 0.052141367 -0.143324051
## log(CS) 0.004245167 -0.00778388 0.003611383 -0.008414867 0.002216189
## [,26] [,27] [,28] [,29] [,30]
## (Intercept) 0.053460833 -1.196477e-01 0.042622911 -0.097484230 0.0318390316
## log(CS) -0.007063194 4.278015e-05 -0.003162888 -0.001672476 0.0006220396
## [,31] [,32] [,33] [,34] [,35]
## (Intercept) -0.075456857 0.017755375 -0.05521396 0.007934416 -0.035749447
## log(CS) -0.003381207 0.005077921 -0.00446529 0.008603619 -0.005361957
## [,36] [,37] [,38] [,39] [,40]
## (Intercept) -0.003263771 -0.017675488 -0.02190958 -0.003229563 -0.02976172
## log(CS) 0.012325904 -0.005850779 0.01760848 -0.005312731 0.02013141
## [,41] [,42] [,43] [,44] [,45]
## (Intercept) 0.009698986 -0.03404409 0.020199213 -0.03176513 0.03358762
## log(CS) -0.004137176 0.02171425 -0.002339893 0.02133373 -0.00136788
## [,46] [,47] [,48] [,49] [,50]
## (Intercept) -0.02639576 0.045666342 -0.02514907 0.059063934 -0.03044382
## log(CS) 0.01999374 0.003151109 0.01841846 0.003592307 0.01853603
## [,51] [,52] [,53] [,54] [,55]
## (Intercept) 0.076035205 -0.03175017 0.094969342 -0.02927755 0.112105942
## log(CS) 0.003126303 0.01774847 0.002133822 0.01610614 0.001568761
## [,56] [,57] [,58] [,59] [,60]
## (Intercept) -0.03225689 0.1330882963 -0.02466459 0.154063230 -0.01415267
## log(CS) 0.01583524 0.0001546678 0.01320429 -0.001215241 0.01010011
## [,61] [,62] [,63] [,64] [,65]
## (Intercept) 0.189188960 0.002673639 0.206507450 0.008943842 0.224126106
## log(CS) -0.002349366 0.005006664 -0.002843167 0.002899274 -0.003226412
## [,66] [,67] [,68] [,69] [,70]
## (Intercept) 0.0152143282 0.228979003 0.03349991 0.210628465 0.02240807
## log(CS) 0.0008754217 -0.003571456 -0.01884880 -0.002397292 -0.01628174
## [,71] [,72] [,73] [,74] [,75]
## (Intercept) 0.194067981 0.01781062 0.178008594 0.01678886 0.16186241
## log(CS) -0.001700254 -0.01541449 -0.001350789 -0.01544066 -0.00110525
## [,76] [,77] [,78] [,79] [,80]
## (Intercept) 0.009489905 -0.1070788 0.05761028 -0.09851321 -1.257594e-02
## log(CS) -0.014036541 0.0121443 -0.01401835 0.01064797 -8.588881e-05
## [,81] [,82] [,83] [,84] [,85]
## (Intercept) -0.11053510 -0.009680225 -0.10635135 -0.013645336 -0.102520845
## log(CS) 0.01312933 -0.003660439 0.01079119 -0.005719064 0.008272315
## [,86] [,87] [,88] [,89] [,90]
## (Intercept) -0.025432821 -0.107353511 -0.026217704 -0.102085540 -0.02903266
## log(CS) -0.005664881 0.007552753 -0.007829738 0.003981667 -0.00896069
## [,91] [,92] [,93] [,94] [,95]
## (Intercept) -0.0967770816 -0.029213474 -0.10001793 -0.040320448 -0.150778392
## log(CS) 0.0001327181 -0.009761524 -0.00204087 -0.006951627 0.007777729
## [,96] [,97] [,98] [,99] [,100]
## (Intercept) -0.028395032 -0.124682977 0.03685871 -0.1178545528 0.0178681263
## log(CS) -0.008823207 -0.001621689 -0.00442952 -0.0003180866 -0.0006606045
## [,101] [,102] [,103] [,104] [,105]
## (Intercept) -0.117777818 3.235664e-03 -0.109084946 -0.0131304063 -0.128089697
## log(CS) 0.001461196 -2.102713e-05 -0.001719916 0.0002840517 -0.001121962
## [,106] [,107] [,108] [,109] [,110]
## (Intercept) -0.052251548 -0.19877675 -0.06134943 -0.21833315 0.012297710
## log(CS) 0.007667267 0.01194455 0.01103554 0.01555857 -0.002748072
## [,111] [,112]
## (Intercept) -0.170461818 0.049746485
## log(CS) 0.006153741 -0.008557924
Models that estimates group means. \(\mathbf{X}\) comprises a vector of 1s and a vector of a dummy variable. The coefficients comprise a (row) vector of intercept values and a (row) vector of slopes. However, the intercept is one group mean and the slopes are the changes from mean to another, by variable.
# Simple single-factor models
model.matrix(fit2)
## (Intercept) SexM
## 1 1 0
## 2 1 0
## 3 1 0
## 4 1 0
## 5 1 0
## 6 1 0
## 7 1 0
## 8 1 0
## 9 1 0
## 10 1 0
## 11 1 0
## 12 1 0
## 13 1 0
## 14 1 0
## 15 1 0
## 16 1 0
## 17 1 1
## 18 1 1
## 19 1 1
## 20 1 1
## 21 1 1
## 22 1 1
## 23 1 1
## 24 1 1
## 25 1 1
## 26 1 1
## 27 1 1
## 28 1 1
## 29 1 1
## 30 1 0
## 31 1 0
## 32 1 0
## 33 1 0
## 34 1 0
## 35 1 0
## 36 1 0
## 37 1 0
## 38 1 0
## 39 1 0
## 40 1 0
## 41 1 0
## 42 1 1
## 43 1 1
## 44 1 1
## 45 1 1
## 46 1 1
## 47 1 1
## 48 1 1
## 49 1 1
## 50 1 1
## 51 1 1
## 52 1 1
## 53 1 1
## 54 1 1
coef(fit2)
## [,1] [,2] [,3] [,4] [,5]
## (Intercept) -0.036733741 -0.067302377 -0.039831620 -0.034414740 0.100470386
## SexM -0.005702358 -0.006823111 -0.003391536 -0.005629083 -0.002590543
## [,6] [,7] [,8] [,9] [,10]
## (Intercept) -0.06714993 -0.175347434 -0.002229842 0.043091350 0.054787582
## SexM -0.00695749 0.002697649 -0.001511731 -0.004052305 0.007333701
## [,11] [,12] [,13] [,14] [,15]
## (Intercept) 0.165287829 0.026004962 0.229571579 0.019163232 0.22847049
## SexM -0.002851513 0.001430887 -0.001497285 -0.002246238 -0.00494028
## [,16] [,17] [,18] [,19] [,20]
## (Intercept) -0.045465009 0.1396551200 -0.050671046 -0.133392918 -0.0005355697
## SexM -0.005286714 -0.0003927986 -0.003845261 0.001933607 0.0007114415
## [,21] [,22] [,23] [,24] [,25]
## (Intercept) -0.160127486 0.009152435 -0.147965481 0.017144355 -0.1341076765
## SexM 0.001299005 -0.002248322 0.001053427 -0.002187271 0.0005773902
## [,26] [,27] [,28] [,29] [,30]
## (Intercept) 0.024053847 -0.1195602738 0.029787485 -1.046456e-01 0.035092466
## SexM -0.001770477 0.0001990056 -0.001484391 -7.642289e-06 -0.001222381
## [,31] [,32] [,33] [,34] [,35]
## (Intercept) -0.0897824763 0.0397213419 -0.0739835462 0.044361648 -0.058122243
## SexM -0.0003319176 -0.0004395619 -0.0007480432 0.000896282 -0.001242767
## [,36] [,37] [,38] [,39] [,40]
## (Intercept) 0.048366040 -0.042002017 0.051432894 -0.025265652 0.053631480
## SexM 0.002441646 -0.001534428 0.004349134 -0.001504082 0.005922933
## [,41] [,42] [,43] [,44] [,45]
## (Intercept) -0.007448675 0.055476497 0.0104913512 0.056027561 0.0279154915
## SexM -0.001197181 0.007280561 -0.0006572993 0.007483475 -0.0003904684
## [,46] [,47] [,48] [,49] [,50]
## (Intercept) 0.055831770 0.058607006 0.050408105 0.073860555 0.045724126
## SexM 0.007119011 0.001161009 0.006956365 0.001231999 0.006733963
## [,51] [,52] [,53] [,54] [,55]
## (Intercept) 0.0889474576 0.041275105 0.1038581517 0.037201863 0.1187377314
## SexM 0.0009993022 0.006253516 0.0005248365 0.005235793 0.0001847221
## [,56] [,57] [,58] [,59] [,60]
## (Intercept) 0.033409866 0.1338670128 0.030146488 0.1491823324 0.028008529
## SexM 0.004513192 -0.0002411394 0.003650071 -0.0006756606 0.002302644
## [,61] [,62] [,63] [,64] [,65]
## (Intercept) 0.179666712 0.0239198917 0.194995801 0.0216205207 0.211018482
## SexM -0.001127093 0.0004212082 -0.001388973 -0.0005314807 -0.001484271
## [,66] [,67] [,68] [,69] [,70]
## (Intercept) 0.019539127 0.214382463 -0.044626943 0.200842692 -0.04500606
## SexM -0.001192992 -0.001462026 -0.005448384 -0.001006206 -0.00485682
## [,71] [,72] [,73] [,74] [,75]
## (Intercept) 0.1871455691 -0.046212805 0.1725356298 -0.047590223 0.1573761666
## SexM -0.0007511189 -0.004182525 -0.0006520585 -0.003676715 -0.0005166555
## [,76] [,77] [,78] [,79] [,80]
## (Intercept) -0.049104821 -0.056208193 -0.001178452 -0.053655046 -1.291011e-02
## SexM -0.003196878 0.002402594 -0.002632122 0.001576043 -7.016388e-05
## [,81] [,82] [,83] [,84] [,85]
## (Intercept) -0.055112238 -0.0251469940 -0.060790510 -0.0378203172 -0.067755768
## SexM 0.001712442 -0.0004463801 0.001390917 -0.0006772184 0.001400591
## [,86] [,87] [,88] [,89] [,90]
## (Intercept) -0.0493132982 -0.07579265 -0.058931584 -0.085516358 -0.066293000
## SexM -0.0008067668 0.00165302 -0.001722824 0.001014953 -0.002343108
## [,91] [,92] [,93] [,94] [,95]
## (Intercept) -0.0962833661 -0.069450093 -0.1083612710 -0.06885537 -0.12296904
## SexM 0.0001554826 -0.003287223 -0.0008306794 -0.00258899 0.01144638
## [,96] [,97] [,98] [,99] [,100]
## (Intercept) -0.063049773 -0.1314218829 0.0175970330 -0.119728987 0.014474974
## SexM -0.006531449 -0.0004331961 0.0005922723 0.001062801 0.001169424
## [,101] [,102] [,103] [,104] [,105]
## (Intercept) -0.112387643 3.132619e-03 -0.1164043184 -0.0118024213 -0.1328064080
## SexM 0.001806376 2.692159e-05 -0.0001016046 -0.0002307019 -0.0001866952
## [,106] [,107] [,108] [,109] [,110]
## (Intercept) -0.020517088 -0.148986130 -0.015277854 -0.153182892 0.0008330935
## SexM 0.002311384 0.002868302 0.002504352 0.003124155 -0.0006405230
## [,111] [,112]
## (Intercept) -0.1442978111 0.0135287872
## SexM 0.0004138084 -0.0009248828
model.matrix(fit3)
## (Intercept) PopSinkhole
## 1 1 0
## 2 1 0
## 3 1 0
## 4 1 0
## 5 1 0
## 6 1 0
## 7 1 0
## 8 1 0
## 9 1 0
## 10 1 0
## 11 1 0
## 12 1 0
## 13 1 0
## 14 1 0
## 15 1 0
## 16 1 0
## 17 1 0
## 18 1 0
## 19 1 0
## 20 1 0
## 21 1 0
## 22 1 0
## 23 1 0
## 24 1 0
## 25 1 0
## 26 1 0
## 27 1 0
## 28 1 0
## 29 1 0
## 30 1 1
## 31 1 1
## 32 1 1
## 33 1 1
## 34 1 1
## 35 1 1
## 36 1 1
## 37 1 1
## 38 1 1
## 39 1 1
## 40 1 1
## 41 1 1
## 42 1 1
## 43 1 1
## 44 1 1
## 45 1 1
## 46 1 1
## 47 1 1
## 48 1 1
## 49 1 1
## 50 1 1
## 51 1 1
## 52 1 1
## 53 1 1
## 54 1 1
coef(fit3)
## [,1] [,2] [,3] [,4] [,5]
## (Intercept) -0.0398599871 -0.0709967031 -0.0411425925 -0.039632420 0.096921183
## PopSinkhole 0.0008222385 0.0008837093 -0.0006954967 0.005415942 0.004972113
## [,6] [,7] [,8] [,9] [,10]
## (Intercept) -0.0703740053 -0.173529470 -0.000585479 0.038073353 0.0579015303
## PopSinkhole -0.0002717905 -0.001121247 -0.005124025 0.006624474 0.0009009209
## [,11] [,12] [,13] [,14] [,15]
## (Intercept) 0.164073191 0.02798998 0.228056797 0.020236612 0.225865816
## PopSinkhole -0.000341956 -0.00279952 0.001714752 -0.004654587 0.000488197
## [,16] [,17] [,18] [,19] [,20]
## (Intercept) -0.048509211 0.1392642863 -0.054431012 -0.131771396 -0.0004453327
## PopSinkhole 0.001077293 0.0004356902 0.004122457 -0.001491537 0.0005449872
## [,21] [,22] [,23] [,24] [,25]
## (Intercept) -0.160143400 0.008704240 -0.1477440252 0.016277498 -0.1340329058
## PopSinkhole 0.001385341 -0.001370154 0.0006172201 -0.000402349 0.0004389813
## [,26] [,27] [,28] [,29] [,30]
## (Intercept) 0.0233991296 -0.1197719505 0.029678288 -0.105114202 0.035514495
## PopSinkhole -0.0004271066 0.0006641875 -0.001307902 0.001004217 -0.002182859
## [,31] [,32] [,33] [,34] [,35]
## (Intercept) -0.090507319 0.040817061 -0.074849741 0.045919942 -0.05913528
## PopSinkhole 0.001220467 -0.002823897 0.001093015 -0.002433782 0.00089568
## [,36] [,37] [,38] [,39] [,40]
## (Intercept) 0.050581780 -0.0430841560 0.054464859 -0.026210200 0.057069179
## PopSinkhole -0.002246686 0.0007416157 -0.002025946 0.000475978 -0.001265579
## [,41] [,42] [,43] [,44] [,45]
## (Intercept) -0.0081413011 0.0588467126 0.010065924 0.059069827 0.0275976664
## PopSinkhole 0.0002510044 0.0002921174 0.000235331 0.001211519 0.0002804151
## [,46] [,47] [,48] [,49] [,50]
## (Intercept) 0.058587422 0.0587756743 0.052613487 0.0741341001 0.048164306
## PopSinkhole 0.001451564 0.0008431267 0.002470995 0.0006904211 0.001732532
## [,51] [,52] [,53] [,54] [,55]
## (Intercept) 0.0892218996 0.043760375 0.1039968870 0.0395182961 1.188191e-01
## PopSinkhole 0.0004464795 0.001135474 0.0002461618 0.0004417299 1.631373e-05
## [,56] [,57] [,58] [,59] [,60]
## (Intercept) 0.0356840157 0.1338137933 0.03240036 0.1489678775 0.030044181
## PopSinkhole -0.0002184442 -0.0001358308 -0.00107228 -0.0002394645 -0.002002258
## [,61] [,62] [,63] [,64] [,65]
## (Intercept) 0.1793418060 0.02561720 0.1946082699 0.023194839 0.210499254
## PopSinkhole -0.0004703796 -0.00322812 -0.0006074651 -0.003953268 -0.000422109
## [,66] [,67] [,68] [,69] [,70]
## (Intercept) 0.021092051 2.136325e-01 -0.0476757707 2.003334e-01 -0.048019484
## PopSinkhole -0.004595027 9.935283e-05 0.0009191488 5.369584e-05 0.001457896
## [,71] [,72] [,73] [,74] [,75]
## (Intercept) 1.868107e-01 -0.04929900 0.1722696162 -0.050879647 0.1572214789
## PopSinkhole -5.773896e-05 0.00231636 -0.0001035514 0.003281371 -0.0002031963
## [,76] [,77] [,78] [,79] [,80]
## (Intercept) -0.052411872 -0.052621574 -0.003946851 -0.050444328 -0.0129051758
## PopSinkhole 0.003818477 -0.005248398 0.003242335 -0.005296068 -0.0000836309
## [,81] [,82] [,83] [,84] [,85]
## (Intercept) -0.051584503 -0.026212058 -0.057859977 -0.039371694 -0.065301662
## PopSinkhole -0.005838967 0.001836303 -0.004883399 0.002646667 -0.003844253
## [,86] [,87] [,88] [,89] [,90]
## (Intercept) -0.050868440 -0.073988540 -0.060780223 -0.084790271 -0.068017843
## PopSinkhole 0.002520068 -0.002177737 0.002201322 -0.000512797 0.001288828
## [,91] [,92] [,93] [,94] [,95]
## (Intercept) -0.096333262 -0.0708602435 -0.1086895973 -0.069371600 -0.12247018
## PopSinkhole 0.000269477 -0.0003727879 -0.0001547217 -0.001577492 0.01082671
## [,96] [,97] [,98] [,99] [,100]
## (Intercept) -0.063648580 -0.1318158151 0.016848480 -0.119734948 0.014352932
## PopSinkhole -0.005499283 0.0004003695 0.002232839 0.001118188 0.001479812
## [,101] [,102] [,103] [,104]
## (Intercept) -0.1114046871 0.0032020837 -0.1163670315 -0.0121245142
## PopSinkhole -0.0002445537 -0.0001220452 -0.0001862084 0.0004557907
## [,105] [,106] [,107] [,108] [,109]
## (Intercept) -0.1330244090 -0.0192624997 -0.1468767 -0.013334847 -0.150674854
## PopSinkhole 0.0002767192 -0.0003060713 -0.0015734 -0.001592369 -0.002168239
## [,110] [,111] [,112]
## (Intercept) 0.0003168294 -0.143344303 0.012096522
## PopSinkhole 0.0004489866 -0.001629217 0.002131814
Let’s look at this in with just the first 4 variables, so it is easy to visualize
What the unique value of a model matrix look like:
unique(model.matrix(fit2))
## (Intercept) SexM
## 1 1 0
## 17 1 1
Multiply just these unique states by the coefficients.
unique(model.matrix(fit2)) %*% coef(fit2)[,1:4]
## [,1] [,2] [,3] [,4]
## 1 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 17 -0.04243610 -0.07412549 -0.04322316 -0.04004382
Now see how that is replicated for every of \(n\) observations
model.matrix(fit2) %*% coef(fit2)[,1:4]
## [,1] [,2] [,3] [,4]
## 1 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 2 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 3 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 4 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 5 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 6 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 7 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 8 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 9 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 10 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 11 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 12 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 13 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 14 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 15 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 16 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 17 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 18 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 19 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 20 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 21 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 22 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 23 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 24 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 25 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 26 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 27 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 28 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 29 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 30 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 31 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 32 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 33 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 34 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 35 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 36 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 37 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 38 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 39 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 40 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 41 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 42 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 43 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 44 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 45 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 46 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 47 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 48 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 49 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 50 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 51 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 52 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 53 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 54 -0.04243610 -0.07412549 -0.04322316 -0.04004382
Should be the same as what R
gives us if we just
ask.
fitted(fit2)[, 1:4]
## [,1] [,2] [,3] [,4]
## 1 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 2 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 3 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 4 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 5 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 6 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 7 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 8 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 9 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 10 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 11 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 12 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 13 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 14 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 15 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 16 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 17 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 18 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 19 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 20 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 21 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 22 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 23 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 24 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 25 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 26 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 27 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 28 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 29 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 30 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 31 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 32 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 33 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 34 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 35 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 36 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 37 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 38 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 39 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 40 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 41 -0.03673374 -0.06730238 -0.03983162 -0.03441474
## 42 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 43 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 44 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 45 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 46 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 47 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 48 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 49 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 50 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 51 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 52 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 53 -0.04243610 -0.07412549 -0.04322316 -0.04004382
## 54 -0.04243610 -0.07412549 -0.04322316 -0.04004382
The following is a reminder of how ANOVA can do multiple model comparisons, using \(R^2\) and \(F\) as statistics for RRPP.
anova(fit8, effect.type = "Rsq")
##
## Analysis of Variance, using Residual Randomization
## Permutation procedure: Randomization of null model residuals
## Number of permutations: 1000
## Estimation method: Ordinary Least Squares
## Sums of Squares and Cross-products: Type I
## Effect sizes (Z) based on R-squared distributions
##
## Df SS MS Rsq F Z Pr(>R-squared)
## Sex 1 0.015780 0.0157802 0.28012 28.209 4.1985 0.001 **
## Pop 1 0.009129 0.0091294 0.16206 16.320 4.4344 0.001 **
## Sex:Pop 1 0.003453 0.0034532 0.06130 6.173 3.7268 0.001 **
## Residuals 50 0.027970 0.0005594 0.49651
## Total 53 0.056333
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Call: procD.lm(f1 = coords ~ Sex * Pop, iter = 999, data = pupfish)
anova(fit8, effect.type = "F")
##
## Analysis of Variance, using Residual Randomization
## Permutation procedure: Randomization of null model residuals
## Number of permutations: 1000
## Estimation method: Ordinary Least Squares
## Sums of Squares and Cross-products: Type I
## Effect sizes (Z) based on F distributions
##
## Df SS MS Rsq F Z Pr(>F)
## Sex 1 0.015780 0.0157802 0.28012 28.209 4.7773 0.001 **
## Pop 1 0.009129 0.0091294 0.16206 16.320 4.7097 0.001 **
## Sex:Pop 1 0.003453 0.0034532 0.06130 6.173 3.7015 0.001 **
## Residuals 50 0.027970 0.0005594 0.49651
## Total 53 0.056333
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Call: procD.lm(f1 = coords ~ Sex * Pop, iter = 999, data = pupfish)
In case there is some confusion on the model comparisons performed.
reveal.model.designs(fit8)
## Reduced Full
## Sex 1 Sex
## Pop Sex Sex + Pop
## Sex:Pop Sex + Pop Sex + Pop + Sex:Pop <- Null/Full inherent in pairwise
The following is how MANOVA stats can be calculated, by updating the previous model.
fitm <- manova.update(fit8, print.progress = FALSE)
Note that MANOVA statistics were simply appended to previous results.
attributes(fit8)
## $names
## [1] "aov.table" "call" "coefficients" "Y" "X"
## [6] "QR" "fitted" "residuals" "Terms" "term.labels"
## [11] "data" "call" "LM" "ANOVA" "PermInfo"
## [16] "turbo" "Models" "fitted" "residuals" "coefficients"
## [21] "GM"
##
## $class
## [1] "procD.lm" "lm.rrpp"
attributes(fitm)
## $names
## [1] "aov.table" "call" "coefficients" "Y" "X"
## [6] "QR" "fitted" "residuals" "Terms" "term.labels"
## [11] "data" "call" "LM" "ANOVA" "PermInfo"
## [16] "turbo" "Models" "fitted" "residuals" "coefficients"
## [21] "GM" "MANOVA"
##
## $class
## [1] "manova.lm.rrpp" "procD.lm" "lm.rrpp"
MANOVA summaries are provided with the summary
function.
summary(fitm)
##
## Linear Model fit with lm.rrpp
##
## Number of observations: 54
## Number of dependent variables: 112
## Data space dimensions: 53
## Residual covariance matrix rank: 50
## Sums of Squares and Cross-products: Type I
## Number of permutations: 1000
##
## Df Rand Roy Z Pr(>Roy)
## Sex 1 Residuals 17.73326 6.8151620 0.001
## Pop 1 Residuals 50.34889 1.5093978 0.070
## Sex:Pop 1 Residuals 12.71263 -0.5293145 0.706
## Full.Model 3 Residuals 54.35676 8.0972310 0.001
## Residuals 50
summary(fitm, test = "Pillai")
##
## Linear Model fit with lm.rrpp
##
## Number of observations: 54
## Number of dependent variables: 112
## Data space dimensions: 53
## Residual covariance matrix rank: 50
## Sums of Squares and Cross-products: Type I
## Number of permutations: 1000
##
## Df Rand Pillai Z Pr(>Pillai)
## Sex 1 Residuals 0.9466190 4.9765825 0.001
## Pop 1 Residuals 0.9805254 1.3801816 0.070
## Sex:Pop 1 Residuals 0.9270745 -0.3379822 0.706
## Full.Model 3 Residuals 2.8339784 9.6895441 0.001
## Residuals 50
Knowing means are different from ANOVA and MANOVA, it might be advisable to entertain which are different.
group <- interaction(pupfish$Pop, pupfish$Sex)
PW <- pairwise(fit8, groups = group)
Two ways to view the same results:
summary(PW)
##
## Pairwise comparisons
##
## Groups: Marsh.F Sinkhole.F Marsh.M Sinkhole.M
##
## RRPP: 1000 permutations
##
## LS means:
## Vectors hidden (use show.vectors = TRUE to view)
##
## Pairwise distances between means, plus statistics
## d UCL (95%) Z Pr > d
## Marsh.F:Sinkhole.F 0.03302552 0.03312516 1.6124629 0.055
## Marsh.F:Marsh.M 0.04611590 0.04297378 2.3159417 0.007
## Marsh.F:Sinkhole.M 0.03881514 0.04633821 -0.5421145 0.699
## Sinkhole.F:Marsh.M 0.04605211 0.05506197 -0.2523753 0.597
## Sinkhole.F:Sinkhole.M 0.02568508 0.04364031 -2.2111968 0.993
## Marsh.M:Sinkhole.M 0.02802087 0.03343901 0.1854026 0.420
summary(PW, stat.table = FALSE)
##
## Pairwise comparisons
##
## Groups: Marsh.F Sinkhole.F Marsh.M Sinkhole.M
##
## RRPP: 1000 permutations
##
## LS means:
## Vectors hidden (use show.vectors = TRUE to view)
##
## Pairwise distances between means
## Marsh.F Sinkhole.F Marsh.M Sinkhole.M
## Marsh.F 0.00000000 0.03302552 0.04611590 0.03881514
## Sinkhole.F 0.03302552 0.00000000 0.04605211 0.02568508
## Marsh.M 0.04611590 0.04605211 0.00000000 0.02802087
## Sinkhole.M 0.03881514 0.02568508 0.02802087 0.00000000
##
## Pairwise 95% Upper confidence limits between means
## Marsh.F Sinkhole.F Marsh.M Sinkhole.M
## Marsh.F 0.00000000 0.03312516 0.04297378 0.04633821
## Sinkhole.F 0.03312516 0.00000000 0.05506197 0.04364031
## Marsh.M 0.04297378 0.05506197 0.00000000 0.03343901
## Sinkhole.M 0.04633821 0.04364031 0.03343901 0.00000000
##
## Pairwise effect sizes (Z) between means
## Marsh.F Sinkhole.F Marsh.M Sinkhole.M
## Marsh.F 0.0000000 1.6124629 2.3159417 -0.5421145
## Sinkhole.F 1.6124629 0.0000000 -0.2523753 -2.2111968
## Marsh.M 2.3159417 -0.2523753 0.0000000 0.1854026
## Sinkhole.M -0.5421145 -2.2111968 0.1854026 0.0000000
##
## Pairwise P-values between means
## Marsh.F Sinkhole.F Marsh.M Sinkhole.M
## Marsh.F 1.000 0.055 0.007 0.699
## Sinkhole.F 0.055 1.000 0.597 0.993
## Marsh.M 0.007 0.597 1.000 0.420
## Sinkhole.M 0.699 0.993 0.420 1.000
It is difficult to recommend how to use summary.pairwise
until you get into the weeds with your own data. ?pairwise
and ?summary.pairwise
will be helpful for finding ways to
get into trouble, but getting out of trouble is elucidative for how to
handle your data.
The next example shows how to compare slope vectors, which is more involved.
This example uses a model that allows for unique slopes among groups. See if it makes sense how to estimate group-specific shape change For example, which group would this vector, predict? \(\mathbf{x}^T = \begin{bmatrix} 1 & \log \bar{CS} &1 &0 & \log \bar{CS} & 0 & 0 & 0\\ \end{bmatrix}\)
coef(fit10)[, 1:2]
## [,1] [,2]
## (Intercept) -0.057721089 -0.0746659422
## log(CS) 0.005027011 0.0015769700
## SexM 0.110753040 0.0163484503
## PopSinkhole 0.055027507 0.0047875515
## log(CS):SexM -0.026910552 -0.0052742844
## log(CS):PopSinkhole -0.013374747 -0.0007495814
## SexM:PopSinkhole -0.107939865 0.1293217548
## log(CS):SexM:PopSinkhole 0.025728309 -0.0304724204
Notice below how we set up the pairwise object differently.
group <- interaction(pupfish$Pop, pupfish$Sex)
PW <- pairwise(fit10, groups = group,
covariate = log(pupfish$CS))
We have to be very careful with the summary. This summary probably does not make much sense:
summary(PW)
##
## Pairwise comparisons
##
## Groups: Marsh.F Sinkhole.F Marsh.M Sinkhole.M
##
## RRPP: 1000 permutations
##
## LS means:
## Vectors hidden (use show.vectors = TRUE to view)
##
## Pairwise distances between means, plus statistics
## d UCL (95%) Z Pr > d
## Marsh.F:Sinkhole.F 0.03302552 0.03312516 1.6124629 0.055
## Marsh.F:Marsh.M 0.04611590 0.04297378 2.3159417 0.007
## Marsh.F:Sinkhole.M 0.03881514 0.04633821 -0.5421145 0.699
## Sinkhole.F:Marsh.M 0.04605211 0.05506197 -0.2523753 0.597
## Sinkhole.F:Sinkhole.M 0.02568508 0.04364031 -2.2111968 0.993
## Marsh.M:Sinkhole.M 0.02802087 0.03343901 0.1854026 0.420
These find the angle difference between the slopes of the groups.
summary(PW, test.type = "VC")
##
## Pairwise comparisons
##
## Groups: Marsh.F Sinkhole.F Marsh.M Sinkhole.M
##
## RRPP: 1000 permutations
##
## LS means:
## Vectors hidden (use show.vectors = TRUE to view)
##
## Pairwise statistics based on mean vector correlations
## r angle UCL (95%) Z Pr > angle
## Marsh.F:Sinkhole.F 0.9994549 0.03301822 0.03311640 1.6127992 0.055
## Marsh.F:Marsh.M 0.9989374 0.04610426 0.04296275 2.3160257 0.007
## Marsh.F:Sinkhole.M 0.9992470 0.03880898 0.04632979 -0.5424108 0.699
## Sinkhole.F:Marsh.M 0.9989403 0.04604175 0.05504729 -0.2527617 0.597
## Sinkhole.F:Sinkhole.M 0.9996703 0.02568092 0.04362918 -2.2111963 0.993
## Marsh.M:Sinkhole.M 0.9996076 0.02801348 0.03343140 0.1851788 0.420
summary(PW, test.type = "VC", angle.type = "deg")
##
## Pairwise comparisons
##
## Groups: Marsh.F Sinkhole.F Marsh.M Sinkhole.M
##
## RRPP: 1000 permutations
##
## LS means:
## Vectors hidden (use show.vectors = TRUE to view)
##
## Pairwise statistics based on mean vector correlations
## r angle UCL (95%) Z Pr > angle
## Marsh.F:Sinkhole.F 0.9994549 1.891805 1.897430 1.6127992 0.055
## Marsh.F:Marsh.M 0.9989374 2.641580 2.461584 2.3160257 0.007
## Marsh.F:Sinkhole.M 0.9992470 2.223591 2.654501 -0.5424108 0.699
## Sinkhole.F:Marsh.M 0.9989403 2.637998 3.153978 -0.2527617 0.597
## Sinkhole.F:Sinkhole.M 0.9996703 1.471408 2.499768 -2.2111963 0.993
## Marsh.M:Sinkhole.M 0.9996076 1.605054 1.915478 0.1851788 0.420
These find the difference between the length of the slope vectors (difference in the amount of shape change).
summary(PW, test.type = "DL")
##
## Pairwise comparisons
##
## Groups: Marsh.F Sinkhole.F Marsh.M Sinkhole.M
##
## RRPP: 1000 permutations
##
## LS means:
## Vectors hidden (use show.vectors = TRUE to view)
##
## Pairwise absolute difference (d) between vector lengths,
## plus statistics
## d UCL (95%) Z Pr > d
## Marsh.F:Sinkhole.F 6.223616e-05 0.0002511821 -0.507313693 0.696
## Marsh.F:Marsh.M 8.666110e-05 0.0002139602 0.008202522 0.501
## Marsh.F:Sinkhole.M 1.674764e-04 0.0001338737 2.029367621 0.012
## Sinkhole.F:Marsh.M 1.488973e-04 0.0001596997 1.431869663 0.077
## Sinkhole.F:Sinkhole.M 1.052402e-04 0.0001910013 0.629786836 0.279
## Marsh.M:Sinkhole.M 2.541375e-04 0.0001980749 2.040722609 0.011