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

RsquareAdj not returning $adj.r.squared in versions 2.5+ (including 2.6) #295

Closed
LucasMS opened this issue Nov 6, 2018 · 10 comments
Closed
Milestone

Comments

@LucasMS
Copy link

LucasMS commented Nov 6, 2018

Hi,

I noticed that RsquareAdj do not return $adj.r.squared in the package versions 2.5+ (including 2.6). It works as expected with package version 2.4-5.

Reproducing the error:

Does work

> library(vegan)
> library(devtools)
> data(dune)
> data(dune.env)
> dune.dist <- vegdist(dune) 
> m <- dbrda(dune.dist ~ Management + Condition(Moisture + A1), data=dune.env)
> RsquareAdj(m)
$r.squared
[1] 0.2101923

$adj.r.squared
[1] 0.1568308


> session_info()
Session info -------------------------------------------------------------
 setting  value                       
 version  R version 3.4.3 (2017-11-30)
 system   x86_64, linux-gnu           
 ui       RStudio (1.1.456)           
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       CET                         
 date     2018-11-06                  

Packages -----------------------------------------------------------------
 package   * version date       source        
 base      * 3.4.3   2018-03-08 local         
 cluster     2.0.6   2017-03-16 CRAN (R 3.4.3)
 compiler    3.4.3   2018-03-08 local         
 datasets  * 3.4.3   2018-03-08 local         
 devtools  * 1.13.4  2017-11-09 CRAN (R 3.4.3)
 digest      0.6.18  2018-10-10 CRAN (R 3.4.3)
 graphics  * 3.4.3   2018-03-08 local         
 grDevices * 3.4.3   2018-03-08 local         
 grid        3.4.3   2018-03-08 local         
 lattice   * 0.20-35 2017-03-25 CRAN (R 3.4.3)
 MASS        7.3-47  2017-04-21 CRAN (R 3.4.3)
 Matrix      1.2-12  2017-11-16 CRAN (R 3.4.3)
 memoise     1.1.0   2017-04-21 CRAN (R 3.4.3)
 methods   * 3.4.3   2018-03-08 local         
 mgcv        1.8-22  2017-09-19 CRAN (R 3.4.3)
 nlme        3.1-131 2017-02-06 CRAN (R 3.4.3)
 parallel    3.4.3   2018-03-08 local         
 permute   * 0.9-4   2016-09-09 CRAN (R 3.4.3)
 stats     * 3.4.3   2018-03-08 local         
 tools       3.4.3   2018-03-08 local         
 utils     * 3.4.3   2018-03-08 local         
 vegan     * 2.4-5   2017-12-01 CRAN (R 3.4.3)
 withr       2.1.2   2018-03-15 cran (@2.1.2) 
 yaml        2.2.0   2018-07-25 CRAN (R 3.4.3)

Does not work

> library(vegan)
> library(devtools)
> data(dune)
> data(dune.env)
> 
> dune.dist <- vegdist(dune) 
> m <- dbrda(dune.dist ~ Management + Condition(Moisture + A1), data=dune.env)
> RsquareAdj(m)
$r.squared
[1] 0.2101923

$adj.r.squared
[1] NA

> session_info()
Session info --------------------
 setting  value                       
 version  R version 3.5.1 (2018-07-02)
 system   x86_64, linux-gnu           
 ui       RStudio (1.1.456)           
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       CET                         
 date     2018-11-06                  

Packages --------------------
 package   * version date       source                          
 base      * 3.5.1   2018-08-10 local                           
 cluster     2.0.7-1 2018-04-09 CRAN (R 3.5.1)                  
 compiler    3.5.1   2018-08-10 local                           
 datasets  * 3.5.1   2018-08-10 local                           
 devtools  * 1.13.5  2018-02-18 CRAN (R 3.5.1)                  
 digest      0.6.15  2018-01-28 CRAN (R 3.5.1)                  
 graphics  * 3.5.1   2018-08-10 local                           
 grDevices * 3.5.1   2018-08-10 local                           
 grid        3.5.1   2018-08-10 local                           
 lattice   * 0.20-35 2017-03-25 CRAN (R 3.5.1)                  
 MASS        7.3-50  2018-04-30 CRAN (R 3.5.1)                  
 Matrix      1.2-14  2018-04-09 CRAN (R 3.5.1)                  
 memoise     1.1.0   2017-04-21 CRAN (R 3.5.1)                  
 methods   * 3.5.1   2018-08-10 local                           
 mgcv        1.8-24  2018-06-18 CRAN (R 3.5.1)                  
 nlme        3.1-137 2018-04-07 CRAN (R 3.5.1)                  
 parallel    3.5.1   2018-08-10 local                           
 permute   * 0.9-4   2016-09-09 CRAN (R 3.5.1)                  
 stats     * 3.5.1   2018-08-10 local                           
 tools       3.5.1   2018-08-10 local                           
 utils     * 3.5.1   2018-08-10 local                           
 vegan     * 2.6-0   2018-11-06 Github (vegandevs/vegan@6097c89)
 withr       2.1.2   2018-03-15 CRAN (R 3.5.1)                  
 yaml        2.1.19  2018-05-01 CRAN (R 3.5.1)    

By the way, many thanks for this awesome package and your support to the community!

Cheers,
Lucas

@jarioksa
Copy link
Contributor

jarioksa commented Nov 6, 2018

This is even documented -- NEWS for the release 2.5-1 say:

    • Adjusted R-squared is not calculated for partial ordination,
       because it is unclear how this should be done (function
       `RsquareAdj`).

We used one way in vegan, but after inspecting alternative ways of defining R2adj I was no longer sure that the way we used was correct and compelling for partial ordination. Therefore the feature was disabled in partial ordination. Just as soon as I get convinced on the correct way, I can re-implement the feature. Perhaps after I get response to my queries (@legendre @gavinsimpson) the situation can change.

@LucasMS
Copy link
Author

LucasMS commented Nov 6, 2018

Hey Jari,

Thanks for the fast reply! I completely missed this release note.

Yeah, I see that is wise not to implement something that you are not sure how it is better done. Would this also apply for AdjRsquare of varpart function?

For instance, considering the example in my post, the adj.r.squared that I get from RsquareAdj(m) using version 2.4-5 is 0.1568308. This is identical to the Adj.R.Square that I get calling varpart for the individual fraction [a] = X1 | X2+X3 obtained with version 2.6:

In 2.4-5

> dune.dist <- vegdist(dune) 
> m <- dbrda(dune.dist ~ Management + Condition(Moisture + A1), data=dune.env)
> RsquareAdj(m)
$r.squared
[1] 0.2101923

$adj.r.squared
[1] 0.1568308

In 2.6

varpart(dune.dist, ~ Management, ~ Moisture, ~ A1, data = dune.env)

#Result 
                      Df R.square Adj.R.square Testable
[a] = X1 | X2+X3       3               0.15683 

I am basically mimicking varpart using Condition as in an old tutorial of yours Constrained Ordination: Tutorial with R and vegan (jan, 2012). Now wondering if I should stop using this approach until further reply from @legendre and @gavinsimpson.

Cheers,
Lucas

@legendre
Copy link
Contributor

legendre commented Nov 6, 2018 via email

@jarioksa jarioksa added this to the 2.5-4 milestone Jan 16, 2019
@jarioksa
Copy link
Contributor

@legendre : A little bit of history. We have RsquareAdj for CCA, but that function did not explicitly handle partial CCA. However, it returned adjusted R2 also for partial models using the same simulation method as for non-partial models. This was inconsistent with adjusted R2 for RDA and with varpart. It is possible to implement consistent adjusted method for CCA, but it is pretty complicated. When I had a look at the issue, I had my doubts on the correct way of doing these things – both for the CCA and for RDA – and decided to disable Radj2 for both temporarily. Soon after that some non-vegan matters took all my attention, and I forgot to settle the issue. I'll go through my papers and possibly I'll mail a working paper to you.

The previous method was similar as in your NEwR book, and it can be re-instated by reverting a commit. Then we should still decide what to do with the partial CCA: (1) leave it NA, like now, or (2) implement the longer method that is consistent with RDA, but requires two permutation cycles.

I have made this issue a milestone for 2.5-4, and we can have a new release (fixing issue #299) with merged changes as soon as we decide what to change (back).

The commit history and my comments can be found with git.

jarioksa pushed a commit that referenced this issue Jan 27, 2019
jarioksa pushed a commit that referenced this issue Jan 27, 2019
… varpart"

This reverts commit 6ac3365.

see github issue #295
@jarioksa
Copy link
Contributor

jarioksa commented Jan 27, 2019

I have now re-instated adjusted R2 for pRDA, and also added a consistent version of the same for pCCA on branch restore-partial-R2-adj. Both of these are also consistent with varpart. This does not mean that I would be certain that these should be implemented in this way (also concerns varpart).

@legendre
Copy link
Contributor

legendre commented Jan 27, 2019 via email

@LucasMS
Copy link
Author

LucasMS commented Jan 28, 2019

Thank you @jarioksa for the followup and re-implementation of the function.
Thank you both @jarioksa @legendre for the availability and discussion.

Cheers,

Lucas

@jarioksa
Copy link
Contributor

@legendre , there is no pRDA function in vegan, but there is rda function that can also do pRDA (the method) as well as PCA. Just as well, function cca can do CA, CCA and pCCA, and function dbrda can do PCoA, dbRDA and p-dbRDA.

@legendre
Copy link
Contributor

legendre commented Jan 28, 2019 via email

jarioksa pushed a commit that referenced this issue Jan 29, 2019
This merge re-enables calculation of adj-R2 for partial RDA that was
removed in vegan release 2.5-1. It also implements adj-R2 for partial
CCA in a way that is consistent with RDA and varpart. Before 2.5-1
release CCA was inconsistent.

See github issue #295
jarioksa pushed a commit that referenced this issue Jan 29, 2019
This reverts commit 32fd2e0.

see github issue #295

(cherry picked from commit 943408c)
jarioksa pushed a commit that referenced this issue Jan 29, 2019
… varpart"

This reverts commit 6ac3365.

see github issue #295

(cherry picked from commit 6201d51)
@jarioksa
Copy link
Contributor

Closed with merge commit 40584a1 which re-enables RsquareAdj for partial RDA and implements consistent permutation-based calculation for partial CCA.

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

3 participants