pak::pkg_install("mlcollyer/RRPP")A follow-up to this post
Where we left off…
The getLSmeans function, used within pairwise was updated to have better memoization. Let’s see how it works now, after we install the updated version.
Data Example
library(geomorph)
# make a latticed cube
vert <- 8
template <- expand.grid(1:vert, 1:vert, 1:vert)
colnames(template) <- c("x", "y", "z")
# Groups
ng <- 10
nw <- 10
group <- factor(rep(1:ng, each = nw))
n <- length(group)
# add points for n specimens
LMlist <- lapply(seq_len(n), function(.){
as.matrix(template + rnorm(length(template),
mean = 0, sd = 0.3))
})GPA
LMa <- simplify2array(LMlist)
GPA <- gpagen(LMa, print.progress = FALSE)
plot(GPA)RRPP
Y <- two.d.array(GPA$coords)
dim(Y)[1] 100 1536
system.time(
{fit1 <- lm.rrpp(Y ~ group,
iter = 999,
Parallel = 1,
turbo = TRUE);
AOV1 <- anova(fit1)}
) user system elapsed
0.173 0.012 0.192
AOV1
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)
group 9 0.11204 0.012448 0.1009 1.1222 0.42806 0.344
Residuals 90 0.99834 0.011093 0.8991
Total 99 1.11037
Call: lm.rrpp(f1 = Y ~ group, iter = 999,
turbo = TRUE, Parallel = 1)
And now for the moment of truth!
system.time(PW <- pairwise(fit1,
groups = group)) user system elapsed
2.074 0.052 2.131
system.time(S1 <- summary(PW)) user system elapsed
0.091 0.002 0.093
S1
Pairwise comparisons
Groups: 1 2 3 4 5 6 7 8 9 10
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
1:2 0.078574607 0.08167040 1.52821015 0.064
1:3 0.098432324 0.08359727 2.09743355 0.013
1:4 0.071414859 0.07870779 1.30324794 0.091
1:5 0.064509941 0.07872720 1.07693023 0.138
1:6 0.099677411 0.08187317 2.09964105 0.013
1:7 0.080720222 0.08073741 1.58740078 0.051
1:8 0.101095926 0.08120902 2.15065784 0.011
1:9 0.114388675 0.08025470 2.69554119 0.002
1:10 0.066486032 0.08346166 1.05420966 0.155
2:3 0.025766106 0.08240749 -0.73409573 0.776
2:4 0.023224912 0.07946718 -0.80198519 0.780
2:5 0.017244004 0.08051551 -1.16715882 0.871
2:6 0.031870895 0.08554038 -0.36110191 0.640
2:7 0.007574997 0.08138419 -1.93076723 0.972
2:8 0.028027118 0.08240491 -0.50743151 0.693
2:9 0.035907863 0.08187794 -0.18618453 0.577
2:10 0.021547147 0.08426699 -0.92666853 0.815
3:4 0.028521355 0.08160216 -0.53821561 0.700
3:5 0.042714723 0.07897872 0.18200918 0.427
3:6 0.044955307 0.08462464 0.22992612 0.415
3:7 0.019658263 0.08149198 -1.09664042 0.853
3:8 0.002664055 0.08051934 -2.58649572 0.997
3:9 0.023255388 0.08275697 -0.91406809 0.809
3:10 0.047286904 0.08324891 0.30527657 0.393
4:5 0.030177955 0.07874557 -0.41609852 0.663
4:6 0.054995188 0.07925584 0.68328950 0.268
4:7 0.018095800 0.08460779 -1.14981450 0.865
4:8 0.031080223 0.08042276 -0.33142038 0.619
4:9 0.049323871 0.08252510 0.42847699 0.338
4:10 0.037313619 0.07929965 -0.06720349 0.536
5:6 0.036688126 0.08069620 -0.07978978 0.540
5:7 0.023250826 0.07863188 -0.79868771 0.780
5:8 0.045084889 0.08012634 0.32304494 0.389
5:9 0.051910543 0.08140889 0.57985790 0.289
5:10 0.007287574 0.08283784 -1.94366532 0.969
6:7 0.037443395 0.08355329 -0.08096422 0.535
6:8 0.045612086 0.07790306 0.36651054 0.371
6:9 0.034955371 0.08339612 -0.21165083 0.572
6:10 0.033245486 0.08193232 -0.27326361 0.604
7:8 0.022150256 0.08053460 -0.88201674 0.792
7:9 0.034223467 0.08169380 -0.26765916 0.605
7:10 0.028500363 0.07834589 -0.60254307 0.724
8:9 0.021736088 0.08039507 -0.88652176 0.780
8:10 0.049487382 0.08335766 0.46208151 0.333
9:10 0.053527888 0.08281461 0.56036110 0.300
An improvement of about 4 seconds!
(i.e., only took 1/3 the previous time)
This might not seem profound but it is worth remembering that the pairwise function is doing more than calculating means. For example, it is also calculating group variances.
system.time(S2 <- summary(PW, test.type = "var")) user system elapsed
0.105 0.001 0.107
S2
Pairwise comparisons
Groups: 1 2 3 4 5 6 7 8 9 10
RRPP: 1000 permutations
Observed variances by group
1 2 3 4 5 6
0.011401783 0.013285562 0.011637595 0.019066232 0.005571209 0.008109551
7 8 9 10
0.009109790 0.006515223 0.007752611 0.007384379
Pairwise distances between variances, plus statistics
d UCL (95%) Z Pr > d
1:2 0.0018837787 0.009386107 -0.51665707 0.695
1:3 0.0002358122 0.009314468 -1.84961666 0.962
1:4 0.0076644484 0.009492552 1.21275430 0.132
1:5 0.0058305738 0.009723652 0.82915045 0.206
1:6 0.0032922324 0.009831855 0.09884225 0.479
1:7 0.0022919928 0.009347964 -0.31571800 0.628
1:8 0.0048865599 0.009350508 0.55189807 0.324
1:9 0.0036491722 0.009435841 0.17750087 0.454
1:10 0.0040174042 0.009279773 0.28118667 0.412
2:3 0.0016479665 0.009322604 -0.68565997 0.760
2:4 0.0057806696 0.009685836 0.76255336 0.250
2:5 0.0077143525 0.009390926 1.23569684 0.112
2:6 0.0051760111 0.009546851 0.59488711 0.293
2:7 0.0041757715 0.009302761 0.35530167 0.385
2:8 0.0067703386 0.009266005 1.03935520 0.166
2:9 0.0055329509 0.009480009 0.69072489 0.261
2:10 0.0059011829 0.009873518 0.77508163 0.244
3:4 0.0074286361 0.009411408 1.14754011 0.136
3:5 0.0060663860 0.009186079 0.90398545 0.204
3:6 0.0035280446 0.009271486 0.18709052 0.444
3:7 0.0025278050 0.009036978 -0.22235545 0.592
3:8 0.0051223721 0.009768389 0.55008927 0.305
3:9 0.0038849844 0.009314009 0.25460803 0.421
3:10 0.0042532164 0.009324560 0.40555002 0.380
4:5 0.0134950221 0.009347566 2.36859599 0.004
4:6 0.0109566807 0.009706382 1.81905664 0.028
4:7 0.0099564411 0.009486714 1.70576009 0.038
4:8 0.0125510083 0.009517332 2.14946201 0.005
4:9 0.0113136205 0.009811268 1.87671167 0.020
4:10 0.0116818525 0.009850539 1.89931875 0.022
5:6 0.0025383414 0.009181609 -0.24952951 0.620
5:7 0.0035385810 0.009252516 0.21188577 0.422
5:8 0.0009440139 0.009596296 -1.09999523 0.842
5:9 0.0021814016 0.009457803 -0.35001328 0.637
5:10 0.0018131696 0.009351355 -0.58370825 0.704
6:7 0.0010002396 0.009285068 -0.98299741 0.822
6:8 0.0015943276 0.009549465 -0.63608739 0.726
6:9 0.0003569398 0.009149024 -1.58903347 0.936
6:10 0.0007251718 0.009393410 -1.29083802 0.891
7:8 0.0025945671 0.009428404 -0.23698861 0.602
7:9 0.0013571794 0.009299577 -0.81492613 0.771
7:10 0.0017254114 0.009453301 -0.56934011 0.701
8:9 0.0012373877 0.009046241 -0.90707325 0.801
8:10 0.0008691557 0.009748551 -1.16423478 0.870
9:10 0.0003682320 0.009797714 -1.67849922 0.946
And vector correlations…
system.time(S3 <- summary(PW, test.type = "VC")) user system elapsed
0.090 0.001 0.090
S3
Pairwise comparisons
Groups: 1 2 3 4 5 6 7 8 9 10
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
1:2 0.9969261 0.078427501 0.08162294 1.52553646 0.064
1:3 0.9951745 0.098279251 0.08352884 2.09580101 0.013
1:4 0.9974615 0.071268486 0.07865724 1.30002330 0.091
1:5 0.9979293 0.064364099 0.07865516 1.07322902 0.138
1:6 0.9950522 0.099517938 0.08181849 2.09798836 0.013
1:7 0.9967557 0.080573025 0.08059412 1.58481376 0.051
1:8 0.9949098 0.100941017 0.08116321 2.14907905 0.011
1:9 0.9934836 0.114223055 0.08020710 2.69422072 0.002
1:10 0.9978003 0.066340765 0.08336721 1.05074718 0.156
2:3 0.9996682 0.025759965 0.08234405 -0.73397396 0.776
2:4 0.9997304 0.023221930 0.07939212 -0.80175171 0.780
2:5 0.9998514 0.017242556 0.08044170 -1.16695931 0.870
2:6 0.9994926 0.031857145 0.08546292 -0.36118925 0.640
2:7 0.9999713 0.007574876 0.08131788 -1.93050144 0.972
2:8 0.9996075 0.028019153 0.08234600 -0.50731756 0.693
2:9 0.9993560 0.035889349 0.08182734 -0.18629125 0.577
2:10 0.9997679 0.021543865 0.08419437 -0.92643789 0.815
3:4 0.9995935 0.028513966 0.08154027 -0.53804860 0.700
3:5 0.9990882 0.042707136 0.07893310 0.18269257 0.427
3:6 0.9989905 0.044937145 0.08454664 0.23021166 0.415
3:7 0.9998069 0.019652238 0.08140745 -1.09663711 0.853
3:8 0.9999965 0.002662219 0.08047195 -2.58615267 0.997
3:9 0.9997300 0.023240301 0.08270868 -0.91451188 0.809
3:10 0.9988826 0.047277481 0.08315753 0.30604804 0.393
4:5 0.9995448 0.030173737 0.07869193 -0.41573778 0.662
4:6 0.9984891 0.054978456 0.07921224 0.68403524 0.268
4:7 0.9998363 0.018092875 0.08449939 -1.14969082 0.865
4:8 0.9995173 0.031071042 0.08036755 -0.33127450 0.619
4:9 0.9987849 0.049302944 0.08247465 0.42879317 0.338
4:10 0.9993042 0.037307483 0.07923984 -0.06667683 0.536
5:6 0.9993276 0.036673855 0.08064303 -0.07969183 0.540
5:7 0.9997297 0.023249264 0.07855858 -0.79831314 0.780
5:8 0.9989843 0.045075478 0.08004769 0.32364748 0.389
5:9 0.9986540 0.051890613 0.08129885 0.58032766 0.289
5:10 0.9999735 0.007285627 0.08278246 -1.94359622 0.968
6:7 0.9992996 0.037429563 0.08342557 -0.08079737 0.535
6:8 0.9989608 0.045592598 0.07784405 0.36677488 0.369
6:9 0.9993899 0.034933751 0.08330951 -0.21195158 0.572
6:10 0.9994479 0.033231244 0.08187713 -0.27326536 0.604
7:8 0.9997549 0.022142406 0.08043263 -0.88208029 0.792
7:9 0.9994151 0.034205030 0.08162950 -0.26782429 0.604
7:10 0.9995940 0.028496963 0.07829558 -0.60217866 0.724
8:9 0.9997641 0.021721842 0.08019883 -0.88694282 0.780
8:10 0.9987763 0.049476136 0.08328041 0.46276801 0.331
9:10 0.9985689 0.053506326 0.08267431 0.56082853 0.300
And standardized vector distances…
system.time(S4 <- summary(PW, test.type = "stdist")) user system elapsed
0.083 0.000 0.083
S4
Pairwise comparisons
Groups: 1 2 3 4 5 6 7 8 9 10
RRPP: 1000 permutations
LS means:
Vectors hidden (use show.vectors = TRUE to view)
Pairwise standardized distances between means, plus statistics
d UCL (95%) Z Pr > d
1:2 1.66820484 1.749460 1.51630895 0.064
1:3 2.08980083 1.797748 2.07097734 0.014
1:4 1.51619739 1.693871 1.29839977 0.089
1:5 1.36960018 1.674342 1.07473842 0.136
1:6 2.11623508 1.757155 2.07577351 0.013
1:7 1.71375805 1.714944 1.57807265 0.052
1:8 2.14635133 1.734228 2.13156084 0.013
1:9 2.42856756 1.722028 2.66039016 0.002
1:10 1.41155424 1.776154 1.05085962 0.152
2:3 0.54703604 1.763764 -0.71837731 0.770
2:4 0.49308438 1.688024 -0.78634471 0.776
2:5 0.36610467 1.724377 -1.15207632 0.870
2:6 0.67664584 1.830964 -0.34570090 0.634
2:7 0.16082354 1.743622 -1.92234265 0.972
2:8 0.59503923 1.768562 -0.49244122 0.682
2:9 0.76235406 1.742970 -0.17315389 0.572
2:10 0.45746402 1.800685 -0.91134953 0.810
3:4 0.60553229 1.741489 -0.52363310 0.700
3:5 0.90686940 1.680507 0.19197706 0.429
3:6 0.95443889 1.803295 0.23896870 0.402
3:7 0.41736142 1.746656 -1.08032634 0.850
3:8 0.05656011 1.719331 -2.59664817 0.997
3:9 0.49373140 1.768666 -0.89832723 0.800
3:10 1.00394064 1.756897 0.31418575 0.389
4:5 0.64070330 1.672016 -0.40169332 0.659
4:6 1.16759399 1.690559 0.68740794 0.265
4:7 0.38418901 1.794263 -1.13533293 0.864
4:8 0.65985921 1.725678 -0.31856800 0.619
4:9 1.04718717 1.776688 0.43601110 0.342
4:10 0.79219945 1.684913 -0.05475130 0.525
5:6 0.77891969 1.709042 -0.06778533 0.537
5:7 0.49363454 1.672339 -0.78472441 0.777
5:8 0.95719003 1.704911 0.33108835 0.382
5:9 1.10210438 1.731915 0.58525473 0.286
5:10 0.15472132 1.754256 -1.93705260 0.968
6:7 0.79495469 1.791513 -0.06789856 0.526
6:8 0.96838285 1.651690 0.37421899 0.365
6:9 0.74213185 1.790348 -0.19863085 0.569
6:10 0.70582957 1.753452 -0.25968780 0.600
7:8 0.47026853 1.718637 -0.86732011 0.791
7:9 0.72659292 1.719409 -0.25407845 0.602
7:10 0.60508661 1.679584 -0.58730111 0.722
8:9 0.46147539 1.727781 -0.87223641 0.778
8:10 1.05065864 1.791663 0.46900932 0.327
9:10 1.13644197 1.774025 0.56580188 0.297
The reason these take practically no time to summarize is because they were all calculated with the initial pairwise use. This is why pairwise will always take longer than lm.rrpp, but as this example shows, it does not mean computational slogs need to be accepted.