vegandevs / vegan

R package for community ecologists: popular ordination methods, ecological null models & diversity analysis
https://vegandevs.github.io/vegan/
GNU General Public License v2.0
442 stars 96 forks source link

Error with ordistep(dbrda) vegan package #670

Closed ParideBalzani closed 1 month ago

ParideBalzani commented 1 month ago

I have an issue when I do a variable selection with a dbrda object.

Here my code:

b<-vegdist(CWM_tot.2[,1:16], method="bray")

dibbierredia.b<-dbrda(b~ ALTITUDE + SLOPE + MICRORELIEF +
                        LITTER + VEGETATION + ROCKS + HEIGHT + DEPTH +
                        pH + C_N + Northerness + Easterness, data= env_tot.3, 
                      strata=site, center=T, scale=T)

ord.null.b<-dbrda(b~1, data=env_tot.3)

ord.sel.b<-ordistep(ord.null.b, scope=formula(dibbierredia.b), direction="forward", permutations = 9999) 

And here the Error:

Error in dimnames(u) <- list(dnam[[1]], c(axnam, negnam)) : 
  length of 'dimnames' [2] not equal to array extent

> traceback()
10: ordConstrain(Y, X, Z)
9: ordConstrained(X, d$Y, d$Z, method = "dbrda")
8: dbrda(formula = b ~ Condition(pH + HEIGHT + C_N + Northerness + 
       Easterness + LITTER) + ROCKS, data = env_tot.3)
7: eval(call, parent.frame())
6: eval(call, parent.frame())
5: update.default(object, fla)
4: update(object, fla)
3: add1.cca(object, scope = scope$add, test = "perm", permutations = permutations, 
       alpha = Pin, trace = trace, ...)
2: add1(object, scope = scope$add, test = "perm", permutations = permutations, 
       alpha = Pin, trace = trace, ...)
1: ordistep(ord.null.b, scope = formula(dibbierredia.b), direction = "forward", 
       permutations = 9999)

Here also the structure of the objects:

> str(b)
 'dist' num [1:3003] 0.146 0.128 0.179 0.164 0.173 ...
 - attr(*, "maxdist")= num 1
 - attr(*, "Size")= int 78
 - attr(*, "Labels")= chr [1:78] "PC_1_02" "PC_1_03" "PC_1_04" "PC_1_05" ...
 - attr(*, "Diag")= logi FALSE
 - attr(*, "Upper")= logi FALSE
 - attr(*, "method")= chr "bray"
 - attr(*, "call")= language vegdist(x = CWM_tot.2[, 1:16], method = "bray")

> str(dibbierredia.b)
List of 13
 $ tot.chi  : num 2.53
 $ Ybar     : num [1:78, 1:78] 0.0483 0.0245 0.0243 0.0213 0.0157 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:78] "PC_1_02" "PC_1_03" "PC_1_04" "PC_1_05" ...
  .. ..$ : chr [1:78] "PC_1_02" "PC_1_03" "PC_1_04" "PC_1_05" ...
  ..- attr(*, "METHOD")= chr "DISTBASED"
 $ method   : chr "dbrda"
 $ call     : language dbrda(formula = b ~ ALTITUDE + SLOPE + MICRORELIEF + LITTER + VEGETATION + ROCKS + HEIGHT +      DEPTH + pH + C_N| __truncated__ ...
 $ pCCA     : NULL
 $ CCA      :List of 13
  ..$ eig        : Named num [1:12] 0.9401 0.2356 0.1018 0.0318 0.0218 ...
  .. ..- attr(*, "names")= chr [1:12] "dbRDA1" "dbRDA2" "dbRDA3" "dbRDA4" ...
  ..$ poseig     : int 8
  ..$ u          : num [1:78, 1:8] -0.1416 -0.2072 -0.1469 -0.0752 -0.0489 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:78] "PC_1_02" "PC_1_03" "PC_1_04" "PC_1_05" ...
  .. .. ..$ : chr [1:8] "dbRDA1" "dbRDA2" "dbRDA3" "dbRDA4" ...
  ..$ v          : logi[0 , 1:8] 
  ..$ wa         : num [1:78, 1:8] -0.2242 -0.1131 -0.1135 -0.0969 -0.0703 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:78] "PC_1_02" "PC_1_03" "PC_1_04" "PC_1_05" ...
  .. .. ..$ : chr [1:8] "dbRDA1" "dbRDA2" "dbRDA3" "dbRDA4" ...
  ..$ alias      : NULL
  ..$ biplot     : num [1:12, 1:8] 0.354 -0.433 -0.229 0.504 0.361 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:12] "ALTITUDE" "SLOPE" "MICRORELIEF" "LITTER" ...
  .. .. ..$ : chr [1:8] "dbRDA1" "dbRDA2" "dbRDA3" "dbRDA4" ...
  ..$ rank       : int 12
  ..$ qrank      : int 12
  ..$ tot.chi    : num 1.29
  ..$ QR         :List of 4
  .. ..$ qr   : num [1:78, 1:12] -8.775 0.0754 0.0736 0.094 0.0677 ...
  .. .. ..- attr(*, "assign")= int [1:12] 1 2 3 4 5 6 7 8 9 10 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : chr [1:78] "PC_1_02" "PC_1_03" "PC_1_04" "PC_1_05" ...
  .. .. .. ..$ : chr [1:12] "ALTITUDE" "SLOPE" "MICRORELIEF" "LITTER" ...
  .. .. ..- attr(*, "scaled:center")= Named num [1:12] 1.18e-16 -1.18e-16 -5.21e-17 2.36e-16 1.78e-16 ...
  .. .. .. ..- attr(*, "names")= chr [1:12] "ALTITUDE" "SLOPE" "MICRORELIEF" "LITTER" ...
  .. ..$ rank : int 12
  .. ..$ qraux: num [1:12] 1.07 1.02 1.11 1.07 1.14 ...
  .. ..$ pivot: int [1:12] 1 2 3 4 5 6 7 8 9 10 ...
  .. ..- attr(*, "class")= chr "qr"
  ..$ envcentre  : Named num [1:12] 1.18e-16 -1.18e-16 -5.21e-17 2.36e-16 1.78e-16 ...
  .. ..- attr(*, "names")= chr [1:12] "ALTITUDE" "SLOPE" "MICRORELIEF" "LITTER" ...
  ..$ imaginary.u: num [1:78, 1:4] -0.279 0.0245 -0.0442 -0.0686 0.1095 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:78] "PC_1_02" "PC_1_03" "PC_1_04" "PC_1_05" ...
  .. .. ..$ : chr [1:4] "idbRDA1" "idbRDA2" "idbRDA3" "idbRDA4"
 $ CA       :List of 7
  ..$ eig        : Named num [1:65] 0.46 0.312 0.258 0.175 0.102 ...
  .. ..- attr(*, "names")= chr [1:65] "MDS1" "MDS2" "MDS3" "MDS4" ...
  ..$ poseig     : int 28
  ..$ u          : num [1:78, 1:28] 0.1273 -0.1221 -0.014 -0.027 0.0489 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:78] "PC_1_02" "PC_1_03" "PC_1_04" "PC_1_05" ...
  .. .. ..$ : chr [1:28] "MDS1" "MDS2" "MDS3" "MDS4" ...
  ..$ v          : logi[0 , 1:28] 
  ..$ rank       : int 65
  ..$ tot.chi    : num 1.24
  ..$ imaginary.u: num [1:78, 1:37] -0.1202 0.0789 0.0485 0.0823 -0.0661 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:78] "PC_1_02" "PC_1_03" "PC_1_04" "PC_1_05" ...
  .. .. ..$ : chr [1:37] "iMDS1" "iMDS2" "iMDS3" "iMDS4" ...
 $ colsum   : logi NA
 $ terms    :Classes 'terms', 'formula'  language b ~ ALTITUDE + SLOPE + MICRORELIEF + LITTER + VEGETATION + ROCKS + HEIGHT + DEPTH + pH +      C_N + Northerness + Easterness
  .. ..- attr(*, "variables")= language list(b, ALTITUDE, SLOPE, MICRORELIEF, LITTER, VEGETATION, ROCKS, HEIGHT, DEPTH, pH, C_N,      Northerness, Easterness)
  .. ..- attr(*, "factors")= int [1:13, 1:12] 0 1 0 0 0 0 0 0 0 0 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : chr [1:13] "b" "ALTITUDE" "SLOPE" "MICRORELIEF" ...
  .. .. .. ..$ : chr [1:12] "ALTITUDE" "SLOPE" "MICRORELIEF" "LITTER" ...
  .. ..- attr(*, "term.labels")= chr [1:12] "ALTITUDE" "SLOPE" "MICRORELIEF" "LITTER" ...
  .. ..- attr(*, "specials")=Dotted pair list of 1
  .. .. ..$ Condition: NULL
  .. ..- attr(*, "order")= int [1:12] 1 1 1 1 1 1 1 1 1 1 ...
  .. ..- attr(*, "intercept")= int 1
  .. ..- attr(*, "response")= int 1
  .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
 $ terminfo :List of 4
  ..$ terms  :Classes 'terms', 'formula'  language ~ALTITUDE + SLOPE + MICRORELIEF + LITTER + VEGETATION + ROCKS + HEIGHT + DEPTH + pH + C_N +      Northerness + Easterness
  .. .. ..- attr(*, "variables")= language list(ALTITUDE, SLOPE, MICRORELIEF, LITTER, VEGETATION, ROCKS, HEIGHT, DEPTH, pH, C_N, Northerness,      Easterness)
  .. .. ..- attr(*, "factors")= int [1:12, 1:12] 1 0 0 0 0 0 0 0 0 0 ...
  .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. ..$ : chr [1:12] "ALTITUDE" "SLOPE" "MICRORELIEF" "LITTER" ...
  .. .. .. .. ..$ : chr [1:12] "ALTITUDE" "SLOPE" "MICRORELIEF" "LITTER" ...
  .. .. ..- attr(*, "term.labels")= chr [1:12] "ALTITUDE" "SLOPE" "MICRORELIEF" "LITTER" ...
  .. .. ..- attr(*, "order")= int [1:12] 1 1 1 1 1 1 1 1 1 1 ...
  .. .. ..- attr(*, "intercept")= int 1
  .. .. ..- attr(*, "response")= num 0
  .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
  ..$ assign : int [1:12] 1 2 3 4 5 6 7 8 9 10 ...
  ..$ xlev   : Named list()
  ..$ ordered: Named logi [1:12] FALSE FALSE FALSE FALSE FALSE FALSE ...
  .. ..- attr(*, "names")= chr [1:12] "ALTITUDE" "SLOPE" "MICRORELIEF" "LITTER" ...
 $ sqrt.dist: logi FALSE
 $ adjust   : num 1
 $ inertia  : chr "squared Bray distance"
 - attr(*, "class")= chr [1:3] "dbrda" "rda" "cca"

There is no correlation among predictors, and they are scaled.

If I remove one variable it works, but I have previously successfully run the same code with another distance matrix (same predictors and code) and it worked perfectly, so I don't understand why this one does not work.

thank you in advance for any help! Paride

jarioksa commented 1 month ago

Unfortunately I cannot reproduce this. Can you prepare a reproducible example?

What is your vegan version?

ParideBalzani commented 1 month ago

Here is a reproducible example:

library(reprex)
#> Warning: package 'reprex' was built under R version 4.3.3
library(vegan)
#> Loading required package: permute
#> Loading required package: lattice
#> This is vegan 2.6-4
library(FD)
#> Loading required package: ade4
#> Loading required package: ape
#> Loading required package: geometry

ant_tot<- data.frame(matrix(NA, nrow = 78, ncol = 25))
rownames(ant_tot)<- paste0("plot", seq_len(78))
colnames(ant_tot)<- paste0("sp", seq_len(25))

ant_tot$sp1<- c(0,0,0,0,0,1,0,0,0,0,2,1,3,0,0,0,0,1,1,0,2,1,1,1,3,3,4,1,2,0,4,1,1,2,4,4,4,3,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,3,0,0,0,0,2,0,1,0,0,0)
ant_tot$sp2<- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,2,0,2,4,0,3,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,4,0,0,4,4,0,0,0,0,0,4,3,3,4,0,4,4,0,1,2)
ant_tot$sp3<- c(1,4,3,4,3,4,0,3,4,4,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,4,0,1,0,0,0,0,0,4,0,3,2,3,0,4,0,3,0,2,4,4,0,0,2,4,0,3,2,1,2,3,1,3,1,1,2,3,0,3,0)
ant_tot$sp4<-c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0)
ant_tot$sp5<- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,4,4,4,4,4,4,4,4,4,2,0,3,4,2,4,4,4,4,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
ant_tot$sp6<- c(0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,1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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
ant_tot$sp25<- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,1,2,0,4,1,1,2,3,4,3,4,4,1,2,4,3,3,2,2,0,0,4,3,0,1,2,0,2,0,0,1,0,0,1,0,0,0,0)

tratti_tot <- data.frame(matrix(NA, nrow = 25, ncol = 8))
rownames(tratti_tot)<- colnames(ant_tot)
colnames(tratti_tot)<- paste0("tr", seq_len(8))

tratti_tot$tr1<- c(2.228,2.068,2.193,1.716,1.679,0.991,1.284,1.303,1.076,0.805,1.026,1.471,1.58,1.185,1.554,1.581,1.742,1.366,1.609,1.09,1.045,1.051,0.873,1.079,0.905)
tratti_tot$tr2<- c(1.995,1.989,1.9,1.616,1.505,0.791,1.152,1.113,0.982,0.481,0.746,1.152,1.213,0.696,1.287,1.272,1.34,1.246,1.283,0.857,0.862,0.917,0.607,0.766,0.682)
tratti_tot$tr3<- c(1.462,1.437,1.477,1.245,1.19,0.828,1.01,1.002,0.871,0.662,0.912,1.097,1.166,0.949,1.132,1.187,1.323,1.133,1.189,0.9,0.778,0.836,0.712,0.836,0.777)
tratti_tot$tr4<- c("Generalist","Sugar","Generalist","Generalist","Generalist","Sugar","Sugar","Sugar","Sugar","Generalist","Generalist","Generalist","Generalist","Generalist","Generalist","Generalist","Generalist","Generalist","Generalist","Generalist","Sugar","Sugar","Generalist","Generalist","Generalist")
tratti_tot$tr5<- c(0,1,0,1,1,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,1,1)
tratti_tot$tr6<- c("Monogyny","Facultative","Polygyny","Facultative","Facultative","Facultative","Polygyny","Monogyny","Monogyny","Polygyny","Facultative","Monogyny","Polygyny","Polygyny","Facultative","Polygyny","Facultative","Polygyny","Monogyny","Monogyny","Polygyny","Polygyny","Monogyny","Monogyny","Monogyny")
tratti_tot$tr7<- c("Facultative","Polydomy","Polydomy","Polydomy","Facultative","Monodomy","Polydomy","Monodomy","Polydomy","Monodomy","Monodomy","Monodomy","Monodomy","Polydomy","Monodomy","Monodomy","Monodomy","Monodomy","Facultative","Monodomy","Polydomy","Polydomy","Monodomy","Polydomy","Monodomy")
tratti_tot$tr8<- c("Independent","Dependent","Independent","Independent","Dependent","Independent","Dependent","Independent","Independent","Dependent","Dependent","Facultative","Facultative","Facultative","Facultative","Facultative","Facultative","Facultative","Facultative","Independent","Dependent","Dependent","Independent","Independent","Independent")

tratti_tot$tr4<-as.factor(tratti_tot$tr4)
tratti_tot$tr5<-as.factor(tratti_tot$tr5)
tratti_tot$tr6<-as.factor(tratti_tot$tr6)
tratti_tot$tr7<-as.factor(tratti_tot$tr7)
tratti_tot$tr8<-as.factor(tratti_tot$tr8)

data_ant<-as.matrix(ant_tot)

CWM_tot <- functcomp(tratti_tot, data_ant, CWM.type = "all")

CWM_tot.2 <- CWM_tot
CWM_tot.2$fascia<-c("1", "1", "1", "1", "1", "1", "1", "1", "1","1", 
                    "2", "2", "2", "2", "2", "2","2", "2", "2", 
                    "3", "3", "3", "3", "3", "3", "3", "3", "3", 
                    "4", "4", "4", "4", "4", "4", "4", "4", "4", "4",
                    "1", "1", "1", "1", "1", "1", "1", "1", "1","1", 
                    "2", "2", "2", "2", "2", "2","2", "2", "2", "2", 
                    "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", 
                    "4", "4", "4", "4", "4", "4", "4", "4", "4", "4")
CWM_tot.2$fascia<- as.factor(CWM_tot.2$fascia)

CWM_tot.2$site <- c(rep("site1", 38),  rep("site2", 40))
CWM_tot.2$site<- as.factor(CWM_tot.2$site)

env_tot<- data.frame(matrix(NA, nrow = 78, ncol = 12))
rownames(env_tot)<- rownames(ant_tot)
colnames(env_tot)<- c("ALTITUDE", "SLOPE", "MICRORELIEF", "LITTER", "VEGETATION", 
                      "ROCKS", "HEIGHT", "DEPTH", "pH", "C_N", "Northerness", "Easterness")

env_tot$ALTITUDE<- c(1640,1661,1657,1702,1644,1742,1717,1746,1677,1721,1453,1426,1480,1399,1440,1399,1408,1396,1481,1340,1264,1267,1300,1312,1287,1326,1233,1334,1188,1035,1207,1185,1124,1057,1149,1102,1150,1169,1859,1907,1984,1862,1953,1890,1924,1922,1921,1872,1678,1678,1733,1774,1723,1729,1713,1784,1727,1761,1425,1399,1417,1407,1402,1391,1408,1417,1419,1582,1239,1251,1276,1322,1347,1326,1333,1361,1339,1353)
env_tot$SLOPE <- c(43,30,30,40,35,30,32,30,34,47,44,40,30,40,35,30,30,30,20,20,20,30,40,20,20,35,30,25,25,10,30,40,40,24,20,20,15,28,28,10,19,28,20,32,40,20,20,30,10,18,28,15,30,30,37,20,30,42,20,8,30,15,20,0,15,30,10,20,15,20,30,40,7,20,15,10,10,20)
env_tot$MICRORELIEF <- c(11,13,21,20,31,20,17,25,20,29,14,9,8,15,13,19,15,8,12,12,18,26,24,20,15,23,19,15,16,11,30,40,25,12,12,22,23,18,9,7,20,9,10,17,14,17.5,5,9,2,8,5,4,18,9,35,14,18,3,25,15,17,12,15,18,9,21,17,15,5,8,13,17,8,16,13,15,12,14)
env_tot$LITTER <- c(96,40,60,80,45,75,75,40,75,55,95,99,95,50,98,75,45,95,85,70,1,90,90,5,50,85,90,3,80,97,90,70,50,70,70,85,80,75,97,40,85,75,90,45,90,65,50,50,98,95,95,75,70,95,65,90,70,100,100,100,100,85,40,100,100,100,100,65,100,96,100,100,98,100,100,100,100,95)
env_tot$VEGETATION <- c(90,90,80,75,90,70,67,75,67,50,90,95,93,100,96,100,95,90,80,65,30,90,90,65,95,80,90,60,95,90,90,95,65,75,95,95,100,85,95,85,95,70,95,60,80,80,98,75,80,75,75,90,75,85,85,85,90,90,95,100,95,75,70,80,85,95,95,100,100,100,90,85,90,95,100,98,90,95)
env_tot$ROCKS <- c(25,15,40,30,10,50,30,30,40,70,5,4,7,10,5,0,2,3,30,40,20,2,5,10,5,8,18,60,0,6,0,0,45,35,15,1,0,1,15,1,5,0,0,75,0,0,0,0,0,1,0,5,45,45,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0)
env_tot$HEIGHT <- c(39.4,15.2,24.2,21.6,25.4,24.2,32.6,19.8,11.8,24,30.4,32.8,27.6,39.4,31.4,35.6,30.6,29.4,28.2,20.2,26.6,34.4,26.8,25,28.6,17.8,16.8,33.4,26.4,40.4,32.2,30.2,27.8,48.2,40.2,30.6,35.6,30.2,19.2,16.2,16.8,16.2,12.8,20,23.2,15,12.3,14.2,32.6,41.8,21.6,15.4,28.2,32.4,23.2,15.6,37.2,34.6,58.2,92.6,56.2,56.6,37.8,53.2,40.8,50.6,49.8,26.8,45.4,54.6,46.2,46.4,42.8,50,49.4,48.2,46,42.6)
env_tot$DEPTH <- c(19.8,8,9.4,3,15.8,5.6,11.2,4.8,10,7.8,15,23.2,24.8,40.4,7.4,21.4,17,17.2,8.4,6.4,15.2,22,18.2,17,37.2,26.4,5.4,6.8,26.4,11.2,19.4,27,3.2,14.4,4.6,12.2,22.4,20.2,19,16.8,26.4,36.6,30,11.6,28,34.2,22.8,34.8,26.6,34,34,13.8,5.2,11.6,40.4,27.4,22,28.4,27.4,33.4,39.9,17.4,18.4,33.6,38.2,48.4,28.6,33.4,46,47,35.2,22.2,41.6,21.2,53.6,38.4,37,57.2)
env_tot$pH <- c(7.09,6.91,6.51,5.82,5.16,5.13,6.84,5.53,6.58,6.8,6.56,6.75,5.53,5.69,5.68,5.06,6.7,7.35,7.34,7.31,7.71,5.52,5.71,7.73,5.45,6.82,7.54,6.98,7.01,7.6,7.04,5.55,7.35,6.95,7.09,6.82,7.05,6.92,4.6,4.21,4.43,4.08,4.26,4.63,4.45,4.02,3.79,3.76,4.08,4.28,4.05,4.14,5.33,6.01,4.95,4.15,3.88,4.57,4.51,4.47,4.65,5.53,4.94,4.64,4.41,4.49,4.55,4.44,4.92,5.33,6.09,5.07,4.39,4.04,4.52,4.61,4.15,4.52)
env_tot$C_N <- c(9.9317647127757,9.07590623486224,7.51433132471259,9.1979283096896,9.97149694838346,11.661431647422,9.8479669328786,10.2559908190182,9.80655042066058,10.0333732982956,10.0476300660018,10.5900118749961,8.38873237078218,10.5731314202627,12.4618106235287,12.9127609597884,7.66553088572237,13.6409072323435,11.3326485535448,12.8496807732952,9.68427368651668,13.203335610773,11.8142434122683,6.75824349786527,11.7062377027595,3.83784554883534,10.7878941313131,11.1575366845919,10.2787502327992,12.3409002800254,11.0707995525736,12.4837031508761,11.4859245219589,5.9286643535668,11.5939705062939,12.1468754480496,10.9453282058355,10.5608091738822,12.7977588899141,13.5625356938892,9.50542596124335,13.2603809539321,15.2199602320537,9.47123306008305,13.4961257665475,14.6220704174749,14.1634085982676,14.2153613338162,9.9491369044148,11.5440174851785,15.4755576598194,13.0056205588768,14.0872120948374,14.2517839565214,12.8274067319351,12.7885828210575,12.0039060192172,11.662936396241,10.5400666433773,11.8572940295238,13.6727757705085,10.1607012859428,10.1452956496494,9.79661482429789,12.7252001747315,11.9510012537688,11.3845530285972,13.0031938933471,12.8548941477065,10.2661184022007,12.0318724085839,10.4480035965479,11.0863477034558,12.438707761121,11.1587693369191,10.5426283644628,10.2519128101179,11.431073347874)
env_tot$Northerness <- c(0.406736643075801,0.17364817766693,-1.83690953073357e-16,-0.642787609686539,-1.83690953073357e-16,0.5,-0.342020143325669,-0.642787609686539,0.309016994374947,-0.642787609686539,-0.544639035015027,-0.629320391049837,0.342020143325668,-0.642787609686539,-0.17364817766693,1,-0.809016994374948,0.848048096156425,0.342020143325668,0.156434465040231,-0.766044443118978,0.5,0.17364817766693,-0.642787609686539,0.342020143325668,0.17364817766693,0.342020143325668,-0.939692620785908,-0.642787609686539,-0.913545457642601,-0.939692620785908,-0.939692620785908,-0.939692620785908,-1,-0.939692620785908,-1,-0.342020143325669,-0.994521895368273,0.17364817766693,-0.939692620785908,-0.939692620785908,-0.719339800338651,-0.766044443118978,-0.939692620785908,-0.984807753012208,-0.984807753012208,-0.939692620785908,-0.90630778703665,-0.766044443118978,-0.0697564737441256,-0.139173100960065,0.17364817766693,-0.939692620785908,0.17364817766693,-0.939692620785908,-0.939692620785908,-0.984807753012208,-0.275637355816999,-0.190808995376545,-0.342020143325669,-0.17364817766693,-0.819152044288992,-0.939692620785908,0.996194698091746,-0.342020143325669,-0.17364817766693,-1.83690953073357e-16,-0.866025403784439,0.0871557427476579,0.0871557427476579,-0.0871557427476582,-0.17364817766693,-0.766044443118978,-0.544639035015027,0.17364817766693,-0.17364817766693,-0.939692620785908,-0.121869343405147)
env_tot$Easterness <- c(-0.913545457642601,-0.984807753012208,-1,-0.766044443118978,-1,-0.866025403784439,-0.939692620785908,-0.766044443118978,-0.951056516295154,-0.766044443118978,-0.838670567945424,-0.777145961456971,-0.939692620785909,-0.766044443118978,-0.984807753012208,0,-0.587785252292473,-0.529919264233206,-0.939692620785909,-0.987688340595138,-0.642787609686539,-0.866025403784439,-0.984807753012208,-0.766044443118978,-0.939692620785909,-0.984807753012208,-0.939692620785909,-0.342020143325669,0.766044443118978,-0.4067366430758,-0.342020143325669,-0.342020143325669,-0.342020143325669,1.22460635382238e-16,-0.342020143325669,1.22460635382238e-16,0.939692620785908,0.104528463267654,-0.984807753012208,-0.342020143325669,-0.342020143325669,0.694658370458997,-0.642787609686539,0.342020143325669,-0.17364817766693,-0.17364817766693,-0.342020143325669,-0.422618261740699,-0.642787609686539,-0.997564050259824,-0.99026806874157,-0.984807753012208,-0.342020143325669,-0.984807753012208,0.342020143325669,-0.342020143325669,-0.17364817766693,-0.961261695938319,-0.981627183447664,-0.939692620785908,-0.984807753012208,-0.573576436351046,-0.342020143325669,-0.0871557427476583,-0.939692620785908,-0.984807753012208,-1,-0.5,-0.996194698091746,-0.996194698091746,-0.996194698091746,-0.984807753012208,-0.642787609686539,-0.838670567945424,-0.984807753012208,-0.984807753012208,-0.342020143325669,-0.992546151641322)

env_tot$site <- c(rep("site1", 38),  rep("site2", 40))
env_tot$site<- as.factor(env_tot$site)

b<-vegdist(CWM_tot.2[,1:16], method="bray")

env_tot[,1:12]<- scale(env_tot[,1:12], center=T, scale=T)

dibbierredia.b<-dbrda(b~ ALTITUDE + SLOPE + MICRORELIEF +
                        LITTER + VEGETATION + ROCKS + HEIGHT + DEPTH +
                        pH + C_N + Northerness + Easterness, data= env_tot, 
                      strata=site, center=T, scale=T)

ord.null.b<-dbrda(b~1, data=env_tot)

ord.sel.b<-ordistep(ord.null.b, scope=formula(dibbierredia.b), direction="forward", permutations = 9999) 
#> 
#> Start: b ~ 1 
#> 
#>               Df    AIC       F Pr(>F)    
#> + pH           1 46.035 34.7625 0.0001 ***
#> + DEPTH        1 61.748 14.5545 0.0001 ***
#> + C_N          1 63.849 12.1472 0.0001 ***
#> + LITTER       1 66.647  9.0416 0.0001 ***
#> + ROCKS        1 67.990  7.5897 0.0002 ***
#> + SLOPE        1 69.566  5.9174 0.0023 ** 
#> + ALTITUDE     1 70.224  5.2297 0.0041 ** 
#> + HEIGHT       1 70.749  4.6847 0.0058 ** 
#> + VEGETATION   1 70.961  4.4656 0.0087 ** 
#> + Northerness  1 72.499  2.8948 0.0389 *  
#> + Easterness   1 72.596  2.7962 0.0418 *  
#> + MICRORELIEF  1 73.331  2.0574 0.1051    
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Step: b ~ pH 
#> 
#>               Df    AIC      F Pr(>F)   
#> + HEIGHT       1 43.035 4.9656 0.0013 **
#> + Northerness  1 43.641 4.3471 0.0015 **
#> + Easterness   1 43.607 4.3815 0.0029 **
#> + LITTER       1 43.782 4.2030 0.0032 **
#> + ALTITUDE     1 43.931 4.0523 0.0032 **
#> + C_N          1 44.165 3.8153 0.0067 **
#> + DEPTH        1 45.981 2.0018 0.0972 . 
#> + SLOPE        1 46.521 1.4707 0.2176   
#> + VEGETATION   1 46.670 1.3246 0.2638   
#> + MICRORELIEF  1 47.197 0.8103 0.5207   
#> + ROCKS        1 47.498 0.5189 0.7232   
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Step: b ~ pH + HEIGHT 
#> 
#>               Df    AIC      F Pr(>F)   
#> + Easterness   1 41.169 3.7599 0.0067 **
#> + C_N          1 41.324 3.6055 0.0075 **
#> + Northerness  1 41.335 3.5951 0.0090 **
#> + LITTER       1 42.498 2.4462 0.0551 . 
#> + ALTITUDE     1 43.234 1.7290 0.1465   
#> + SLOPE        1 43.506 1.4648 0.2183   
#> + DEPTH        1 43.971 1.0161 0.4003   
#> + MICRORELIEF  1 44.056 0.9343 0.4506   
#> + VEGETATION   1 44.437 0.5692 0.6867   
#> + ROCKS        1 44.548 0.4633 0.7608   
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Step: b ~ pH + HEIGHT + Easterness 
#> 
#>               Df    AIC      F Pr(>F)  
#> + C_N          1 39.748 3.2731 0.0151 *
#> + LITTER       1 40.073 2.9557 0.0219 *
#> + Northerness  1 40.053 2.9753 0.0266 *
#> + ALTITUDE     1 40.960 2.0973 0.0850 .
#> + MICRORELIEF  1 41.108 1.9546 0.1080  
#> + DEPTH        1 42.122 0.9868 0.4131  
#> + SLOPE        1 42.127 0.9816 0.4229  
#> + VEGETATION   1 42.535 0.5958 0.6695  
#> + ROCKS        1 42.951 0.2042 0.9155  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Step: b ~ pH + HEIGHT + Easterness + C_N 
#> 
#>               Df    AIC      F Pr(>F)  
#> + Northerness  1 38.376 3.1809 0.0165 *
#> + LITTER       1 39.025 2.5576 0.0431 *
#> + ALTITUDE     1 39.400 2.2005 0.0736 .
#> + MICRORELIEF  1 39.962 1.6678 0.1684  
#> + DEPTH        1 40.654 1.0174 0.3918  
#> + SLOPE        1 40.657 1.0144 0.4074  
#> + VEGETATION   1 41.090 0.6099 0.6552  
#> + ROCKS        1 41.575 0.1596 0.9307  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Step: b ~ pH + HEIGHT + Easterness + C_N + Northerness 
#> 
#>               Df    AIC      F Pr(>F)  
#> + LITTER       1 37.482 2.6836 0.0329 *
#> + ALTITUDE     1 37.861 2.3267 0.0632 .
#> + MICRORELIEF  1 38.467 1.7593 0.1429  
#> + SLOPE        1 39.345 0.9445 0.4414  
#> + DEPTH        1 39.409 0.8861 0.4856  
#> + VEGETATION   1 39.566 0.7414 0.5724  
#> + ROCKS        1 40.234 0.1298 0.9416  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Step: b ~ pH + HEIGHT + Easterness + C_N + Northerness + LITTER
#> Error in dimnames(u) <- list(dnam[[1]], c(axnam, negnam)): length of 'dimnames' [2] not equal to array extent
jarioksa commented 1 month ago

Confirmed.

To make things easier for other to study, this is the model that causes the error:

dbrda(b ~ Condition(pH + HEIGHT + Easterness + C_N + Northerness + LITTER) + ROCKS, env_tot)

This model is fit internally in ordistep when trying to evaluate should ROCKS be added to the last accepted model within Condition().

This is a strange geometric quirk that needs a bit thinking: the conditional (partial) model with ROCKS has no numerically positive eigenvalues: the largest ("leading") eigenvalue is 1.2 × 10-17 that we regard as zero within numerical precision. However, there is one numerically non-zero negative eigenvalue of −3 × 10-3. If you look at the permutation tests of the model that would include ROCKS, you see this peculiarity:

Permutation test for dbrda under reduced model
Terms added sequentially (first to last)
Permutation: free
Number of permutations: 999

Model: dbrda(formula = b ~ pH + HEIGHT + Easterness + C_N + Northerness + LITTER + ROCKS, data = env_tot)
            Df SumOfSqs       F Pr(>F)    
pH           1  0.79424 40.5281  0.001 ***
HEIGHT       1  0.10783  5.5021  0.001 ***
Easterness   1  0.07875  4.0183  0.012 *  
C_N          1  0.06651  3.3938  0.023 *  
Northerness  1  0.06276  3.2025  0.033 *  
LITTER       1  0.05174  2.6401  0.051 .  
ROCKS        1 -0.00297 -0.1516  0.998    
Residual    70  1.37180         

ROCKS only has imaginary contribution!

Your case is so enchanting that I was carried along with details. The main point is that we should handle this kind of situation smoothly and I'll fix this. Really an exciting case!