Skip to content

ldaFunction(): score sign/magnitude biased toward the second class level (signed mean difference added to unsigned coefficient) #104

In review

Description

@JamesYang1209

The ldaFunction() implementation combines a signed mean difference with an unsigned LDA coefficient, which can produce incorrect score directions:

(R/lefser.R, devel):

lefser/R/lefser.R

Lines 121 to 132 in a0a8ddd

coeff <- vector("numeric", length(scal)) # absolute scaled LDA coefficient
for (v in seq_along(scal)) {
if (!is.na(scal[v])) {
coeff[v] <- abs(scal[v])
} else {
coeff[v] <- 0
}
}
## Feature Importance
lda.means.diff <- (lda.fit$means[2, ] - lda.fit$means[1, ]) # difference between the class means for each feature
res <- (lda.means.diff + coeff) / 2

coeff[v] <- abs(scal[v])
lda.means.diff <- (lda.fit$means[2, ] - lda.fit$means[1, ])
res <- (lda.means.diff + coeff) / 2

Because coeff is always non-negative, this calculation can bias scores toward the second factor level. For features enriched in the first (reference) class, lda.means.diff is negative, resulting in a score of (coeff - diff) / 2. In contrast, the expected LEfSe score is -(diff + coeff) / 2, where diff represents the absolute difference between class means.

When coeff is smaller than diff, the score retains its negative sign but has an incorrect magnitude. When coeff exceeds diff, the score becomes positive, incorrectly assigning the feature to the second class.

Consequently, the calculated scores can depend on the factor-level ordering rather than solely on the underlying data. This may lead to underestimated LDA scores for features enriched in the reference class, causing some features to fall below lda.threshold. Other features may be assigned to the wrong class, resulting in incorrect group labels in lefserPlot() and lefserPlotClad().

Activity

  1. LiNk-NY commented on Dec 1, 2026

    @LiNk-NY
    Contributor

    Thanks for the issue @JamesYang1209
    Would you take a look at PR #107 and provide some feedback?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions