vegandevs/vegan

Error in if (R2.adds[best] > R2.previous && (!R2scope || R2scope && R2.adds[best] <= : missing value where TRUE/FALSE needed

eggxo opened this issue · 4 comments

eggxo commented

Dear jarioksa,
I meet an error: Error in if (R2.adds[best] > R2.previous && (!R2scope || R2scope && R2.adds[best] <= : missing value where TRUE/FALSE needed when I run ordiR2step. It seems the test reached the <none>, then the program Execution halted.
How could I solve this problem? Thanks alot! (below are the log and my command)

command:
RDA0 <- rda(gen ~ 1, Variables)
save(RDA0,file="RDA0.data")
RDAfull <- rda(gen ~ ., Variables)
save(RDAfull,file="RDAfull.data")
mod <- ordiR2step(RDA0, RDAfull, Pin = 1, R2permutations = 1000, R2scope = F)

log:
Step: R2.adj= 0.4143618
Call: gen ~ UVB4 + sradthrid7_9 + sradfirst1_3 + UVB3 + sradsecond4_6 + Organic + sradfour10_12 + vaprsecond4_6 + sradannual + CECSOL_M_mean + PHIHOX_M_mean + K + UVB5 + windthrid7_9 + P + vaprfirst1_3 + elev + windsecond4_6 + windfour10_12 + UVB2 + vaprfour10_12 + vaprannual + OCDENS_M_mean

R2.adjusted
<none> 0.4143618

Error in if (R2.adds[best] > R2.previous && (!R2scope || R2scope && R2.adds[best] <= :
missing value where TRUE/FALSE needed
Calls: ordiR2step
Execution halted

There is no reproducible example, but I can generate this with overfitted models that have no residual variation (no residual unconstrained component). In those cases RsquareAdj will return NA. Is this the case with your full model (RDAfull)? Normally the function will stop earlier, but if you set Pin=1 and R2scope=FALSE it will indeed proceed to the bitter end. However, it should stop gracefully instead of an error. I'll fix this.

Please confirm if your full model is overfitted (no residual variation). If it is not overfitted, there is some unknown problem and we need a reproducible example.

eggxo commented

I think the full model is not overfitted cause I have ran a 67 environment variants and a 27 environment variants dataset for forward selection without any error (use the same command line). Here I paste a reproducible example in a email.
Thanks.

@eggxo Thanks for the files you sent privately. First look at these files shows that you really run out of degrees of freedom and you have zero residual variation. This makes vegan::ordiR2step to fail. Please note that other stepwise methods in vegan can work with this situation: the problem is that vegan::RsquareAdj returns adjusted R2 as NA in this case. That behaviour is correct as such, because R2 cannot be adjusted, but vegan::ordiR2step did not handle this special case.

Here is the essential information from your full model:

              Inertia Proportion Rank
Total            4131          1     
Constrained      4131          1   24
Unconstrained       0          0    0
Inertia is variance 
Some constraints or conditions were aliased because they were redundant

This shows that the residual unconstrained variance is 0. The rank of constrained component is 24, and some constraints were aliased because you got more of them than could be analysed with your data. In this case the aliased variables were

> alias(RDAfull, names.only=TRUE)
[1] "windannual" "UVB4"       "UVB5"       "UVB6"  
eggxo commented

thank u Sir!