Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eggxo opened this issue Dec 5, 2023 · 4 comments

Comments

@eggxo
Copy link

eggxo commented Dec 5, 2023

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

@jarioksa
Copy link
Contributor

jarioksa commented Dec 5, 2023

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
Copy link
Author

eggxo commented Dec 6, 2023

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.

@jarioksa
Copy link
Contributor

jarioksa commented Dec 6, 2023

@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
Copy link
Author

eggxo commented Dec 6, 2023

thank u Sir!

@eggxo eggxo closed this as completed Dec 6, 2023
jarioksa added a commit that referenced this issue Dec 6, 2023
ordir2step can proceed to models with no residual unconstrained
variation where adjusted R2 will be NA and this will stop with
error condition. Now stops smoothly and reports adjR2=0 for these
cases.
jarioksa added a commit that referenced this issue Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants