Skip to content

Handle ties and missing values in get.pc() - #108

Open
thierrygosselin wants to merge 1 commit into
bcm-uga:masterfrom
thierrygosselin:fix-get-pc-ties
Open

thierrygosselin wants to merge 1 commit into
bcm-uga:masterfrom
thierrygosselin:fix-get-pc-ties

Conversation

@thierrygosselin

Copy link
Copy Markdown
Contributor

Summary

This PR makes get.pc() return exactly one deterministic principal component for every requested marker while handling missing component scores correctly.

Problems

get.pc() identifies the most strongly associated principal component using:

which(zscore^2 == max(zscore^2))

When two or more components have the same maximum squared z-score, which() returns multiple component indices. Assigning those indices into a single result position can cause recycling, truncation, warnings, or an output that is no longer aligned reliably with the requested markers.

Missingness is also currently determined from PC1 alone. Consequently, a marker is skipped when its PC1 z-score is missing even if another component has a valid score.

Changes

  • Return the first component when several components share the maximum squared z-score.
  • Evaluate all components before classifying a marker as missing.
  • Return NA only when every component score for that marker is missing.
  • Preserve the order and duplication of requested marker indices.
  • Return a correctly typed empty result for an empty marker selection.
  • Document the tie-breaking and missing-value behaviour.
  • Add regression tests for all these cases.

Why deterministic tie handling is appropriate

get.pc() promises one principal component per marker. Returning the first maximum:

  • fulfils that interface;
  • follows the deterministic behaviour of which.max();
  • avoids silently expanding or recycling results;
  • produces reproducible output;
  • does not claim that one tied component is biologically more strongly associated than another.

The documented rule makes this limitation visible to users.

Validation

  • 43 package tests passed, including five new assertions.
  • R CMD check --no-manual: 0 errors, 0 warnings, 0 notes when unavailable suggested packages were not forced.

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

Successfully merging this pull request may close these issues.

1 participant