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

Suggestion : Add functions for PCA and CA that just call rda() and cca() in the background #655

Closed
cmartin opened this issue May 30, 2024 · 12 comments
Assignees

Comments

@cmartin
Copy link

cmartin commented May 30, 2024

Hi,

I'm teaching every year an undergrad course where we use vegan for many useful things (nmds, hclust,kmeans, etc.).

Since this is an undergrad course, we don't go into canonical ordinations, but I like my students to have a constant interface when doing multivariate analysis so we use vegan also for pca and ca, especially since vegan is THE multivariate library to know in ecology.

Every year though, I see the confusion in their eyes that they use a function named for another statistical method because it can do both.

Would it be possible to add both a pca and ca method that just call rda and cca transparently in the background?

Thanks you for your time and great package!

@jarioksa
Copy link
Contributor

You mean these functions?

ca <- function(x, ...) cca(x, ...)
pca <- function(x, scale = FALSE, ...) rda(x, scale = scale, ...)

@gavinsimpson
Copy link
Contributor

gavinsimpson commented May 30, 2024

@jarioksa Yes; I face the same questions every time I have to teach vegan to people. I know it's trivial to write those functions myself, but that doesn't help the students.

I was going to propose this in a PR but @cmartin has beaten me to the proposing.

Making this change gets my full support and I'll even do the PR if you are OK with it Jari?

@gavinsimpson
Copy link
Contributor

I would also add pco() to the proposed list as a wrapper around wcmdscale()

@gavinsimpson gavinsimpson changed the title Suggestion : Add method for PCA and CA that just call RDA and CCA methods in the background Suggestion : Add functions for PCA and CA that just call rda() and cca() in the background May 30, 2024
@cmartin
Copy link
Author

cmartin commented May 30, 2024

Yes @jarioksa , that's exactly what I meant.

Thanks @gavinsimpson for putting this in action.

I can't believe how fast you guys reacted! I should have posted this suggestion YEARS ago LOL

@jarioksa
Copy link
Contributor

jarioksa commented May 30, 2024

OK Gav, just go on!. Anyway it's a bit more complicated than my suggestion above: you need to adjust the (printed) call as well. There may be other bits where you need changes for support functions. For pco you probably mean making eig=TRUE default?

@gavinsimpson
Copy link
Contributor

@jarioksa Will do (and yes, I realize the actual functions will need some messing with the call - things are never that simple :-)

For pco(), yes, I think so. At least that's how I was calling wcmdscale() when I wrote my slide on it but I don't use it except when I have to teach, so I need to refresh my memory on it.

@gavinsimpson gavinsimpson self-assigned this May 30, 2024
@jarioksa
Copy link
Contributor

jarioksa commented May 30, 2024

See issue #186 which suggests having eigenvalues etc for default wcmdscale. Then I declined, because wcmdscale was designed as a drop-in replacement of stats::cmdscale, but pco() could solve this anomaly.

@jarioksa
Copy link
Contributor

jarioksa commented May 30, 2024

Another option is to make pco as a wrapper to dbrda (which only has formula interface currently).

Please note that it would be possible to call directly ordConstrained set of functions:

ca <- function(x, ....) ordConstrained(x, method="cca", ...)
pca <- function(x, scale = FALSE, ...) ordConstrained(x, method="rda", arg = scale, ...)
pco <- function(d, ...) ordConstrained(d, method = "dbrda", ...)

This will set header info and names as well (ordHead), and if you want to omit those, there are only essential analytic steps: init* and ordResid. For instance:

pco <- function(d, ...)
{
    d <- initDBRDA(d)
    ordResid(d)
}

This will only return numeric result without janitorial stuff of dbrda. However, I think you may want to have Lingoes and Cailliez distortions in pco and that goes more easily with wcmdscale (or then you need to edit dbrda to accept non-formula interface).

@jarioksa
Copy link
Contributor

@gavinsimpson I think it is best to implement pco() as a wrapper to dbrda so that all these functions (pca, ca, pco) have similar output, support functions and user experience. You can also have Cailliez & Lingoes distortions with dbrda (but not with direct call to ordConstrained(..., method = "dbrda", ...)). The prototype would be:

pco <- function(d, ...) dbrda(d ~ 1, ...)

@gavinsimpson
Copy link
Contributor

These are now implemented in the GitHub (development version).

@jarioksa, should these be cherry-picked to 2.6-6.2 so that they will be more immediately avaiable?

@jarioksa
Copy link
Contributor

jarioksa commented Jun 19, 2024

@gavinsimpson yes indeed, I think that these should be cherry-picked -x (use this switch) to cran-2.6-6 branch. Now I think that we should release 2.6-6.2 in mid-August before the (northern hemisphere) university teaching season (which seems to be called 'semester' in the English world, while 'semester' in Scandinavia means holiday). The fix is a (relatively) save wrapper and intended for teaching purposes, and we should have it in teaching release.

Please note that cran-2.6-6 has not moved inst/NEWS.md to the main directory. I did not see a need for this because there is no github.io page for the 2.6-6 branch. Currently the NEWS live in parallel universes: master lives like there will be no new CRAN releases, and cran-2.6-6 like there will be. After release the NEWS need synchronizing, but now they are separate.

gavinsimpson added a commit that referenced this issue Jun 20, 2024
gavinsimpson added a commit that referenced this issue Jun 20, 2024
@gavinsimpson
Copy link
Contributor

@jarioksa Done; I think a mid-August release would be good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants