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

anova.cca by="margin" inconsistent with earlier version #291

Closed
battusboy opened this issue Sep 20, 2018 · 4 comments
Closed

anova.cca by="margin" inconsistent with earlier version #291

battusboy opened this issue Sep 20, 2018 · 4 comments
Labels

Comments

@battusboy
Copy link

battusboy commented Sep 20, 2018

The anova.cca function in version 2.5-2 is giving answers (p-values) that are inconsistent with earlier versions (and don't make sense to me) when using by="margin". In particular, when using by="margin" things are showing up as "significant" that seem erroneous.

Below is code and results using version 2.4-6 and 2.5-2.

library(vegan)

set.seed(2)
dat<-matrix(rnorm(90),ncol=9)
x<-c(rep("A",5),rep("B",5))

mod<-rda(dat~x)

vegan version 2.4-6

set.seed(2);anova(mod)
set.seed(2);anova(mod, by="margin")

 > set.seed(2);anova(mod)
 Permutation test for rda under reduced model
 Permutation: free
 Number of permutations: 999

 Model: rda(formula = dat ~ x)
 Df Variance      F Pr(>F)
 Model     1   1.0949 0.9649  0.518
 Residual  8   9.0779

 > set.seed(2);anova(mod, by="margin")
 Permutation test for rda under NA model
 Marginal effects of terms
 Permutation: free
 Number of permutations: 999

 Model: rda(formula = dat ~ x)
 Df Variance      F Pr(>F)
 x         1   1.0949 0.9649  0.518
 Residual  8   9.0779
 >

vegan version 2.5-2

set.seed(2);anova(mod)
set.seed(2);anova(mod, by="margin")

 > set.seed(2);anova(mod)
 Permutation test for rda under reduced model
 Permutation: free
 Number of permutations: 999

 Model: rda(formula = dat ~ x)
 Df Variance     F Pr(>F)
 Model     1   1.3924 1.031  0.456
 Residual  8  10.8045

 > set.seed(2);anova(mod, by="margin")
 Permutation test for rda under reduced model
 Marginal effects of terms
 Permutation: free
 Number of permutations: 999

 Model: rda(formula = dat ~ x)
 Df Variance     F Pr(>F)
 x         1   1.3924 1.031   0.05 *
   Residual  8  10.8045

  Signif. codes:  0***0.001**0.01*0.05.0.1 ‘ ’ 1
@jarioksa
Copy link
Contributor

You have noticed that it makes no sense to have marginal test with only one variable? It did not occur to me that somebody would do so, and it seems that we do not handle this case gracefully. At the moment the best thing you can do is that you don't have marginal tests when you have only one variable and hence no marginal effects. I'll fix this, though.

@battusboy
Copy link
Author

battusboy commented Sep 20, 2018 via email

jarioksa pushed a commit that referenced this issue Sep 21, 2018
We only tested for non-null constraints & conditins in ordConstrained,
but we could have null data in 0-column matrix, and then we actually
ran unconstrained ordination instead of skipping analysis. This happened
in github issue #291, where a marginal anova.cca() gave wrong results
when the model only had one variable: when that one variable was dropped,
we got a zero-column constraint matrix.
@jarioksa
Copy link
Contributor

jarioksa commented Sep 21, 2018

We re-wrote completely constrained ordination and permutations tests for vegan 2.5-1, and a tiny detail in the ordination infrastructure caused this bug. The marginal effects are tested by removing each variable in turn and seeing how the full model changes. If there is only one constraining variable, it makes no sense to drop it because the remaining model is unconstrained, and the constraint matrix has zero columns. We did not have any guard of this in 2.4-6 either, but incidentally the model was handled correctly, but 2.5-1 needed a check against such models. Suggested fix is in commit eefb4a7.

jarioksa pushed a commit that referenced this issue Sep 21, 2018
Overall anova (without by=) and all by= cases in anova.cca and
permutest.cca should be equal when there is only 1-df variable.
Github issue #291 reported this to fail for by="margin".
jarioksa pushed a commit that referenced this issue Sep 21, 2018
@jarioksa
Copy link
Contributor

Closed with commit 6f28cda

jarioksa pushed a commit that referenced this issue Sep 21, 2018
We only tested for non-null constraints & conditins in ordConstrained,
but we could have null data in 0-column matrix, and then we actually
ran unconstrained ordination instead of skipping analysis. This happened
in github issue #291, where a marginal anova.cca() gave wrong results
when the model only had one variable: when that one variable was dropped,
we got a zero-column constraint matrix.

(cherry picked from commit eefb4a7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants