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

goodness.cca #189

Closed
sjankin opened this issue Aug 16, 2016 · 7 comments
Closed

goodness.cca #189

sjankin opened this issue Aug 16, 2016 · 7 comments
Assignees
Labels
Milestone

Comments

@sjankin
Copy link

sjankin commented Aug 16, 2016

Hi I was running a CCA model, calling goodness() afterwards returns an error "Error in diag(w) %*% CA^2 %*% diag(eig) : non-conformable arguments".

Replicable code below:

Data:
data.zip

Code:

library(vegan)
library(readr)

#Example works fine
data(dune)
data(dune.env)
mod <- cca(dune ~ A1 + Management + Condition(Moisture), data=dune.env)
goodness(mod, addprevious = TRUE)

#Error message
words <- read_csv("words.csv")
env <- read_csv("env.csv")
cca <- cca(words ~ Idealpoint, data = env)

goodness(cca, addprevious = TRUE)
#Error in diag(w) %*% CA^2 %*% diag(eig) : non-conformable arguments
@jarioksa
Copy link
Contributor

jarioksa commented Aug 16, 2016

This is a bug. I'll fix it asap.

The bug can be triggered with standard vegan data:

library(vegan)
data(dune, dune.env)
# these both fail
goodness(cca(dune ~ A1, dune.env))
goodness(rda(dune ~ A1, dune.env))

The error appears when constraints have rank=1. It looks like one of the classic R gotchas: what happens with diag(x) when x is a one-element vector?

@jarioksa jarioksa self-assigned this Aug 16, 2016
@jarioksa jarioksa added the bug label Aug 16, 2016
jarioksa pushed a commit that referenced this issue Aug 16, 2016
reported as issue #189 in github
jarioksa pushed a commit that referenced this issue Aug 17, 2016
@jarioksa
Copy link
Contributor

Fixed with 07f1857. Thanks for reporting the bug.

@sjankin
Copy link
Author

sjankin commented Aug 17, 2016

That's great. Thanks for dealing with it so quickly. Are you going to push to CRAN an update?

@sjankin
Copy link
Author

sjankin commented Aug 17, 2016

Hi Jari, The build directly from GitHub is failing. So I used a local source with updated goodness.cca.R function, and I am still getting the same error message. Using the example data and code I submitted earlier:

source("goodness.cca.R")
words <- read_csv("words.csv")
env <- read_csv("env.csv")
cca <- cca(words ~ Idealpoint, data = env)
goodness.cca(cca, addprevious = TRUE)

Error in diag(w) %*% CCA^2 %*% diag(object$CCA$eig) : 
non-conformable arguments 
4 is.data.frame(x) 
3 rowSums(diag(w) %*% CCA^2 %*% diag(object$CCA$eig)) 
2 inertcomp(object, display = display) at goodness.cca.R#42
1 goodness.cca(cca, addprevious = TRUE) 

@jarioksa
Copy link
Contributor

You also need to upgrade the inertcomp() function that is called from goodness.cca and has the same flaw in handling diag(x). The inertcomp function was fixed in the same commit as goodness.cca.

If you upgrade these functions by sourcing, you may also need to take care that they are in the vegan environment and replace the original functions that were locked into vegan namespace when loading vegan:

source("goodness.cca.R")
source("inertcomp.R")
environment(goodness.cca) <- enviroment(dbrda) # or any function in vegan NAMESPACE
environment(inertcomp) <- environment(dbrda)
assignInNamespace("goodness.cca", goodness.cca, "vegan")
assignInNamespace("inertcomp", inertcomp, "vegan")

You may not need all these tricks, but sometimes you do -- depends on the kind of functions.

About inability to build vegan from github: do you have C and Fortran compilers?

@sjankin
Copy link
Author

sjankin commented Aug 17, 2016

Ok, perfect. My mistake with the Fortran compiler.

One small thing, the "choices" option is not functional any more? (Just running from my earlier example data/code, but with 2.5 version)

goodness(cca, display="sites", choices=c(1,2,3))
goodness(cca, display="species", choices=c(1,2,3))

This produces contributes only for the constrained dimension (CCA1).

@gavinsimpson
Copy link
Contributor

It looks like choices isn't used anywhere in the code since the original goodness.cca was replaced by goodness2.cca. Previously we had:

    if (!missing(choices)) 
        vexp <- vexp[, choices, drop = FALSE]

It's not immediately clear to me what choices did or where it fit in the newer version of the code, so I'll leave that to @jarioksa but I'll file a new issue to trick this bug, be it in documentation or code.

@jarioksa jarioksa added this to the 2.4-1 milestone Aug 22, 2016
jarioksa pushed a commit that referenced this issue Aug 30, 2016
reported as issue #189 in github

(cherry picked from commit 07f1857)
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