Skip to content

Contingency matrix with columns of only 0s #11

Description

@Jorge-C

Current CCA code fails if the contingency matrix has any column with no observations, but vegan's R doesn't.

However, in R both sol and sol2 have the same results (Yval has a few columns with no observations):

library(vegan)
X <- read.table('Xval')
Y <- read.table('Yval')

nonzero <- apply(Y, 2, sum) != 0

sol <- cca(Y[, nonzero], X)
sol2 <- cca(Y, X)

and they match the current python implementation

from ordination import CCA
import numpy as np

X = np.loadtxt('Xval')
Y = np.loadtxt('Yval')

nonzero = Y.sum(axis=0) != 0

sol = CCA(Y[:, nonzero], X)

Maybe we can just remove those columns in __init__ and be careful with names (warning the user "hey, {n_cols} of the contingency matrix had no observations, they were dropped in the analysis.")

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions