Add MZ twin support to adjacency matrix via twinID column #116
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements support for modeling monozygotic (MZ) twins in the relatedness matrix by redirecting one twin's parental links to point to the other twin. This causes the adjacency matrix to assign a relatedness of 1.0 between MZ co-twins instead of the default 0.5 for siblings.
Key Changes
New
addMZtwins()function inR/constructAdjacency.R:twinIDcolumn in the pedigreezygositycolumn exists, only modifies pairs where both members havezygosity == "MZ"zygositycolumn exists, assumes alltwinIDpairs are MZmomIDanddadIDto point to the first twinUpdated
ped2com()function inR/buildComponent.R:mz_twinsparameter (defaults to FALSE for backward compatibility)addMZtwins()whenmz_twins = TRUEandtwinIDcolumn existsUpdated
ped2add()function inR/buildComponent.R:mz_twinsparameter and passes it through toped2com()Enhanced documentation:
mz_twinsparameter description inped2com()to explain the new behavioraddMZtwins()functionComprehensive test coverage in
tests/testthat/test-buildComponent.R:mz_twins = TRUEmz_twins = FALSEImplementation Details
The key insight is that by redirecting both a twin's
momIDanddadIDto point to their co-twin, the path tracing algorithm in the adjacency matrix produces two 0.5 entries (one for each parent link) that sum to 1.0, correctly modeling genetic identity between MZ twins. The diagonal fix ensures that the self-relatedness of the redirected twin matches their co-twin's self-relatedness.https://claude.ai/code/session_01P3RQTYpWtAtheSqi4aPjR5